DAVIET/CSE/1241647: Program 12: WAP To Add Complex Nos Using Structures

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 49

DAVIET/CSE/1241647

Program 12: WAP to add complex nos using structures

#include<iostream.h>
#include<conio.h>
struct complex
{
float real;
float img;
};
void main()
{
clrscr();
complex c1,c2,c3;
cout<<"roll no=118"<<endl;
cout<<"enter first complex no"<<endl;
cin>>c1.real>>c1.img;
cout<<"enter second no"<<endl;
cin>>c2.real>>c2.img;
cout<<"first complex no"<<endl;
cout<<c1.real<<"+i"<<c1.img<<endl;
cout<<"second complex no"<<endl;
cout<<c2.real<<"+i"<<c2.img<<endl;
c3.real=c1.real+c2.real;
c3.img=c1.img+c2.img;
cout<<"sum of 2 complex nos"<<c3.real<<"+i"<<c3.img;
getch();
}
Output:

OOPS LAB Page 20


DAVIET/CSE/1241647

Program 13: WAP to illustrate concept of virtual base class

#include<iostream.h>
#include<conio.h>
class grandparent
{
protected:
int base_data;
public:
void readgp()
{
cout<<"roll no=118"<<endl;
cout<<"enter data of grand parent"<<endl;
cin>>base_data;
}
};
class parent1: virtual public grandparent
{
protected:
int parent1_data;
public:
void readp1()
{
cout<<"enter data of parent1"<<endl;
cin>>parent1_data;
}
};
class parent2:virtual public grandparent
{
protected:
int parent2_data;
public:
void readp2()
{
cout<<"enter data of parent2"<<endl;
cin>>parent2_data;
}
};
class child:public parent1,public parent2
{
private :
int sum;
public:
void add()
{
sum=base_data+parent1_data+parent2_data;
}
void show()
{

OOPS LAB Page 21


DAVIET/CSE/1241647

cout<<"grandparents data member="<<base_data<<endl;


cout<<"\ndata members of parent1 and parent2
="<<parent1_data<<'/t'<<parent2_data<<endl;
cout<<"\n sum of all data="<<sum;
}
};
int main()
{
clrscr();
child c1;
c1.readgp();
c1.readp1();
c1.readp2();
c1.add();
c1.show();
getch();
return 0;
}

Output:

OOPS LAB Page 22


DAVIET/CSE/1241647

Program 14: WAP to illustrate concept of ambiguity in multiple inheritance

#include<iostream.h>
#include<conio.h>
class publication
{
private:
char publisher[20];
protected:
double price;
public:
void read()
{
cout<<"enter publisher and price"<<endl;
cin>>publisher>>price;
}
void show()
{
cout<<"publisher="<<publisher <<endl;
cout<<"price="<<price;
}
};
class sales
{
protected:
double pub_sales;
public:
void read()
{
cout<<"enter total sales="<<endl;
cin>>pub_sales;
}
void show()
{
cout<<" total sales of publication="<<pub_sales<<endl;
}
};

class book: public publication,public sales


{
char author[20];
double isbn;
int pages;
public:
void read()
{
cout<<"enter author,isbn number and pages"<<endl;
cin>>author>>isbn>>pages;
}
void show()

OOPS LAB Page 23


DAVIET/CSE/1241647

{
cout<<"book info:"<<author<<'\t'<<isbn<<'\t'<<pages<<endl;
}
void cal_sal_amt()
{
double saleamt;
saleamt=price * pub_sales;
cout<<"sales amount="<<saleamt;
}
};
int main()
{
clrscr();
book b1;
cout<<”roll no 118”<<endl;
cout<<"enter publication information"<<endl;
b1.publication::read();
cout<<"enter sales information"<<endl;
b1.sales::read();
cout<<"enter book information"<<endl;
b1.read();
b1.cal_sal_amt();
b1.publication::show();
b1.sales::show();
b1.show();
getch();
return 0;
}

OOPS LAB Page 24


DAVIET/CSE/1241647

Output:

OOPS LAB Page 25


DAVIET/CSE/1241647

Program 15 : WAP to demonstrate the use of default, parameterized and dynamic


constructor.

