0% found this document useful (0 votes)
5 views

Oops Practical 05 by 31

C++ program language

Uploaded by

prasadnerkar434
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Oops Practical 05 by 31

C++ program language

Uploaded by

prasadnerkar434
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Shri Vile Parle Kelavani Mandal's

INSTITUTE OF TECHNOLOGY
DHULE (M.S.)
DEPARMENT OF COMPUTER ENGINEERING
Remark
Subject :Object Oriented programming in c++

Name : Chetan Sharad Gujar Roll No. : 31

Class :SY comp Batch : S2 Division: B


Signature
Expt. No. :05 Date : /08/2024

Title : implementation of operator overloading

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

enter the student roll no23

enter the student branchcompputer


enter the student ph no45123456
1234
23
computer
45123456eneter the faculty id223
eneter the faculty phone no 1234567

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;
}

Complex operator+(Complex const& obj)


{
Complex res;
res.real = real + obj.real;
res.imag = imag + obj.imag;
return res;
}
void print() { cout << real << " + i" << imag << '\n'; }
};

int main()
{
Complex c1(10, 8), c2(2, 3);
Complex c3 = c1 + c2;
c3.print();
}
Output:
12 + i11

You might also like