This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA
>e.code; cout<<"Enter the emp name"; cin>>e.name; } for(i=0;i<5;i++) { cout<<"Emp code="<<e[i].code<<endl; cout<<"Emp name="<<e[i].name<<endl; } getch(); }
71. SHOW ARRAY OF POINTERS. #include #include void main() { int a=10, b=20, c=30, d=40, e=50; int *ar[5],i; ar[0] = &a; ar[1] = &b; ar[2] = &c; ar[3] = &d;
ar[4] = &e; for(i=0;i<=4;i++) { cout<<"Value="<<*ar[i]<<"Add="<<ar[i]<<endl; } getch(); }
72. TO DEFINE A STRUCTURE WITHIN ANOTHER STRUCTURE. #include #include void main() { struct emp { int code; char name[10]; }; struct student int roll no., char name[10]; struct emp e; }s; cout<<"Enter the student roll no."; cin>>s.roll no.; cout<<"Enter the student name"; cin>>s.name; cout<<"Enter the emp code"; cin<<s.e.code; cout<<"Enter the emp name"; cin>>s.e.name; cout<<"St. Rollno.="<<s.roll no.<<endl; cout<<"St. Name="<<s.name<<endl; cout<<"Emp Code="<<s.e.code<<endl; cout<<"Emp Name="<<s.e.name<<endl; getch(); }
73. TO DEFINE A STRUCTURE WITH THE USE OF ARRAYS. #include #include void main() { struct emp { int code; char name[10]; }; struct student int roll no., char name[10]; struct emp e; }s[5]; int i; for(i=0;i<5;i++) { cout<<"Enter the student roll no."; cin>>s.roll no.; cout<<"Enter the student name"; cin>>s.name; cout<<"Enter the emp code"; cin<<s.e.code; cout<<"Enter the emp name"; cin>>s.e.name; } for(i=0;i<5;i++) { cout<<"St. Rollno.="<<s.roll no.<<endl; cout<<"St. Name="<<s.name<<endl; cout<<"Emp Code="<<s.e.code<<endl; cout<<"Emp Name="<<s.e.name<<endl; } getch(); }
74.TO DECLARE A CLASS. #include #include class emp { int code; char name[10]; public: void getdata() { cout<<"Enter the emp code"; cin<>name; } void put() { cout<<"Emp Code="<>name; } void put() { cout<<"Emp Code="<
77. TO CREATE A CONSTRUCTOR. #include #include class A { int a; public: A() { a=10; } void show() { cout<
} }; void main() { A a2; a2.show(); getch(); }
78. TO CREATE A CONSTRUCTOR WITH THE ARGUMENT. #include #include class A { int a; public: A(int x) { a= x; } void show() { cout<
79. TO CREATE A DESTRUCTOR. #include
#include class A { int a; public: A(int x) { a= x; } void show() { cout<
80. TO CREATE A FRIEND FUNCTION. #include #include class B; class A { int a; public: A() { a=10; } void friend show(A,B); }; class B { int z; public: B()
{ z=20; } void friend show(A,B); }; void show(A a2, B b2) { cout<
81. TO CREATE A FUNCTION MEMBER OVERLOADING. #include #include class A { public: void add() { cout<<"Rahul"<<endl; } void add(int x) { cout<<x<<endl; } void add(int x, int y) { cout<<x+y; } }; void main() { A a2; a2.add(); a2.add(10); a2.add(10,20); getch();
}
82. TO CREATE A CONSTRUCTOR OVERLOADING WITH ARGUMENTS. #include #include class A { public: A (char *p) { cout<
83. TO CREATE A CONSTRUCTOR OVERLOADING WITHOUT ARGUMENTS.
#include #include class A { public: A (char *p) { cout<
84. TO CREATE A OPERATOR OVERLOADING. #include #include class A { public: int a; A() { a = 10; } void operator ++() { a++; } void show()
{ cout<
85. TO CREATE A STATIC DATA MEMBERS. #include #include class A { static int a; public: void add() { a++; } void show() { cout<
86. TO CREATE A SINGLE-LEVEL INHERITANCE. #include #include class A { public: void show() { cout<<"Class A"<<endl; } }; class B: class A { public: void put() { cout<<”Class B”; } }; void main() { B b2; b2.show(); b2.put(); getch(); }
87. TO CREATE A MULTI-LEVEL INHERITANCE. #include #include class A { public: void show() { cout<<"Class A"<<endl;
} }; class B: class A { public: void show1() { cout<<”Class B”<<endl; } }; class C : public B { public: void show2() { cout<<”Class C”; } }; void main() { C e; e.show(); e.show1(); e.show2(); getch(); }
88. TO CREATE A MULTIPLE-LEVEL INHERITANCE. #include #include class A { public: void show() { cout<<"Class A"<<endl; } }; class B { public: void show1()
{ cout<<”Class B”<<endl; } }; class C : public A, public B { public: void show2() { cout<<”Class C”; } }; void main() { C e; e.show(); e.show1(); e.show2(); getch(); }
89. TO CREATE A HYBRID INHERITANCE. #include #include class A { public: void show() { cout<<"Class A"<<endl; } }; class B: class A { public: void get() { cout<<”Class B”<<endl; } }; class C : public A {
public: void put() { cout<<”Class C”<<endl; } }; void main() { B b2; C c1; b2.show(); b2.get(); c2.put(); getch(); }
90. TO CREATE A HIERARCHIAL INHERITANCE. #include #include class A { int a; public: void add() { cout<<"Enter the value of a”; cin>>a; } }; void sum() { cout<
cin rel="nofollow">>a>>b; } }; class C : public virtual A { protected: float p; public: void getdata() { cout <<"Enter the value of p”; cin>>p; } }; class D: public B , public C { int total; public: void display() { total=a+b+p; cout<
91. TO SHOW POLYMORPHISM. #include #include class A { public: void virtual show()
{ cout<<"class A”<<endl; } }; class B : public A { public: void show() { cout <<"class B”<<endl; } }; class C : public A { public: void show () { cout <<"class C ”<<endl; } }; void main() { A *p; B b1; C c1; p = &b1 p → show(); p = &c1; p → show(); getch(); }
92. TO CREATE A PURE VIRTUAL FUNCTION. #include #include class A { public: void virtual show() = 0; }; class B : public A {
public: void show() { cout <<"class B”<<endl; } }; class C : public A { public: void show () { cout <<"class C ”<<endl; } }; void main() { A *p; B b1; C c1; p = &b1 p → show(); p = &c1; p → show(); getch(); }
93. TO SHOW THE USE OF GET(). #include #include void main() { char a; cout<<”Enter the char of a”; cin.get(a); cout<
94. TO SHOW THE USE OF PUT(). #include #include void main() { char a = ‘z’; cin.get(a); cout<
95. TO SHOW THE USE OF GETLINE(). #include #include void main() { char name[10]; cout<<”Enter the name”; cin.getline(name,10); cout<
96. TO SHOW THE USE OF WRITE(). #include #include void main()
{ char name[10] = “RAHUL”; cout.write(name,10); getch(); }