#include<string.h>
#include<iostream.h>
#include<conio.h>
class student
{
char *name1,*name2;
int m,n,len1,len2;
public:
student(char*s1,char*s2)
{
len1=strlen(s1);
name1=new char[len1+1];
strcpy(name1,s1);
len2=strlen(s2);
name2=new char[len2+1];
strcpy(name2,s2);
if(strcmp(name1,name2)==0)
{ cout<<"\n Strings are equal"<<endl;
cout<<"DYNAMIC CONSTRUCTOR" <<endl;
}
else
cout<<"They are not"<<endl;
}
student()
{
m=2;
n=1;
cout<<"DEFAULT CONSTRUCTOR"<<endl;
}
student(int x,int y)
{
m=x;
n=y;
cout<<m<<endl;
cout<<n<<endl;
cout<<"PARAMERTISED CONSTRUCTOR"<<endl;
}
};
void main()
{
clrscr();
cout<<"roll no. 118"<<endl;
student t1;
student t2(50,10);
student t3("divyanshu","divyanshu");
getch();
}

OOPS LAB Page 26


DAVIET/CSE/1241647

Output:

OOPS LAB Page 27


DAVIET/CSE/1241647

Program 16: WAP to illustrate multilevel inheritance.

#include<iostream.h>
#include<conio.h>
class a
{
protected:
int x;
public:
void getdata()
{
cout<<"enter any number"<<endl;
cin>>x;
}
};
class b : public a
{
protected:
int y;float area;
public:
void getdata1()
{
cout<<"enter another number"<<endl;
cin>>y;
}
void area1()
{
area=x*y;
cout<<"area is"<<area<<endl;
}
};
class c: public b
{
private:
int c;float vol;
public:
void getdata2()
{
cout<<"enter a number"<<endl;
cin>>c;
}
void volume()
{
vol=area*c;
cout<<"volume is"<<vol;
}
};
void main()
{
clrscr();

OOPS LAB Page 28


DAVIET/CSE/1241647

cout<<"roll no 118"<<endl;
c obj;
obj.getdata();
obj.getdata1();
obj.getdata2();
obj.area1();
obj.volume();
getch();
}

Output:

OOPS LAB Page 29


DAVIET/CSE/1241647

Program 17 : WAP using classes where member functions are defined inside class
triangle having height and base as data members .write functions area and hypotenuse
to calculate the same.

#include<iostream.h>
#include<conio.h>
#include<math.h>
class triangle
{
public:
int h;
int b;
float ar,hypt;
public:
void get_data()
{
cout<<"roll no 118"<<endl;
cout<<"enter height and base"<<endl;
cin>>h>>b;
}
void area()
{
ar=0.5*b*h;
cout<<"area of right angled triangle is"<<ar<<endl;
}
void hypotenuse()
{
hypt= sqrt(h*h-b*b);
cout<<"hypotenuse of right angled triangle is"<<hypt<<endl;
}
};
void main()
{
clrscr();
triangle t;
t.get_data();
t.area();
t.hypotenuse();
getch();
}

OOPS LAB Page 30


DAVIET/CSE/1241647

Output:

OOPS LAB Page 31


DAVIET/CSE/1241647

Program 18: WAP by making a class distance to add 2 distances in feet and inches.

#include<iostream.h>
#include<conio.h>
class distance
{
public:
int feet;
int inches;
void dist(distance &);
void get()
{
cout<<”roll no 118”<<endl;
cout<<"\n\tEnter feets: ";
cin>>feet;
cout<<"\tEnter inches: ";
cin>>inches;
}

void display()
{
cout<<"\n\n\tDistance: "<<feet<<" feets and "<<inches<<" inches.";
}
};
void distance::dist(distance &obj)
{
feet=feet+obj.feet;
inches=inches+obj.inches;
loo:
if(inches>=12)
{
feet++;
inches=inches-12;
}
if(inches>=12)
goto loo;
}
void main()
{
clrscr();
distance ob,obj;
ob.get();
obj.get();
ob.dist(obj);
ob.display();
getch();
}

OOPS LAB Page 32


DAVIET/CSE/1241647

Output:

OOPS LAB Page 33


DAVIET/CSE/1241647

Program 19 : WAP to design a structure time having 3 members as hours, minutes and
seconds.pass structure to function and display total no of seconds.

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

