Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

Friday, 27 April 2012

Program Of Nested Class In C++


#include<iostream.h>
#include<conio.h>
class base
{
private:
int a;
public:
class nested
{
private:
int b;
public:
void getdatan(int y)
{
b=y;
}
void displayn()
{
cout<<"\n nested value is="<<b;
}

} n;
{
a=x;
}
void display()
{
cout<<"\n Base Value is="<<a;
}
} ;
main()
{
clrscr();
base b1;
b1.getdata(5);
b1.display();
b1.n.getdatan(7);
b1.n.displayn();

getch();
}

Sunday, 15 January 2012

Program To Find Out Simple Interest Using Class In C++

     #include<iostream.h>
#include<conio.h>
#include<math.h>
class pawan
{
private:
float p,r,t;
public:

void getdata(float m,float n,float o)
{
 p=m;
 r=n;
 t=o;

}
void display()
{
float s,u,w,x,y;
s=(1+r/100);
u=p*t;
w=u-p;
cout<<w;
   }
   };
   main()
   {
   pawan a1;
   clrscr();
   float d,e,f;
   cout<<"enter numbers p,r,t=";
   cin>>d>>e>>f;
   a1.getdata(d,e,f);
   a1.display();
   getch();
   }

Thursday, 12 January 2012

Program To Find Local Class In C++

#include<iostream>
using namespace std;

                               int x;                       // global variable
                                 void f()                 // function definition
{
   static int y;       
                                                             
            //   int x;                 
                                                        
   extern int g();       
                                                                                         

              class local              // local class
       {
                       int g() { return x; }       // error, local variable x
                                                                               // cannot be used by g
                      int h() { return y; }       // valid,static variable y
              int k() { return ::x; }    // valid, global x
                          int l() { return g(); }        // valid, extern function g
      };
}

int main()
{
}
---------------------------------------------------------------------
Introduction To Local Class


A class can be declared inside a function or a block. In such cases, it is not visible from anywhere else, and instances thereof can only be created within the scope in which it is declared. This can be useful if you need to hide an ancillary object, which should not be accessible or used anywhere else: void f(const char *text)


Wednesday, 11 January 2012

Program Of Nested Class In C++

#include<iostream.h>
#include<conio.h>

class base
{
private:
int a;
public:
class nested
{
private:
int b;
public:
void getdatan(int y)
{
b=y;
}
void displayn()
{
cout<<"\n nested value is="<<b;
}

} n;
void getdata(int x)
{
a=x;
}
void display()
{
cout<<"\n Base Value is="<<a;
}
} ;


main()
{
clrscr();
base b1;
b1.getdata(5);
b1.display();
b1.n.getdatan(7);
b1.n.displayn();

getch();
}
-----------------------------------------------------------------------------------------------------



A nested class is declared within the scope of another class. The name of a nested class is local to its enclosing class. Unless you use explicit pointers, references, or object names, declarations in a nested class can only use visible constructs, including type names, static members, and enumerators from the enclosing class and global variables.

Member functions of a nested class follow regular access rules and have no special access privileges to members of their enclosing classes. Member functions of the enclosing class have no special access to members of a nested class.



VIEW SOURCE :-- http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=/com.ibm.xlcpp8l.doc/language/ref/cplr061.htm