Oops Practical 05 by 31
Oops Practical 05 by 31
INSTITUTE OF TECHNOLOGY
DHULE (M.S.)
DEPARMENT OF COMPUTER ENGINEERING
Remark
Subject :Object Oriented programming in c++
Code: assignment
#include <iostream>
using namespace std;
class student{
public:
int stuid;
int rollno;
char branch[10];
long int phno;
void studinfo(){
cout<<"enter the student id";
cin>>stuid;
cout<<"\nenter the student roll no";
cin>>rollno;
cout<<"\nenter the student branch";
cin>>branch;
cout<<"\nenter the student ph no";
cin>>phno;
}
void studinfoput(){
cout<<stuid<<"\n"<<rollno<<"\n"<<branch<<"\n"<<phno;
}
};
class faculty{
public:
int facultyid;
long int fphno;
void facultyinfo(){
cout<<"enter the faculty id";
cin>>facultyid;
cout<<"enter the faculty phone no ";
cin>>fphno;
}
void facultyinfoput(){
cout<<"\n"<<facultyid<<"\n"<<fphno;}
};
class adress{
public:
long int stno,pincode;
char nearloc[100],state[10];
void addinfo(){
cout<<"enter street no, near location,state,pincode respectively";
cin>>stno>>nearloc>>state>>pincode;
}
void addinfoput(){
cout<<"\n"<<stno<<"\n"<<nearloc<<"\n"<<state<<"\n"<<pincode;
}
};
class person:public student,public faculty,public adress{
public:
char name[10];
long int adno;
void personinfo(){
cout<<"enter the person name ";
cin>>name;
cout<<"enter the adhar no";
cin>>adno;}
void personinfoput(){
cout<<"\nperson info"<<name<<"\n"<<adno;
};
int main(){
person p1;
p1. studinfo();
p1.studinfoput();
p1.facultyinfo();
p1.facultyinfoput();
p1.addinfo();
p1.addinfoput();
p1. personinfo();
p1. personinfoput();
Output:
enter the student id1234
223
1234567enter street no, near location,state,pincode respectively23
sdrfg
maharastra
23456
31
sdrfg
maharastra
23456enter the person name nipun
enter the adhar no123345
person infonipun
123345
code:operator overloading
#include <iostream>
using namespace std;
class Complex {
private:
int real, imag;
public:
Complex(int r = 0, int i = 0)
{
real = r;
imag = i;
}
int main()
{
Complex c1(10, 8), c2(2, 3);
Complex c3 = c1 + c2;
c3.print();
}
Output:
12 + i11