struct time
{
int hour;
int minute;
int second;
};
void get(time &t)
{
cout<<"roll no 118"<<endl;
cout<<"\n\tEnter number of hours: ";
cin>>t.hour;
cout<<"\n\tEnter number of minutes: ";
cin>>t.minute;
cout<<"\n\tEnter number of seconds: ";
cin>>t.second;
}
void calculate(time &t)
{
t.second = 3600*t.hour + 60*t.minute + t.second;
cout<<"\n\n\tTotal time in seconds: "<<t.second;
}
void main()
{
clrscr();
time t;
get(t);//passing of structure in function
calculate(t);
getch();
}

OOPS LAB Page 34


DAVIET/CSE/1241647

Output:

OOPS LAB Page 35


DAVIET/CSE/1241647

Program 20 : WAP to print telephone bill of n customers

#include<iostream.h>
#include<conio.h>
#include<string.h>
struct tele
{
char name[20];
long acc_no;
float bill;
};
void main()
{
clrscr();

tele cust[20];
int n;
cout<<"roll no 118"<<endl;
cout<<"\tEnter number of customers: ";
cin>>n;
for(int i=0; i<n; i++)
{
cout<<"\n\t\t***DETAILS FOR CUSTOMER "<<i+1<<"***";
cout<<"\n\tEnter name: ";
cin>>cust[i].name;
cout<<"\tEnter account number: ";
cin>>cust[i].acc_no;
cout<<"\tEnter telephone bill of customer: ";
cin>>cust[i].bill;
}
cout<<"\n\t\t******DISPLAYING BILLS******\n";
for(i=0; i<n; i++)
{
cout<<"\t*TELEPHONE BILL OF "<<cust[i].name<<":*\n";
cout<<"\tACCOUNT NUMBER: "<<cust[i].acc_no;
cout<<"\n\tBILL DUE: "<<cust[i].bill;
cout<<"\n";
}
getch();
}

OOPS LAB Page 36


DAVIET/CSE/1241647

Output:

OOPS LAB Page 37


DAVIET/CSE/1241647

Program 21: WAP to count no of objects created and destroyed using constructor and
destructor respectively

#include<iostream.h>
#include<conio.h>
int count =0;
class counter
{
public:
counter()
{
count++;
}
~counter()
{
count --;
cout<<"objects destroying "<<count<<endl;
}
};
void main()
{
clrscr();
counter c1,c2,c3,c4;
cout<<"roll no 118"<<endl;
cout<<"object created"<<count<<endl<<"exit"<<endl;
}

Output:

OOPS LAB Page 38


DAVIET/CSE/1241647

Program 22: WAP to find whether string is palindrome or not

#include<iostream.h>
#include<conio.h>
#include<string.h>
int main()
{
clrscr();
char a[80],c[80];
cout<<"roll no 118"<<endl;
cout<<"enter a string"<<endl;
cin.get(a,80);
strcpy(c,a);
strrev(a);
if(strcmp(c,a)==0)
cout<<"string="<<c<<"is palindrome";
else
cout<<c<<"is not palindrome";
getch();
return 0;
}

Output:

OOPS LAB Page 39


DAVIET/CSE/1241647

Program 23: WAP to extract m characters from a string starting with nth character

#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
char a[80];
int n,m,c=0,count=0;
cout<<"roll no 118"<<endl;
cout<<"enter a string"<<endl;
cin.get(a,80);
cout<<"enter value of m and n"<<endl;
cin>>m>>n;
for(int i=0;a[i]!='\0';i++)
{
count++;
if(count>=n&&c<m)
{
cout<<a[i];
c++;
}
}
getch();
return 0;
}

Output:

OOPS LAB Page 40


DAVIET/CSE/1241647

OOPS LAB Page 41


DAVIET/CSE/1241647

Program 24 : WAP to concatenate two strings without using inbuilt function

#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
void string_concat(char[],char[]);
char source[20],dest[40];
cout<<"roll no 118"<<endl;
cout<<"enter destination string"<<endl;
cin>>dest;
cout<<"enter source string"<<endl;
cin>>source;
string_concat(dest,source);
cout<<"concatenated stringis "<<dest;
getch();
return 0;
}
void string_concat(char dest[],char source[])
{
int i,j,count=0;
char temp[40];
for(i=0;dest[i]!='\0';i++)
count++;
for(j=count,i=0;source[i]!='\0';j++,i++)
dest[j]=source[i];
dest[j]='\0'; }

