Difference Between Procedure Oriented Programming & Object Oriented Programming
POP | OOP |
---|---|
It is a programming technique in which stress is given on functions rather than data. | It is a programming technique in which stress is given on the data rather than functions. |
In this programming the data members are global and they float from function to function. | In this programming the data members are not global and they remain attached with their specific function. |
Data hiding/Encapsulation is not possible in POP. | Data hiding/Encapsulation is one of the Principles of OOP. |
In this programming technique problem is divided into functions. | In this programming technique problem is divided into segments (i.e. modules). |
It is a Top down approach of Programming. | It is a Bottom up approach of Programming. |
No inheritance is possible in POP. | Inheritance is one of the basic principles of OOP. |
Polymorphism is not possible in POP. | Polymorphism is also one of the basic principles of OOP. |
Function overloading is not possible in POP. | Function overloading is possible in OOP. |
Function overriding is not possible in POP. | Function overriding is possible in OOP. |
Operator overloading is not possible in POP. | Operator overloading is possible in OOP. |
Mapping between Data and Function is difficult and complicated. | Mapping between Data and Function can be used using "Objects". |
Data abstraction is not possible in POP. | Data abstraction is possible in OOP. |
We can’t use access specifiers (i.e. public/private/protected) in POP. | We can use access specifiers (i.e. public/private/protected) in OOP. |
Examples: COBOL, BASIC, FORTRAN, C etc. | Examples: C++, JAVA, PYTHON, VISUAL BASIC etc. |
Difference Between C Language & C++ Language
C Language | C++ Language |
---|---|
It is a Procedural & Structural Language. | It is an Object oriented Language. |
It is a Top down approach of Programming. | It is a Bottom up approach of Progrmming. |
It uses printf() function for output and scanf() function for input. | It uses cout<< for output and cin>> for input. |
In C, Polymorphism is not possible. | The concept of polymorphism is used in C++. |
Operator overloading is not possible in C. | Operator overloading is one important Feature of C++. |
Mapping between Data and Function is difficult and complicated. | Mapping between Data and Function can be used using "Objects" |
C requires all the variables to be defined at the starting of a scope. | C++ allows the declaration of variable anywhere in the scope i.e at time of its First use. |
No inheritance is possible in C. | Inheritance is possible in C++ |
In C, malloc() and calloc() Functions are used for Memory Allocation and free() function for memory Deallocating. | In C++, new and delete operators are used for Memory Allocating and Deallocating. |
It supports built-in and primitive data types. | It supports both built-in and user define data types. |
In C, Exception Handling is not present. | In C++, Exception Handling is done with Try and Catch block. |
No virtual Functions are present in C | The concept of virtual Functions are used in C++. |
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
cout<<"Welcome";
return 0;
}
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int x;
float y;
char z;
x=5;
y=4.4;
z='a';
cout<<endl<<"x is "<<x<<endl<<"y is "<<y<<endl<<"z is "<<z;
return 0;
}
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int x;
float y;
char z;
cout<<"Enter the value of x ";
cin>>x;
cout<<"Enter the value of y ";
cin>>y;
cout<<"Enter the value of z ";
cin>>z;
cout<<endl<<"x = "<<x;
cout<<endl<<"y = "<<y;
cout<<endl<<"z = "<<z;
return 0;
}
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int x;
float y;
char z;
cout<<"Enter the values of x, y & z ";
cin>>x>>y>>z;
cout<<"\nx = "<<x<<"\ny = "<<y<<"\nz = "<<z;
}
class class_name
{
Access_specifier:
data
code
Access_specifier:
data
code
----------
----------
----------
};
#include<iostream>
#include<conio.h>
using namespace std;
//Class Design
class demo
{
private:
int x;
public:
void getdata()
{
cout<<"\nEnter the value of x ";
cin>>x;
}
void showdata()
{
cout<<"\nValue of x "<<x;
}
};
int main()
{
demo d; //Creating Object
d.getdata();
d.showdata();
}
#include<iostream>
#include<conio.h>
using namespace std;
int x=55;//Global Variable
int main()
{
int x=22;//Local Variable
cout<<"\nLocal Value of x is "<<x;
cout<<"\nGlobal Value of x is "<<::x;
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
int rn;
float m;
char n[10];
public:
void getdata();
void showdata();
};
void student :: getdata()
{
cout<<"\nEnter your rn, name and marks ";
cin>>rn>>n>>m;
}
void student::showdata()
{
cout<<"\nyour rn is "<<rn;
cout<<"\nyour name is "<<n;
cout<<"\nyour marks is "<<m;
}
int main()
{
student s;
s.getdata();
s.showdata();
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
public:
int rn;
float m;
char n[10];
void getdata();
};
void student::getdata()
{
cout<<"\nEnter your rn, name and marks ";
cin>>rn>>n>>m;
}
void showdata(student st)
{
cout<<"\nyour rn is "<<st.rn;
cout<<"\nyour name is "<<st.n;
cout<<"\nyour marks is "<<st.m;
}
int main()
{
student s;
s.getdata();
showdata(s);
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
public:
int x,y;
void getdata()
{
cout<<"\nEnter the value of x & y ";
cin>>x>>y;
}
void showdata()
{
cout<<"\nx = "<<x;
cout<<"\ny = "<<y;
}
};
void add(demo obj1,demo obj2)
{
demo obj3;
obj3.x=obj1.x+obj2.x;
obj3.y=obj1.y+obj2.y;
obj3.showdata();
}
main()
{
demo ob1,ob2;
ob1.getdata();
ob2.getdata();
add(ob1,ob2);
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
public:
int rn;
float m;
char n[10];
void showdata();
};
student getdata()
{
student st;
cout<<"\nEnter your rn, name and marks ";
cin>>st.rn>>st.n>>st.m;
return st;
}
void student::showdata()
{
cout<<"\nyour rn is "<<rn;
cout<<"\nyour name is "<<n;
cout<<"\nyour marks is "<<m;
}
int main()
{
student s;
s=getdata();
s.showdata();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
public:
int x,y;
void getdata()
{
cout<<"\nEnter the value of x & y ";
cin>>x>>y;
}
void showdata()
{
cout<<"\nx = "<<x;
cout<<"\ny = "<<y;
}
};
demo add()
{
demo obj1,obj2,obj3;
obj1.getdata();
obj2.getdata();
obj3.x=obj1.x+obj2.x;
obj3.y=obj1.y+obj2.y;
return obj3;
}
main()
{
demo obj;
obj=add();
obj.showdata();
}
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
class student
{
public:
int rn;
float m;
char n[10];
void getdata();
void showdata();
};
void student::getdata()
{
cout<<"\nEnter your rn, name and marks ";
cin>>rn>>n>>m;
}
void student::showdata()
{
cout<<"\nyour rn is "<<rn;
cout<<"\nyour name is "<<n;
cout<<"\nyour marks is "<<m;
}
student modifydata(student st)
{
student rst;
rst.rn=st.rn+10;
strcpy(rst.n,st.n);
strcat(rst.n," Gupta");
rst.m=st.m+20;
return rst;
}
int main()
{
student s,rs;
s.getdata();
rs=modifydata(s);
rs.showdata();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
public:
int x,y;
void getdata()
{
cout<<"\nEnter the value of x & y ";
cin>>x>>y;
}
void showdata()
{
cout<<"\nx = "<<x;
cout<<"\ny = "<<y;
}
};
demo add(demo obj1,demo obj2)
{
demo obj3;
obj3.x=obj1.x+obj2.x;
obj3.y=obj1.y+obj2.y;
return obj3;
}
main()
{
demo ob1,ob2,ob3;
ob1.getdata();
ob2.getdata();
ob3=add(ob1,ob2);
ob3.showdata();
}
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
class student
{
int rn;
float m;
char n[10];
public:
void getdata();
void showdata();
student modifydata(student);
};
void student::getdata()
{
cout<<"\nEnter your rn, name and marks ";
cin>>rn>>n>>m;
}
void student::showdata()
{
cout<<"\nyour rn is "<<rn;
cout<<"\nyour name is "<<n;
cout<<"\nyour marks is "<<m;
}
student student::modifydata(student st)
{
student rst;
rst.rn=st.rn+10;
strcpy(rst.n,st.n);
strcat(rst.n," Gupta");
rst.m=st.m+20;
return rst;
}
int main()
{
student s,rs,temp;
s.getdata();
rs=temp.modifydata(s);
rs.showdata();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
int x,y;
public:
void getdata()
{
cout<<"\nEnter the value of x & y ";
cin>>x>>y;
}
void showdata()
{
cout<<"\nx = "<<x;
cout<<"\ny = "<<y;
}
demo add(demo obj2)
{
demo obj3;
obj3.x=x+obj2.x;
obj3.y=y+obj2.y;
return obj3;
}
};
main()
{
demo ob1,ob2,ob3;
ob1.getdata();
ob2.getdata();
ob3=ob1.add(ob2);
ob3.showdata();
}
#include<iostream>
#include<conio.h>
using namespace std;
void show()
{
cout<<"\nWelcome to BIIT";
}
void show(int x)
{
cout<<"\nvalue of x = "<<x;
}
main()
{
show();
show(5);
}
#include<iostream>
#include<conio.h>
using namespace std;
int area(int side)
{
int ar;
ar=side*side;
return ar;
}
float area(float rad)
{
float ar;
ar=3.14*rad*rad;
return ar;
}
int area(int len,int br)
{
int ar;
ar=len*br;
return ar;
}
main()
{
int sd,l,b;
float r;
cout<<"\nFor Square";
cout<<"\nEnter the Side of any Square ";
cin>>sd;
cout<<"\nArea of Square = "<<area(sd);
cout<<"\nFor Rectangle";
cout<<"\nEnter the Length & Bredth of any Rectangle ";
cin>>l>>b;
cout<<"\nArea of Rectangle = "<<area(l,b);
cout<<"\nFor Circle";
cout<<"\nEnter the Radius of any Circle ";
cin>>r;
cout<<"\nArea of Circle = "<<area(r);
}
#include<iostream>
#include<conio.h>
using namespace std;
class demooverload
{
public:
int area(int side)
{
int ar;
ar=side*side;
return ar;
}
float area(float rad)
{
float ar;
ar=3.14*rad*rad;
return ar;
}
int area(int len,int br)
{
int ar;
ar=len*br;
return ar;
}
};
main()
{
demooverload obj;
int sd,l,b;
float r;
cout<<"\nFor Square";
cout<<"\nEnter the Side of any Square ";
cin>>sd;
cout<<"\nArea of Square = "<<obj.area(sd);
cout<<"\nFor Rectangle";
cout<<"\nEnter the Length & Bredth of any Rectangle ";
cin>>l>>b;
cout<<"\nArea of Rectangle = "<<obj.area(l,b);
cout<<"\nFor Circle";
cout<<"\nEnter the Radius of any Circle ";
cin>>r;
cout<<"\nArea of Circle = "<<obj.area(r);
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
public:
demo()
{
cout<<"\nConstructor is being run";
}
};
main()
{
demo d;
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
int x;
public:
demo()
{
x=0;
}
void show()
{
cout<<"\nx = "<<x;
}
};
main()
{
demo d,a,b;
d.show();
a.show();
b.show();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
int x;
public:
demo(int p)
{
x=p;
}
void show()
{
cout<<"\nx = "<<x;
}
};
main()
{
demo obj1(55);
obj1.show();
demo obj2=155;
obj2.show();
int n=22;
demo obj3(n);
obj3.show();
cout<<"\nEnter the value of n ";
cin>>n;
demo obj4(n);
obj4.show();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
int x,y;
public:
demo(int p,int q)
{
x=p;
y=q;
}
void show()
{
cout<<"\nx = "<<x;
cout<<"\ny = "<<y;
}
};
main()
{
demo obj1(55,33);
obj1.show();
demo obj2={55,33};
obj2.show();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
int x;
public:
demo()
{
x=0;
}
demo(int p)
{
x=p;
}
demo(demo &d)//copy constructor
{
x=d.x;
}
void show()
{
cout<<"\nx = "<<x;
}
};
main()
{
demo obj1,obj2(99),obj3(obj1),obj4=obj2;
cout<<"\nObject 1";
obj1.show();
cout<<"\nObject 2";
obj2.show();
cout<<"\nObject 3";
obj3.show();
cout<<"\nObject 4";
obj4.show();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
int x;
public:
demo() //default constructor
{
x=0;
}
demo(int p)//parameterized constructor
{
x=p;
}
void show()
{
cout<<"\nx = "<<x;
}
};
main()
{
demo obj1,obj2(99);
obj1.show();
obj2.show();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
public:
~demo()
{
cout<<"\nDestructor is being run";
}
};
main()
{
demo d;
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
int x;
public:
demo()
{
x=55;
}
void show()
{
cout<<"\nx = "<<x;
}
~demo()
{
x=0;
}
};
main()
{
demo d;
d.show();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
int x,y;
public:
void getdata()
{
cout<<"\nEnter the value of x & y ";
cin>>x>>y;
}
void showdata()
{
cout<<"\nx = "<<x;
cout<<"\ny = "<<y;
}
demo operator+(demo obj2)
{
demo obj3;
obj3.x=x-obj2.x;
obj3.y=y*obj2.y;
return obj3;
}
};
main()
{
demo ob1,ob2,ob3;
ob1.getdata();
ob2.getdata();
ob3=ob1+ob2;
ob3.showdata();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
int x,y;
public:
void getdata()
{
cout<<"\nEnter the value of x & y ";
cin>>x>>y;
}
void showdata()
{
cout<<"\nx = "<<x;
cout<<"\ny = "<<y;
}
demo operator+(demo obj2)
{
demo obj3;
obj3.x=x+obj2.x;
obj3.y=y+obj2.y;
return obj3;
}
};
main()
{
demo ob1,ob2,ob3;
ob1.getdata();
ob2.getdata();
ob3=ob1+ob2;
ob3.showdata();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
int x,y;
public:
void getdata()
{
cout<<"\nEnter the value of x & y ";
cin>>x>>y;
}
void showdata()
{
cout<<"\nx = "<<x;
cout<<"\ny = "<<y;
}
demo operator++()
{
demo obj3;
obj3.x=x+1;
obj3.y=y+1;
return obj3;
}
};
main()
{
demo ob1,ob3;
ob1.getdata();
ob3=++ob1;
ob3.showdata();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
int x,y;
public:
void getdata()
{
cout<<"\nEnter the value of x & y ";
cin>>x>>y;
}
void showdata()
{
cout<<"\nx = "<<x;
cout<<"\ny = "<<y;
}
void operator++()
{
x++;
y++;
}
};
main()
{
demo ob1;
ob1.getdata();
++ob1;
ob1.showdata();
}
class demo
{
int x; //Member Data
void show() //Member function
{
…….
…….
}
};
class demo
{
…….
…….
};
void show() //Non-member function
{
…….
…….
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
public:
int x;
};
int main()
{
demo d;
cout<<"\nEnter the value of x ";
cin>>d.x;
cout<<"\nValue of x is "<<d.x;
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demo
{
private:
int x;
public:
void getdata()
{
cout<<"\nEnter the value of x ";
cin>>x;
}
void showdata()
{
cout<<"\nValue of x "<<x;
}
}d;
int main()
{
d.getdata();
d.showdata();
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
private:
int rn;
float m;
char n[10];
public:
void getdata()
{
cout<<"\nEnter your rn, name and marks ";
cin>>rn>>n>>m;
}
void showdata()
{
cout<<"\nyour rn is "<<rn;
cout<<"\nyour name is "<<n;
cout<<"\nyour marks is "<<m;
}
};
int main()
{
student s,st;
s.getdata();
st.getdata();
s.showdata();
st.showdata();
}
class demo
{
int x; //Member Data
void show() //Member function
{
…….
…….
}
};
class demo
{
…….
…….
};
void show() //Non-member function
{
…….
…….
}
#include<iostream>
#include<conio.h>
using namespace std;
class base
{
private:
int privdata;
protected:
int protdata;
public:
int pubdata;
void initdatainbase()
{
cout<<"\nInitdata In Base Class";
privdata=1;
protdata=2;
pubdata=3;
}
void showdatainbase()
{
cout<<"\nShowdata In Base Class";
cout<<"\nPrivdata = "<<privdata;
cout<<"\nProtdata = "<<protdata;
cout<<"\nPubdata = "<<pubdata;
}
};
class derived:public base
{
public:
void initdatainderived()
{
cout<<"\nInitdata In Derived Class";
//privdata=11;
protdata=22;
pubdata=33;
}
void showdatainderived()
{
cout<<"\nShowdata In Derived Class";
//cout<<"\nPrivdata = "<<privdata;
cout<<"\nProtdata = "<<protdata;
cout<<"\nPubdata = "<<pubdata;
}
};
class other
{
base b;
public:
void initdatainother()
{
cout<<"\nInitdata In other Class";
//privdata=111;
//protdata=222;
b.pubdata=333;
}
void showdatainother()
{
cout<<"\nShowdata In other Class";
//cout<<"\nPrivdata = "<<privdata;
//cout<<"\nProtdata = "<<protdata;
cout<<"\nPubdata = "<<b.pubdata;
}
};
main()
{
//base b;
derived d;
other o;
//b.initdatainbase();
//b.showdatainbase();
d.initdatainderived();
d.showdatainderived();
d.initdatainbase();
d.showdatainbase();
o.initdatainother();
o.showdatainother();
}
#include<iostream>
#include<conio.h>
using namespace std;
class other
{
base b;
public:
void initdatainother()
{
cout<<"\nInitdata In other Class";
//privdata=11;
//protdata=22;
b.pubdata=33;
}
void showdatainother()
{
cout<<"\nShowdata In other Class";
//cout<<"\nPrivdata = "<<privdata;
//cout<<"\nProtdata = "<<protdata;
cout<<"\nPubdata = "<<b.pubdata;
}
};
class emp
{
int eid;
public:
void getemp()
{
cout<<"\nEnter the Employee ID of employee ";
cin>>eid;
}
void showemp()
{
cout<<"\nEmployee ID = "<<eid;
}
};
class manager:public emp
{
char cat[10];
public:
void getmanager()
{
cout<<"\nEnter Category of Manager ";
cin>>cat;
}
void showmanager()
{
cout<<"\nCategory = "<<cat;
}
};
int main()
{
manager m;
m.getemp();
m.getmanager();
m.showemp();
m.showmanager();
}
#include<iostream>
#include<conio.h>
using namespace std;
class base
{
int x;
public:
void getdata()
{
cout<<"\nEnter the value of x ";
cin>>x;
}
void showdata()
{
cout<<"\nValue of x = "<<x;
}
};
class derived :public base
{
int y;
public:
void getdata()
{
base::getdata();
cout<<"\nEnter the value of y ";
cin>>y;
}
void showdata()
{
base::showdata();
cout<<"\nValue of y = "<<y;
}
};
main()
{
derived d;
d.getdata();
d.showdata();
getch();
}
Difference Between Overloading & Overriding
Function Overloading | Function Overriding |
---|---|
It is possible in single class also. | It is not possible in single class but it is possible in the base and derived class. |
It is possible that more than one definition of a function can be defined in single class. | It is not possible to have more than one definition in single class but if one body is defined in base class then other body can be defined inside its derived class only. |
Prototypes of all functions must be different. | Prototypes of all functions must be same. |
#include<iostream>
#include<conio.h>
using namespace std;
class employee
{
int e_id;
char e_name[20];
public:
void getdata()
{
cout<<endl<<"Enter the Employee ID & Employee Name ";
cin>>e_id>>e_name;
}
void showdata()
{
cout<<endl<<"Employee ID\t: "<<e_id;
cout<<endl<<"Employee Name\t: "<<e_name;
}
};
class manager : public employee
{
char dept[20],cat[20];
public:
void getdata()
{
employee::getdata();
cout<<endl<<"Enter the Category & Department name ";
cin>>cat>>dept;
}
void showdata()
{
employee::showdata();
cout<<endl<<"Category\t: "<<cat;
cout<<endl<<"Department\t: "<<dept;
}
};
main()
{
manager m;
m.getdata();
m.showdata();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class person
{
int p_ano;
char p_name[20];
protected:
void getdata()
{
cout<<endl<<"Enter the Aadhar No & Name ";
cin>>p_ano>>p_name;
}
void showdata()
{
cout<<endl<<"Aadhar No\t: "<<p_ano;
cout<<endl<<"Name\t\t: "<<p_name;
}
};
class student : public person
{
int r_no;
char qual[20];
protected:
void getdata()
{
person::getdata();
cout<<endl<<"Enter the Roll No & Qualification ";
cin>>r_no>>qual;
}
void showdata()
{
person::showdata();
cout<<endl<<"Roll No\t\t: "<<r_no;
cout<<endl<<"Qualification\t: "<<qual;
}
};
class employee : public student
{
int e_id;
double e_sal;
public:
void getdata()
{
student::getdata();
cout<<endl<<"Enter the Employee ID & Salary ";
cin>>e_id>>e_sal;
}
void showdata()
{
student::showdata();
cout<<endl<<"Employee ID\t: "<<e_id;
cout<<endl<<"Salary\t\t: "<<e_sal;
}
};
class manager : public employee
{
char dept[20],cat[20];
public:
void getdata()
{
employee::getdata();
cout<<endl<<"Enter the Category & Department name ";
cin>>cat>>dept;
}
void showdata()
{
employee::showdata();
cout<<endl<<"Category\t: "<<cat;
cout<<endl<<"Department\t: "<<dept;
}
};
main()
{
manager m;
m.getdata();
m.showdata();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class employee
{
int e_id;
char e_name[20];
public:
void getdata()
{
cout<<endl<<"Enter the Employee ID & Employee Name ";
cin>>e_id>>e_name;
}
void showdata()
{
cout<<endl<<"Employee ID\t: "<<e_id;
cout<<endl<<"Employee Name\t: "<<e_name;
}
};
class manager : public employee
{
char dept[20],cat[20];
public:
void getdata()
{
employee::getdata();
cout<<endl<<"Enter the Category & Department name ";
cin>>cat>>dept;
}
void showdata()
{
employee::showdata();
cout<<endl<<"Category\t: "<<cat;
cout<<endl<<"Department\t: "<<dept;
}
};
class scientist : public employee
{
char no_rp[20];
public:
void getdata()
{
employee::getdata();
cout<<endl<<"Enter the No. of Research Papers Published ";
cin>>no_rp;
}
void showdata()
{
employee::showdata();
cout<<endl<<"No. of \t\t: "<<no_rp<<endl<<"Research Papers ";
}
};
class laborer : public employee
{
};
main()
{
manager m;
scientist s;
laborer l;
cout<<endl<<endl<<"Manager";
m.getdata();
cout<<endl<<endl<<"Scientist";
s.getdata();
cout<<endl<<endl<<"Laborer";
l.getdata();
cout<<endl<<endl<<"Manager";
m.showdata();
cout<<endl<<endl<<"Scientist";
s.showdata();
cout<<endl<<endl<<"Laborer";
l.showdata();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class A
{
...........
...........
...........
};
class B
{
...........
...........
...........
};
class C:public A, public B
{
...........
...........
...........
};
void main()
{
...........
...........
...........
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
int r_no;
char qual[20],name[20];
protected:
void getdata()
{
cout<<endl<<"Enter the Roll No, Name & Qualification ";
cin>>r_no>>name>>qual;
}
void showdata()
{
cout<<endl<<"Roll No\t\t: "<<r_no;
cout<<endl<<"Name\t\t: "<<name;
cout<<endl<<"Qualification\t: "<<qual;
}
};
class employee
{
int e_id;
double e_sal;
public:
void getdata()
{
cout<<endl<<"Enter the Employee ID & Salary ";
cin>>e_id>>e_sal;
}
void showdata()
{
cout<<endl<<"Employee ID\t: "<<e_id;
cout<<endl<<"Salary\t\t: "<<e_sal;
}
};
class manager : public student, public employee
{
char dept[20],cat[20];
public:
void getdata()
{
student::getdata();
employee::getdata();
cout<<endl<<"Enter the Category & Department name ";
cin>>cat>>dept;
}
void showdata()
{
student::showdata();
employee::showdata();
cout<<endl<<"Category\t: "<<cat;
cout<<endl<<"Department\t: "<<dept;
}
};
main()
{
manager m;
m.getdata();
m.showdata();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
int r_no;
char qual[20];
protected:
void getdata()
{
cout<<endl<<"Enter the Roll No & Qualification ";
cin>>r_no>>qual;
}
void showdata()
{
cout<<endl<<"Roll No\t\t: "<<r_no;
cout<<endl<<"Qualification\t: "<<qual;
}
};
class employee
{
int e_id;
char e_name[20];
double e_sal;
public:
void getdata()
{
cout<<endl<<"Enter the Employee ID, Name & Salary ";
cin>>e_id>>e_name>>e_sal;
}
void showdata()
{
cout<<endl<<"Employee ID\t: "<<e_id;
cout<<endl<<"Name\t\t: "<<e_name;
cout<<endl<<"Salary\t\t: "<<e_sal;
}
};
class manager : public student, public employee
{
char dept[20],cat[20];
public:
void getdata()
{
student::getdata();
employee::getdata();
cout<<endl<<"Enter the Category & Department name ";
cin>>cat>>dept;
}
void showdata()
{
student::showdata();
employee::showdata();
cout<<endl<<"Category\t: "<<cat;
cout<<endl<<"Department\t: "<<dept;
}
};
class scientist : public student, public employee
{
char no_rp[20];
public:
void getdata()
{
student::getdata();
employee::getdata();
cout<<endl<<"Enter the No. of Research Papers Published ";
cin>>no_rp;
}
void showdata()
{
student::showdata();
employee::showdata();
cout<<endl<<"No. of \t\t: "<<no_rp<<endl<<"Research Papers ";
}
};
class laborer : public employee
{
};
main()
{
manager m;
scientist s;
laborer l;
cout<<endl<<endl<<"Manager";
m.getdata();
cout<<endl<<endl<<"Scientist";
s.getdata();
cout<<endl<<endl<<"Laborer";
l.getdata();
cout<<endl<<endl<<"Manager";
m.showdata();
cout<<endl<<endl<<"Scientist";
s.showdata();
cout<<endl<<endl<<"Laborer";
l.showdata();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class base
{
public:
base()
{
cout<<endl<<"Constructor of Base class";
}
};
class derived1 : public base
{
public:
derived1()
{
cout<<endl<<"Constructor of Derived1 class";
}
};
class derived2 : public base
{
public:
derived2()
{
cout<<endl<<"Constructor of Derived2 class";
}
};
class derived3 : public derived1
{
public:
derived3()
{
cout<<endl<<"Constructor of Derived3 class";
}
};
main()
{
cout<<endl<<"When object of derived3 class is created";
derived3 d3;
cout<<endl<<"When object of derived2 class is created";
derived2 d2;
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class base
{
int x;
public:
base(int a)
{
x=a;
}
void show()
{
cout<<endl<<"x = "<<x;
}
};
class derived1 : public base
{
int y;
public:
derived1(int b):base(b)
{
y=b;
}
void show()
{
base::show();
cout<<endl<<"y = "<<y;
}
};
class derived2 : public base
{
int z;
public:
derived2(int c):base(c)
{
z=c;
}
void show()
{
base::show();
cout<<endl<<"z = "<<z;
}
};
class derived3 : public derived1
{
int w;
public:
derived3(int d):derived1(d)
{
w=d;
}
void show()
{
derived1::show();
cout<<endl<<"w = "<<w;
}
};
main()
{
cout<<endl<<"When object of derived3 class is created";
derived3 d3(90);
d3.show();
cout<<endl<<"When object of derived2 class is created";
derived2 d2(50);
d2.show();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class base
{
public:
~base()
{
cout<<endl<<"Destructor of Base class";
}
};
class derived1 : public base
{
public:
~derived1()
{
cout<<endl<<"Destructor of Derived1 class";
}
};
class derived2 : public base
{
public:
~derived2()
{
cout<<endl<<"Destructor of Derived2 class";
}
};
class derived3 : public derived1
{
public:
~derived3()
{
cout<<endl<<"Destructor of Derived3 class";
}
};
main()
{
cout<<endl<<"When object of derived3 class is created";
derived3 d3;
cout<<endl<<"When object of derived2 class is created";
derived2 d2;
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class base
{
public:
base()
{
cout<<endl<<"Constructor of Base class";
}
~base()
{
cout<<endl<<"Destructor of Base class";
}
};
class derived1 : public base
{
public:
derived1()
{
cout<<endl<<"Constructor of Derived1 class";
}
~derived1()
{
cout<<endl<<"Destructor of Derived1 class";
}
};
class derived2 : public base
{
public:
derived2()
{
cout<<endl<<"Constructor of Derived2 class";
}
~derived2()
{
cout<<endl<<"Destructor of Derived2 class";
}
};
class derived3 : public derived1
{
public:
derived3()
{
cout<<endl<<"Constructor of Derived3 class";
}
~derived3()
{
cout<<endl<<"Destructor of Derived3 class";
}
};
main()
{
cout<<endl<<"When object of derived3 class is created";
derived3 d3;
cout<<endl<<"When object of derived2 class is created";
derived2 d2;
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class Base1
{
public:
void show()
{
cout<<endl<<"show() function of Base 1 Class";
}
};
class Base2
{
public:
void show()
{
cout<<endl<<"show() function of Base 2 Class";
}
};
class Derived:public Base1, public Base2
{
};
main()
{
Derived d;
d.Base1::show();
d.Base2::show();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class base
{
private:
int privdata;
protected:
int protdata;
public:
int pubdata;
void function1()
{
privdata=1; //OK
protdata=2; //OK
pubdata=3; //OK
}
};
class derived1:public base
{
public:
void function2()
{
privdata=11;//ERROR
protdata=22;//OK
pubdata=33;//OK
}
};
class derived2:protected base
{
public:
void function3()
{
privdata=111;//ERROR
protdata=222;//OK
pubdata=333;//OK
}
};
class derived3:private base
{
public:
void function4()
{
privdata=1111;//ERROR
protdata=2222;//OK
pubdata=3333;//OK
}
};
main()
{
base b;
derived1 d1;
derived2 d2;
derived3 d3;
b.privdata=9;//ERROR
b.protdata=9;//ERROR
b.pubdata=9;//OK
d1.privdata=8;//ERROR
d1.protdata=8;//ERROR
d1.pubdata=8;//OK
d2.privdata=7;//ERROR
d2.protdata=7;//ERROR
d2.pubdata=7;//ERROR
d3.privdata=6;//ERROR
d3.protdata=6;//ERROR
d3.pubdata=6;//ERROR
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
int r_no;
char qual[20];
protected:
void getdata()
{
cout<<endl<<"Enter the Roll No & Qualification ";
cin>>r_no>>qual;
}
void showdata()
{
cout<<endl<<"Roll No\t\t: "<<r_no;
cout<<endl<<"Qualification\t: "<<qual;
}
};
class employee
{
int e_id;
char e_name[20];
double e_sal;
public:
void getdata()
{
cout<<endl<<"Enter the Employee ID, Name & Salary ";
cin>>e_id>>e_name>>e_sal;
}
void showdata()
{
cout<<endl<<"Employee ID\t: "<<e_id;
cout<<endl<<"Name\t\t: "<<e_name;
cout<<endl<<"Salary\t\t: "<<e_sal;
}
};
class manager : private student, private employee
{
char dept[20],cat[20];
public:
void getdata()
{
student::getdata();
employee::getdata();
cout<<endl<<"Enter the Category & Department name ";
cin>>cat>>dept;
}
void showdata()
{
student::showdata();
employee::showdata();
cout<<endl<<"Category\t: "<<cat;
cout<<endl<<"Department\t: "<<dept;
}
};
class scientist : private student, private employee
{
char no_rp[20];
public:
void getdata()
{
student::getdata();
employee::getdata();
cout<<endl<<"Enter the No. of Research Papers Published ";
cin>>no_rp;
}
void showdata()
{
student::showdata();
employee::showdata();
cout<<endl<<"No. of \t\t: "<<no_rp<<endl<<"Research Papers ";
}
};
class laborer : protected employee
{
};
class dailywage:private laborer
{
double wage;
public:
void getdata()
{
employee::getdata();
cout<<endl<<"Enter the wage of laborer ";
cin>>wage;
}
void showdata()
{
employee::showdata();
cout<<endl<<"Wage\t\t: "<<wage;
}
};
class monthly:private laborer
{
double salary;
public:
void getdata()
{
employee::getdata();
cout<<endl<<"Enter the Salary of laborer ";
cin>>salary;
}
void showdata()
{
employee::showdata();
cout<<endl<<"Salary\t\t: "<<salary;
}
};
main()
{
manager ma;
scientist s;
dailywage d;
monthly m;
cout<<endl<<endl<<"Manager";
ma.getdata();
cout<<endl<<endl<<"Scientist";
s.getdata();
cout<<endl<<endl<<"Daily Wage Laborer";
d.getdata();
cout<<endl<<endl<<"Monthly Laborer";
m.getdata();
cout<<endl<<endl<<"Manager";
ma.showdata();
cout<<endl<<endl<<"Scientist";
s.showdata();
cout<<endl<<endl<<"Daily Wage Laborer";
d.showdata();
cout<<endl<<endl<<"Monthly Laborer";
m.showdata();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class A
{
public:
void show()
{
cout<<endl<<"show() function of class A";
}
};
class B:public virtual A
{
};
class C:public virtual A
{
};
class D:public B, public C
{
};
main()
{
D obj;
obj.show();
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
int rn;
float m;
char n[20];
public:
void getdata()
{
cout<<endl<<"Enter the roll number, name and marks ";
cin>>rn>>n>>m;
}
void showdata()
{
cout<<endl<<"Roll number\t: "<<rn;
cout<<endl<<"Name\t\t: "<<n;
cout<<endl<<"Marks\t\t: "<<m;
}
};
main()
{
int i;
student s[2];//Array of objects
for(i=0;i<2;i++)
{
cout<<endl<<"Student "<<(i+1);
s[i].getdata();
}
for(i=0;i<2;i++)
{
cout<<endl<<"Student "<<(i+1);
s[i].showdata();
}
}
#include<iostream>
#include<conio.h>
using namespace std;
class outer
{
public:
class inner
{
private:
int x;
public:
void getdata()
{
cout<<endl<<"Enter the value of x ";
cin>>x;
}
void showdata()
{
cout<<endl<<"value of x is "<<x;
}
};
};
main()
{
outer::inner obj;
obj.getdata();
obj.showdata();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class outer
{
class inner
{
private:
int x;
public:
void getdata()
{
cout<<endl<<"Enter the value of x ";
cin>>x;
}
void showdata()
{
cout<<endl<<"value of x is "<<x;
}
};
public:
inner i;
};
main()
{
outer obj;
obj.i.getdata();
obj.i.showdata();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class outer
{
private:
int x;
class inner
{
private:
int y;
public:
void getdata()
{
cout<<endl<<"Enter the value of y ";
cin>>y;
}
void showdata()
{
cout<<endl<<"value of y is "<<y;
}
};
public:
inner i;
void getdata()
{
cout<<endl<<"Enter the value of x ";
cin>>x;
}
void showdata()
{
cout<<endl<<"value of x is "<<x;
}
};
main()
{
outer obj;
obj.getdata();
obj.showdata();
obj.i.getdata();
obj.i.showdata();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class inner
{
private:
int y;
public:
void getdata()
{
cout<<endl<<"Enter the value of y ";
cin>>y;
}
void showdata()
{
cout<<endl<<"value of y is "<<y;
}
};
class outer
{
private:
int x;
public:
inner i;
void getdata()
{
cout<<endl<<"Enter the value of x ";
cin>>x;
}
void showdata()
{
cout<<endl<<"value of x is "<<x;
}
};
main()
{
outer obj;
obj.getdata();
obj.showdata();
obj.i.getdata();
obj.i.showdata();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class inner
{
public:
int y;
};
class outer
{
private:
int x;
public:
inner i;
void getdata()
{
cout<<endl<<"Enter the value of x & y ";
cin>>x>>i.y;
}
void showdata()
{
cout<<endl<<"value of x is "<<x;
cout<<endl<<"value of y is "<<i.y;
}
};
main()
{
outer obj;
obj.getdata();
obj.showdata();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
private:
int rn;
float m;
char n[10];
public:
void getdata()
{
cout<<"\nEnter your rn, name and marks ";
cin>>rn>>n>>m;
}
void showdata()
{
cout<<"\nyour rn is "<<rn;
cout<<"\nyour name is "<<n;
cout<<"\nyour marks is "<<m;
}
};
int main()
{
student s,*ptr;
s.getdata();
ptr=&s;
ptr->showdata();
}
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
main()
{
char str[20],*ptr;
int l;
cout<<endl<<"Enter any string ";
cin>>str;
l=strlen(str);
ptr=new char[l+1];
cout<<endl<<"Before copy";
cout<<endl<<"str = "<<str;
cout<<endl<<"ptr = "<<ptr;
strcpy(ptr,str);
cout<<endl<<"After copy";
cout<<endl<<"str = "<<str;
cout<<endl<<"ptr = "<<ptr;
delete ptr;
}
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
class demoptr
{
public:
char *ptr;
demoptr(int l)
{
ptr=new char[l+1];
}
~demoptr()
{
delete ptr;
}
};
main()
{
char str[20];
int l;
cout<<endl<<"Enter any string ";
cin>>str;
l=strlen(str);
demoptr obj(l);
cout<<endl<<"Before copy";
cout<<endl<<"str = "<<str;
cout<<endl<<"ptr = "<<obj.ptr;
strcpy(obj.ptr,str);
cout<<endl<<"After copy";
cout<<endl<<"str = "<<str;
cout<<endl<<"ptr = "<<obj.ptr;
}
#include<iostream>
#include<conio.h>
using namespace std;
class demothis
{
private:
int x;
public:
demothis()
{
this->x=55;
}
void showdata()
{
cout<<"\nValue of x "<<this->thix;
}
};
int main()
{
demothis d,d1;
d.showdata();
d1.showdata();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demoinline
{
private:
int x;
public:
void getdata()
{
cout<<endl<<"Enter the value of x ";
cin>>x;
}
void showdata()
{
cout<<"\nValue of x "<<x;
}
};
int main()
{
demoinline obj;
obj.getdata();
obj.showdata();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demoinline
{
private:
int x;
public:
inline void getdata();
inline void showdata();
};
void demoinline::getdata()
{
cout<<endl<<"Enter the value of x ";
cin>>x;
}
void demoinline::showdata()
{
cout<<"\nValue of x "<<x;
}
int main()
{
demoinline obj;
obj.getdata();
obj.showdata();
}
#include<iostream>
#include<conio.h>
using namespace std;
class demofriend
{
private:
int x;
public:
void getdata()
{
cout<<endl<<"Enter the value of x ";
cin>>x;
}
friend void showdata(demofriend d);
};
void showdata(demofriend d)
{
cout<<"\nValue of x "<<d.x;
}
int main()
{
demofriend obj;
obj.getdata();
showdata(obj);
}
#include<iostream>
#include<conio.h>
using namespace std;
class B;
class A
{
int x;
public:
void getdata()
{
cout<<endl<<"Enter the value of x ";
cin>>x;
}
friend void showadd(A,B);
};
class B
{
int y;
public:
void getdata()
{
cout<<endl<<"Enter the value of y ";
cin>>y;
}
friend void showadd(A,B);
};
void showadd(A obj1,B obj2)
{
int z;
z=obj1.x+obj2.y;
cout<<endl<<"Sum is "<<z;
}
main()
{
A ob1;
B ob2;
ob1.getdata();
ob2.getdata();
showadd(ob1,ob2);
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class base
{
public:
virtual void vfun()
{
cout<<endl<<"Virtual function of base class";
}
};
class derived:public base
{
public:
void vfun()
{
cout<<endl<<"Virtual function of derived class";
}
};
main()
{
base b, *ptr;
derived d;
ptr=&b;
ptr->vfun();//base class
ptr=&d;
ptr->vfun();//derived class
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class base
{
public:
virtual void vfun()
{
cout<<endl<<"Virtual function of base class";
}
};
class derived1:public base
{
public:
void vfun()
{
cout<<endl<<"Virtual function of derived 1 class";
}
};
class derived2:public base
{
public:
void vfun()
{
cout<<endl<<"Virtual function of derived 2 class";
}
};
main()
{
base b, *ptr;
derived1 d1;
derived2 d2;
ptr=&b;
ptr->vfun();//base class
ptr=&d1;
ptr->vfun();//derived1 class
ptr=&d2;
ptr->vfun();//derived2 class
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class base
{
public:
virtual void vfun()
{
cout<<endl<<"Virtual function of base class";
}
};
class derived1:public base
{
public:
void vfun()
{
cout<<endl<<"Virtual function of derived 1 class";
}
};
class derived2:public derived1
{
public:
void vfun()
{
cout<<endl<<"Virtual function of derived 2 class";
}
};
main()
{
base b, *ptr;
derived1 d1;
derived2 d2;
ptr=&b;
ptr->vfun();//base class
ptr=&d1;
ptr->vfun();//derived1 class
ptr=&d2;
ptr->vfun();//derived2 class
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class base
{
public:
virtual void vfun()
{
cout<<endl<<"Virtual function of base class";
}
};
class derived1:public base
{
};
class derived2:public derived1
{
public:
void vfun()
{
cout<<endl<<"Virtual function of derived 2 class";
}
};
main()
{
base b, *ptr;
derived1 d1;
derived2 d2;
ptr=&b;
ptr->vfun();//base class
ptr=&d1;
ptr->vfun();//base class
ptr=&d2;
ptr->vfun();//derived2 class
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class base
{
public:
virtual void vfun()=0; //Pure Virtual function
};
class derived:public base
{
public:
void vfun()
{
cout<<endl<<"Virtual function of derived class";
}
};
main()
{
base *ptr;
derived d;
ptr=&d;
ptr->vfun();//derived class
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class base //Abstract class
{
public:
virtual void vfun()=0; //Pure Virtual function
};
class derived:public base
{
public:
void vfun()
{
cout<<endl<<"Virtual function of derived class";
}
};
main()
{
base *ptr;
derived d;
ptr=&d;
ptr->vfun();//derived class
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
class base //Abstract class
{
public:
virtual void vfun()=0; //Pure Virtual function
void show()
{
cout<<endl<<"I am in Show() function of Base class";
}
};
class derived:public base
{
public:
void vfun()
{
cout<<endl<<"Virtual function of derived class";
}
};
main()
{
base *ptr;
derived d;
ptr=&d;
ptr->vfun();//derived class
d.show();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
ofstream obj("fileout.txt");
obj<<"Welcome Students to BIIT";
cout<<endl<<"Data is written";
getch();
obj.close();
}
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
ifstream obj("fileout.txt");
char line[80];
obj>>line;
cout<<endl<<line;
obj.close();
}
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
ifstream obj("fileout.txt");
char line[80];
obj.getline(line,80);
cout<<endl<<line;
obj.close();
}
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
ofstream obj;
obj.open("fileout.txt");
char str[80],choice;
do
{
cout<<"Enter the line "<<endl;
cin.getline(str,80);
obj<<str<<endl;
cout<<"Do you want more ";
cin>>choice;
cin.ignore();
}while(choice=='y'||choice=='Y');
cout<<endl<<"Data is written";
getch();
obj.close();
}
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
ifstream obj;
obj.open("fileout.txt");
char line[80];
do
{
obj.getline(line,80);
cout<<endl<<line;
}while(!obj.eof());
getch();
obj.close();
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
int rn;
float marks;
char name[20];
public:
void getdata()
{
cout<<endl<<"Enter the rn, name & marks of a student ";
cin>>rn>>name>>marks;
}
};
main()
{
ofstream obj;
student s;
obj.open("fileout.txt");
s.getdata();
obj.write((char*)&s,sizeof(s));
cout<<"Record is written";
getch();
obj.close();
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
int rn;
float marks;
char name[20];
public:
void showdata()
{
cout<<endl<<"Roll number = "<<rn;
cout<<endl<<"Name\t= "<<name;
cout<<endl<<"Marks\t= "<<marks;
}
};
main()
{
ifstream obj;
student s;
obj.open("fileout.txt");
obj.read((char*)&s,sizeof(s));
s.showdata();
getch();
obj.close();
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
int rn;
float marks;
char name[20];
public:
void getdata()
{
cout<<endl<<"Enter the rn, name & marks of a student ";
cin>>rn>>name>>marks;
}
};
main()
{
ofstream obj;
student s;
char choice;
obj.open("fileout.txt");
do
{
s.getdata();
obj.write((char*)&s,sizeof(s));
cout<<"Do you want more ";
cin>>choice;
}while(choice=='y'||choice=='Y');
getch();
obj.close();
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
int rn;
float marks;
char name[20];
public:
void showdata()
{
cout<<endl<<"Roll number = "<<rn;
cout<<endl<<"Name\t= "<<name;
cout<<endl<<"Marks\t= "<<marks;
}
};
main()
{
ifstream obj;
student s;
obj.open("fileout.txt");
obj.read((char*)&s,sizeof(s));
do
{
s.showdata();
obj.read((char*)&s,sizeof(s));
}while(!obj.eof());
getch();
obj.close();
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
int rn;
float marks;
char name[20];
public:
void getdata()
{
cout<<endl<<"Enter the rn, name & marks of a student ";
cin>>rn>>name>>marks;
}
void showdata()
{
cout<<endl<<"Roll number = "<<rn;
cout<<endl<<"Name\t= "<<name;
cout<<endl<<"Marks\t= "<<marks;
}
};
main()
{
ofstream obj;
student s1,s2;
obj.open("fileout.txt");
s1.getdata();
obj.write((char*)&s1,sizeof(s1));
obj.close();
ifstream ob;
ob.open("fileout.txt");
ob.read((char*)&s2,sizeof(s2));
s2.showdata();
getch();
ob.close();
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
int rn;
float marks;
char name[20];
public:
void getdata()
{
cout<<endl<<"Enter the rn, name & marks of a student ";
cin>>rn>>name>>marks;
}
void showdata()
{
cout<<endl<<"Roll number = "<<rn;
cout<<endl<<"Name\t= "<<name;
cout<<endl<<"Marks\t= "<<marks;
}
};
main()
{
fstream obj;
student s1,s2;
obj.open("fileout.txt",ios::out|ios::in);
s1.getdata();
obj.write((char*)&s1,sizeof(s1));
obj.seekg(0);
obj.read((char*)&s2,sizeof(s2));
s2.showdata();
getch();
obj.close();
}
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
int rn;
float marks;
char name[20];
public:
void showdata()
{
cout<<endl<<"Roll number = "<<rn;
cout<<endl<<"Name\t= "<<name;
cout<<endl<<"Marks\t= "<<marks;
}
};
main()
{
ifstream obj;
student s;
int num,loc;
obj.open("fileout.txt");
//From Begining
cout<<endl<<"Current Position : "<<obj.tellg();
cout<<endl<<"Enter the record number (from Begining) ";
cin>>num;
loc=(num-1)*sizeof(s);
obj.seekg(loc,ios::beg);
cout<<endl<<"Current Position : "<<obj.tellg();
obj.read((char*)&s,sizeof(s));
s.showdata();
cout<<endl<<"Current Position : "<<obj.tellg();
//From End
cout<<endl<<"Enter the record number (from End) ";
cin>>num;
loc=-1*(num)*sizeof(s);
obj.seekg(loc,ios::end);
cout<<endl<<"Current Position : "<<obj.tellg();
obj.read((char*)&s,sizeof(s));
s.showdata();
cout<<endl<<"Current Position : "<<obj.tellg();
//From Current Position in forward direction
cout<<endl<<"Enter the record number (from Current Position in Forward direction) ";
cin>>num;
loc=(num-1)*sizeof(s);
obj.seekg(loc,ios::cur);
cout<<endl<<"Current Position : "<<obj.tellg();
obj.read((char*)&s,sizeof(s));
s.showdata();
cout<<endl<<"Current Position : "<<obj.tellg();
//From Current Position in backward direction
cout<<endl<<"Enter the record number (from Current Position in Backward direction) ";
cin>>num;
loc=-1*(num+1)*sizeof(s);
obj.seekg(loc,ios::cur);
cout<<endl<<"Current Position : "<<obj.tellg();
obj.read((char*)&s,sizeof(s));
s.showdata();
cout<<endl<<"Current Position : "<<obj.tellg();
getch();
obj.close();
}
#include<iostream>
#include<conio.h>
using namespace std;
namespace a
{
class demo
{
public:
void show()
{
cout<<"\nIn the namespace A";
}
};
}
namespace b
{
class demo
{
public:
void show()
{
cout<<"\nIn the namespace B";
}
};
}
using namespace a;
using namespace b;
main()
{
a::demo d;
b::demo d1;
d.show();
d1.show();
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
template <class dtype>
void show(dtype a) //Generic Function
{
cout<<endl<<a;
}
main()
{
int i=44;
float j=45.5;
char k='a';
cout<<"\nInteger";
show(i);
cout<<"\nFloat";
show(j);
cout<<"\nCharacter";
show(k);
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
template &tl;class ctyp>
class demo //Generic Class
{
public:
void show(ctyp p)
{
cout<<endl<<p;
}
};
main()
{
demo<char> d;
cout<<"\nCharacter";
d.show('a');
demo<int> d1;
cout<<"\nInteger";
d1.show(11);
demo<float> d2;
cout<<"\nFloat";
d2.show(22.33);
getch();
}