Output:

OOPS LAB Page 42


DAVIET/CSE/1241647

OOPS LAB Page 43


DAVIET/CSE/1241647

Program 25: WAP to copy one string to another using pointers

#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
cout<<"roll no 118"<<endl;
char *str1="do good have good";
char str2[40];
void copystr(char *,char *);
copystr(str2,str1);
cout<<"string 2="<<str2<<endl;
getch();
return 0;
}
void copystr(char *dest,char *src)
{
while(*src!='\0')
*dest++=*src++;
*dest='\0';
return ;
}

Output:

OOPS LAB Page 44


DAVIET/CSE/1241647

Program 26: WAP to find transpose of matrix using classes

#include<conio.h>
#include<iostream.h>
class transpose
{
int m,n,i,j,k,a[5][5];
public:
void input();
void output();
};
void transpose::input()
{
cout<<"enter roll no 118"<<endl;
cout<<"Enter order of the matrix: "<<endl;
cin>>m>>n;
cout<<"Enter "<<m*n<<"elements in the matrix:"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cin>>a[i][j];
}
}
void transpose::output()
{
cout<<"Before transpose the matrix is: \n"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)

OOPS LAB Page 45


DAVIET/CSE/1241647

cout<<a[i][j]<<" ";
cout<<endl;
}
cout<<"after transpose the given matrix is:\n"<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
cout<<a[j][i]<<" ";
cout<<endl;
}
}
void main()
{
transpose t1;
clrscr();
t1.input();
t1.output();
getch();
}

Output:

OOPS LAB Page 46


DAVIET/CSE/1241647

Program 27: WAP to demonstrate concept of run time polymorphism

#include<iostream.h>
#include<conio.h>
class Base
{
public:

virtual void display(int i)


{

cout<<"Base::"<<i; }
};

class Derv: public Base


{
public:

void display(int j)
{
cout<<"roll no 118"<<endl;
cout<<"Derv::"<<j; }
};

int main()
{
clrscr();
Base *ptr=new Derv;

OOPS LAB Page 47


DAVIET/CSE/1241647

ptr->display(10);
getch();
return 0;
}

Output:

Program 28: WAP to illustrate concept of static data members

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

class Box
{
public:
static int objectCount;
// Constructor definition
Box(double l=2.0, double b=2.0, double h=2.0)
{ cout<<"roll no 118"<<endl;
cout <<"Constructor called." << endl;
length = l;
breadth = b;
height = h;
// Increase every time object is created
objectCount++;
}
double Volume()
{
return length * breadth * height;
}
private:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};

OOPS LAB Page 48


DAVIET/CSE/1241647

// Initialize static member of class Box


int Box::objectCount = 0;

int main(void)
{
clrscr();
Box Box1(3.3, 1.2, 1.5); // Declare box1
Box Box2(8.5, 6.0, 2.0); // Declare box2

// Print total number of objects.


cout << "Total objects: " << Box::objectCount << endl;
getch();

return 0;
}

Output:

OOPS LAB Page 49


DAVIET/CSE/1241647

Program 29: WAP to illustrate concept of static member functions

#include <iostream.h>
#include<conio.h>
class Box
{
public:
static int objectCount;
// Constructor definition
Box(double l=2.0, double b=2.0, double h=2.0)
{ cout<<"roll no 118"<<endl;
cout <<"Constructor called." << endl;
length = l;
breadth = b;
height = h;
// Increase every time object is created
objectCount++;
}
double Volume()
{
return length * breadth * height;
}
static int getCount()
{
return objectCount;
}
private:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};

OOPS LAB Page 50


DAVIET/CSE/1241647

// Initialize static member of class Box


int Box::objectCount = 0;

int main(void)
{
clrscr();

// Print total number of objects before creating object.


cout << "Inital Stage Count: " << Box::getCount() << endl;

Box Box1(3.3, 1.2, 1.5); // Declare box1


Box Box2(8.5, 6.0, 2.0); // Declare box2

// Print total number of objects after creating object.


cout << "Final Stage Count: " << Box::getCount() << endl;
getch();

return 0;
}

Output:

OOPS LAB Page 51


DAVIET/CSE/1241647

Program 30 : WAP to illustrate concept of constant member function

#include <iostream.h>
#include<conio.h>
class rational
{
private:
int num;
int dnum;
public:
rational():num(1),dnum(1)
{}
void get ()
{
cout<<"roll no 118"<<endl;
cout<<"enter numerator";
cin>>num;
cout<<"enter denomenator";
cin>>dnum;
}
void print () const // const keyword is used
{
cout<<num<<"/"<<dnum<<endl;
}
void multi(rational r1,rational r2)
{
num=r1.num*r2.num;
dnum=r1.dnum*r2.dnum;
}
};
void main ()

OOPS LAB Page 52


DAVIET/CSE/1241647

{
clrscr();
rational r1,r2,r3;
r1.get();
r2.get();
r3.multi(r1,r2);

r3.print();
getch();

Output:

OOPS LAB Page 53


DAVIET/CSE/1241647

Program 31:WAP to illustrate dynamic memory allocation in array and sort the
elements in descending order

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"roll no 112/12"<<endl;
int i,*ptr,n,t,j;
cout<<"enter the no of elements"<<endl;
cin>>n;
ptr=new int[n];
for(i=0;i<n;i++)
{
cout<<"enter element"<<(i+1)<<endl;
cin>>*(ptr+i);
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(*(ptr+j)<*(ptr+j+1))
{
t=*(ptr+j);
*(ptr+j)=*(ptr+j+1);
*(ptr+j+1)=t;
}
}

OOPS LAB Page 54


DAVIET/CSE/1241647

}
cout<<"after sorting"<<endl;
for(i=0;i<n;i++)
{
cout<<*(ptr+i)<<endl;
}
getch();
}

Output:

OOPS LAB Page 55


DAVIET/CSE/1241647

Program 32: WAP to implement bubble sort using function template

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
template<class T>
void bubblesort(T a[],int size)
{
T temp;
for(int i=0;i<size-1;i++)
for(int j=0;j<(size-i-1);j++)
if (a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
int main()
{
clrscr();
int m[6]={10,87,44,65,12,23};
float n[6]={12.5,8.6,7.1,2.3,1.6,9.8};
bubblesort(m,6);
bubblesort(n,6);
cout<<"roll no 118"<<endl;
cout<<"sorted array m=";
for(int i=0;i<6;i++)

OOPS LAB Page 56


DAVIET/CSE/1241647

cout<<m[i]<<' ';
cout<<'\n';
cout<<"sorted array n=";
for(int j=0;j<6;j++)
cout<<setprecision(2)<<n[j]<<' ';
getch();
return 0;
}

Output:

OOPS LAB Page 57


DAVIET/CSE/1241647

Program 33: WAP that implements class stack for different data types

#include<iostream.h>
#include<conio.h>
#include<process.h>
const int max=10;
template<class T>
class stack
{
private:
T array [max];
int top;
public:
stack()
{
top=-1;
}
void push(T item)
{
if(top==(max-1))
{
cout<<"stack overflow"<<endl;
exit(0);
}
else
{
top++;
array[top]=item;
}
}
OOPS LAB Page 58
DAVIET/CSE/1241647

T pop()
{
if (top==-1)
{
cout<<"underflow";
exit(0);
}
else
{
T elem=array[top--];
return elem;
}

Output:

OOPS LAB Page 59


DAVIET/CSE/1241647

Program 34: WAP to store an object using write() function and then retrieves that
object using read() function
#include<fstream.h>
#include<conio.h>
class student
{
private:
int rollno;
char name[20];
int marks;
public:
void read()
{
cout<<"roll no 118"<<endl;
cout<<"enter student information";
cin>>rollno>>name>>marks;
}
void show()
{
cout<<"rollno ="<<rollno;
cout<<"\n name="<<name;
cout<<"\n marks="<<marks;
}
};
int main()
{
clrscr();
student s1;
s1.read();

OOPS LAB Page 60


DAVIET/CSE/1241647

ofstream out1("STUD.DAT",ios::binary);
out1. write(( char*)&s1,sizeof(s1));out1.close();
out1.close();
ifstream in1("STUD.DAT",ios::binary);
in1.read((char*)&s1, sizeof(s1));
cout<<"displaying student object retrieved from file"<<endl;
s1.show();
getch();
return 0;
}

Output:

OOPS LAB Page 61


DAVIET/CSE/1241647

Program 35: WAP to copy contents of one file to another

#include<fstream.h>
#include<process.h>
#include<conio.h>
int main(int argc,char *argv[])
{
clrscr();
if (argc!=3)
{
cout<<"roll no 118"<<endl;
cout<<"wrong no of arguments";
exit(0);
}
ifstream fin (argv[1]);
if(!fin)
{
cout<<"unable to open file";
exit(0);
}
ofstream fout (argv[2]);
if(!fout)
{
cout<<"unable to open file";
exit(0);
}
char ch;
while(fin.eof()==0)
{
fin.get(ch);
OOPS LAB Page 62
DAVIET/CSE/1241647

fout.put(ch);
}
cout<<"1-file copied";
getch();
return 0;
}
Output:

Program 36: WAP to store and read multiple objects from file

#include<fstream.h>
#include<conio.h>
#include<process.h>
class account
{
private:
int accno;
double balance;
public:
void read()
{
cout<<"roll no 118"<<endl;
cout<<"enter account no and balance";
cin>>accno>>balance;
}
void show()
{
cout<<"\n account no="<<accno;
cout<<"\n balance="<<balance;
}
};
int main()
{
clrscr();
fstream f1;
char ch='y';
account act;

OOPS LAB Page 63


DAVIET/CSE/1241647

f1.open("temp.dat",ios::binary|ios::out|ios::in);
if(!f1)
{
cerr<<"file cannot open correctly";
exit(-1);
}
while(ch=='y')
{
act.read();
f1.write((char*)&act,sizeof(act));
cout<<"want to input more objects?(y/n):";
cin>>ch;
}

Output:

OOPS LAB Page 64


DAVIET/CSE/1241647

Program 37 :WAP to show type conversion of base type to class type

#include<iostream.h>
#include<conio.h>
class time
{
private:
int hours,mins;
public:
time(int m)
{
hours=m/60;
mins=m%60;
}
void show()
{
cout<<"roll no 118"<<endl;
cout<<"time in hrs and mins="<<hours<<":"<<mins;
}
};
int main()
{
clrscr();
int minutes=120;
time t1=minutes;
t1.show();
getch();
return 0;
}

Output:

OOPS LAB Page 65


DAVIET/CSE/1241647

Program 38 : WAP to show type conversion of class type to basic type

#include<iostream.h>
#include<conio.h>
class time
{
private:
int hours,mins;
public:
time(int hr,int mm)
{
hours=hr;
mins=mm;
}
operator int()
{
int mnts;
mnts=hours*60+mins;
return (mnts);
}
void show()
{
cout<<"time in hours and minutes="<<hours<<":"<<mins;
}
};
int main()
{
clrscr();
int minutes;
time t1(3,15);
t1.show();
minutes=t1;
cout<<"\ntime in minutes="<<minutes;
OOPS LAB Page 66
DAVIET/CSE/1241647

getch();
return 0;
}

Output:

Program 39: WAP to show type conversion of one class to another class

#define dol_val 44.20


#include<iostream.h>
#include<conio.h>
class rupee
{
double rs;
public:
rupee(double rs1)
{
rs=rs1;
}
void show()
{
cout<<"money in rs ="<<rs<<endl;
}
rupee()
{
rs=0;
}};
class dollar
{
double dol;
public:
dollar(double doll)
{
dol=doll;
}
operator rupee()
{
double rs1=dol*dol_val;
return (rupee(rs1));

OOPS LAB Page 67


DAVIET/CSE/1241647

}
void show()
{
cout<<"roll no 118"<<endl;
cout<<"money in dollars="<<dol<<endl;}
};
int main()
{
clrscr();
dollar d1(3);
d1.show();
rupee r1;
r1=d1;
r1.show();
getch();
return 0;
}
Output:

OOPS LAB Page 68

You might also like