0% found this document useful (0 votes)
16 views33 pages

Practical Ans (2)

The document contains a series of programming assignments related to classes and objects in C++. Each assignment involves creating classes for various applications such as Fibonacci series, employee management, and sales data processing, with methods for reading input, calculating values, and displaying results. The code snippets demonstrate the use of constructors, member functions, and basic input/output operations.

Uploaded by

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

Practical Ans (2)

The document contains a series of programming assignments related to classes and objects in C++. Each assignment involves creating classes for various applications such as Fibonacci series, employee management, and sales data processing, with methods for reading input, calculating values, and displaying results. The code snippets demonstrate the use of constructors, member functions, and basic input/output operations.

Uploaded by

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

SYBCA [SEM-III] US03CBCA24[PRACTICAL]

ASSIGNMENT – I [ CLASS AND OBJECT]

1)
#include<iostream.h> for(i=1;i<=n;i++)
#include<conio.h> {
class fibo c=a+b;
{ cout<<c<<"\n";
public: a=b;
int a,b,c,n,i; b=c;
void read() }
{
cout<<"enter n:"; }
cin>>n;
} };
void main()
void gen() {
{ fibo f;
a=1,b=0; clrscr();
f.read();
f.gen();
getch();

}
3)
//assignment:3 void printdata()
#include<iostream.h> {
#include<conio.h> cout<<"\n
#include<stdio.h> name:"<<pname;
class person cout<<"\n age:"<<age;
{ cout<<"\n city:"<<city;
public:
int age; }
char pname[20],city[20]; };
void getdata() void main()
{ {
cout<<"enter name:"; person p;
gets(pname); clrscr();
cout<<"enter age:"; p.getdata();
cin>>age; p.printdata();
cout<<"enter city:"; getch();
gets(city);
} }

4)
//assingment-4 void print()
{
#include<iostream.h> cout<<"\n student
#include<stdio.h> no:"<<sno;
#include<conio.h> cout<<"\n student
class student name:"<<sname;
{ cout<<"\n
public: marks1:"<<m1;
int sno,m1,m2,m3,total; cout<<"\n
float per; marks2:"<<m2;
char sname[20]; cout<<"\n
void read() marks3:"<<m3;
{ cout<<"\n total:"<<total;
cout<<"enter student cout<<"\n per:"<<per;
no:";
cin>>sno; }
cout<<"enter student
name:"; };
gets(sname); void main()
cout<<"enter marks 1:"; {
cin>>m1; student s;
cout<<"enter marks 2:"; clrscr();
cin>>m2; s.read();
cout<<"enter marks 3:"; s.calc();
cin>>m3; s.print();
getch();
}
void calc() }
{
total=m1+m2+m3;
per=total/3;

}
5)
//asingment-5 void read()
{
#include<iostream.h> for(int i=0;i<=9;i++)
#include<conio.h> {
#include<stdio.h>
class myarrary cout<<"enter
{ value:";
public:int a[10]; cin>>a[i];
void sortasc()
{ }
for(int i=0;i<=8;i++) cout<<"\n you enter this
{ value:";
for(int
j=i+1;j<=9;j++) }
{
if(a[i]>a[j]) void print()
{ {
int
c=a[i]; for(int i=0;i<=9;i++)
{
a[i]=a[j]; cout<<"\n"<<a[i];

a[j]=c; }

} }

} };
void main()
} {
cout<<"\n after int ch=0;
assending"; myarrary m;
clrscr();
} m.read();
m.print();
void sortdesc() while(ch!=3)
{ {
for(int i=0;i<=8;i++) cout<<"\n\n menu
{ ";
for(int cout<<"\n-----------------------";
j=i+1;j<=9;j++) cout<<"\n 1:Sort ascending";
{ cout<<"\n 2:sort
if(a[i]<a[j]) descending";
{ cout<<"\n 3:exit ";
int cout<<"\n----------------------";
c=a[i]; cout<<"\n enter your choice:";
cin>>ch;
a[i]=a[j]; if(ch==1)
{
a[j]=c; m.sortasc();
} m.print();
}
}
if(ch==2)
} {
cout<<"\n after m.sortdesc();
descending"; m.print();
} }
}
}
7)
#include<iostream.h> void main()
#include<conio.h> {
#include<stdio.h> int ch=0;
#include<string.h> mystring m;
class mystring clrscr();
{ m.read();
public:char s[20]; while(ch!=5)
void read() {
{ cout<<"\n menu
cout<<"enter string:"; ";
gets(s); cout<<"\n------------------
--------------";
} cout<<"\n 1:finding
void disp() length ";
{ cout<<"\n 2:revers
cout<<"\n string="<<s; string ";
} cout<<"\n 3:convert to
void length() uppercase ";
{ cout<<"\n 4:convert to
cout<<"string lowercase ";
length="<<strlen(s); cout<<"\n 5:exit
} ";
void revers() cout<<"\n------------------
{ ---------------";
cout<<"revers cout<<"\n enter your
string="<<strrev(s); choice:";
} cin>>ch;
void upper()
{ if(ch==1)
cout<<"upper {
string="<<strupr(s); m.length();
} }
void lower() if(ch==2)
{ {
cout<<"lower m.revers();
string="<<strlwr(s); }
} if(ch==3)
{
}; m.upper();
}
if(ch==4)
{
m.lower();
}
}

getch();
}

ASSIGNMENT – II [ CONSTRUCTOR]
1)
#include<iostream.h> void main()
#include<conio.h> {
class emp clrscr();
{ class emp e;
int no,sal; e.print();
char nm[30]; getch();
public: }
emp();
void print();
};
emp::emp()
{
cout<<"\n Enter the Employee_No:";
cin>>no;
cout<<"\n Enter the
Employee_Name:";
cin>>nm;
cout<<"\n Enter the Basic Salary:";
cin>>sal;
}
void emp::print()
{
cout<<"\n Employee No:"<<no;
cout<<"\n Employee Name:"<<nm;
cout<<"\n Basic Salary :"<<sal;
}
3)
#include<iostream.h> void disp()
#include<conio.h> {
class demo cout<<"\n i="<<i;
{ cout<<"\n j="<<j;
public:int i,j; cout<<"\n";
float x,y; cout<<"\n x="<<x;
demo() cout<<"\n y="<<y;
{ cout<<"\n";
i=10;
j=20; }
x=12.50; void swap()
y=23.4; {
i=i+j;
} j=i-j;
demo(int a,int b,float c,float d) i=i-j;
{
i=a; x=x+y;
j=b; y=x-y;
x=c; x=x-y;
y=d; }
};
} void main()
{
demo d1,d2(5,8,2.3,3.2);
clrscr();
d1.disp();
d2.disp();
d1.swap();
d1.disp();
getch();

}
4)
#include<iostream.h> cout<<"\n
#include<conio.h> factorial(while)="<<f;
class math
{ }
public:int n,f;
math() };
{ void main()
f=1; {
int ch=0;
} math m;
void read() clrscr();
{ m.read();
cout<<"enter n:"; while(ch!=4)
cin>>n; {
cout<<"\n menu
} ";
void factfor() cout<<"\n------------------
{ --------------";
f=1; cout<<"\n 1.factorial
for(int i=n;i>=1;i--) using for..next";
{ cout<<"\n 2.factorial
f=f*i; using do..while";
} cout<<"\n 3.factorial
cout<<"\n using while";
factorial(for)="<<f; cout<<"\n 4.exit";
cout<<"\n------------------
} ---------------";
void factdo() cout<<"\n enter your
{ choice:";
f=1; cin>>ch;
int i=n; if(ch==1)
do {
{ m.factfor();
f=f*i; }
i--; if(ch==2)
{
m.factdo();
}while(i>=1); }
cout<<" if(ch==3)
factorial(do)="<<f; {
} m.factwhile();
void factwhile() }
{
f=1; }
int i=n; getch();
while(i>=1)
{ }
f=f*i;
i--;
}

ASSIGNMENT – III [ ARRAY OF OBJECT]


3)
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<iomanip.h>
class cricketer
{
public: int age,tm,tr,tw;
char cname[25],country[20],type[20];
void read()
{
cout<<"\n enter cricketer name:";
gets(cname);
cout<<"\n enter contry";
gets(country);
cout<<"\n enter age:";
cin>>age;
cout<<"\n enter type:";
gets(type);
cout<<"\n enter total match:";
cin>>tm;
cout<<"\n enter total runs:";
cin>>tr;
cout<<"\n enter total wickets:";
cin>>tw;

}
void disp()
{
// cout<<"\n\n"<<cname<<" "<<country<<" "<<age<<" "<<type<<"
"<<tm<<" "<<tr<<" "<<tw;
cout<<"\n"<<setw(15)<<cname<<setw(10)<<country<<setw(5)<<age<<setw
(10)<<type<<setw(8)<<tm<<setw(8)<<tr<<setw(8)<<tw;
}

};
void main()
{
cricketer c[5];
clrscr();
for(int i=0;i<=1;i++)
{
c[i].read();
}
cout<<"\n cricketer
details ";
cout<<"\n-------------------------------------------------------------";
cout<<"\n"<<setw(15)<<"name"<<setw(10)<<"country"<<setw(5)<<"age"<<
setw(10)<<"type"<<setw(8)<<" totmatch"<<setw(8)<<"
totalrun"<<setw(8)<<" totwic";
cout<<"\n--------------------------------------------------------------";
for(i=0;i<=1;i++)
{
c[i].disp();
}
cout<<"\n-------------------------------------------------------------";

getch();
}

4)
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iostream.h>
#include<iomanip.h>
int tq=0;
float ta=0,tc=0;

class salesman
{
public:int sno,qty;
float rate,amt,comm;
void read()
{
cout<<"\n enter salesman number:";
cin>>sno;

qty=0;
while(qty<50)
{
cout<<"\n enter quantity:";
cin>>qty;
}
cout<<"\n enter rate:";
cin>>rate;

tq=tq+qty;

amt=rate*qty;
ta=ta+amt;

if(amt<=1000)
{
comm=0;
}
else if(amt<=2000)
{
comm=amt*0.15;
}
else if(amt<=4000)
{
comm=amt*0.20;
}
else
{
comm=amt*0.25;
}
tc=tc+comm;
}
void disp()
{

cout<<"\n"<<setw(10)<<sno<<setw(10)<<qty<<setw(10)<<rate<<setw(12)<
<amt<<setw(12)<<comm;
}

};
void main()
{
int n;
salesman s[50];
clrscr();
cout<<"enter total salesman:";
cin>>n;
for(int i=0;i<=n-1;i++)
{
s[i].read();
}
cout<<"\n abc company";
cout<<"\n salesman information";
cout<<"\n---------------------------------------------------------";
cout<<"\n"<<setw(10)<<"salno"<<setw(10)<<"quantity"<<setw(10)<<
"rate"<<setw(12)<<"amount"<<setw(12)<<"commission";
cout<<"\n---------------------------------------------------------";
for(i=0;i<=n-1;i++)
{
s[i].disp();
}
cout<<"\n-------------------------------------------------------------";
cout<<"\n"<<setw(10)<<"total:"<<setw(10)<<tq<<setw(10)<<"
"<<setw(12)<<ta<<setw(12)<<tc;
cout<<"\n-------------------------------------------------------------";
getch();

}
5)
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<iomanip.h>
#include<dos.h>
class employee
{

public: int eno,code;


char ename[20];
float sal,da,hra,pt,it,gs,td,ns;
void read()
{

cout<<"\n enter employee number:";


cin>>eno;
cout<<"\n enter employee name:";
gets(ename);
cout<<"\n enter salary:";
cin>>sal;
cout<<"\n enter code:";
cin>>code;
}

void calculate()
{

if(sal<=1500)
{
da=sal*1.59;

}
if(sal>1500 && sal<=2500)
{

da=sal*1.48;
}
if(sal>2500 && sal<=4500)
{
da=sal*1.25;
}
if(sal>4500)
{
da=sal*0.90;
}
if(code==0)
{
hra=0;
}
if(code==1)
{
hra=120;
}
if(code==2)
{
hra=250;
}
if(code==3)
{
hra=400;
}
gs=da+hra+sal;
it=gs*0.10;
pt=80;
td=it+pt;
ns=gs-td;

void disp()
{
cout<<"\n employee payslip";
cout<<"\n _________________";
cout<<"\n\n employ number:"<<eno<<" name:"<<ename;
cout<<"\n------------------------------------------";

cout<<"\n"<<setw(15)<<"earnig"<<setw(15)<<"amount"<<setw(15)<<"dedu
ctions"<<setw(15)<<"amount";
cout<<"\n------------------------------------------";
cout<<"\n"<<setw(15)<<"basic"<<setw(15)<<sal;
cout<<"\n\n"<<setw(15)<<"da"<<setw(15)<<da<<setw(15)<<"
pt:"<<setw(15)<<pt;
cout<<"\n\n"<<setw(15)<<"hra"<<setw(15)<<hra<<setw(15)<<" incom
tax:"<<setw(15)<<it;
cout<<"\n\n"<<setw(15)<<"gross"<<setw(15)<<gs<<setw(15)<<" total
deducation"<<setw(15)<<td;
cout<<"\n-------------------------------------------";
cout<<"\n"<<setw(30)<<" "<<setw(15)<<"net salary:"<<setw(15)<<ns;
}

};
void main()
{
int n;

employee e[50];
clrscr();
cout<<"enter total employee:";
cin>>n;
for(int i=0;i<=n-1;i++)
{

e[i].read();
e[i].calculate();
}
// clrscr();
for(i=0;i<=n-1;i++)
{
e[i].disp();

/* for(int j=1;j<=10;j++)
{
gotoxy(20,30);
cout<<10-j<<"seconds remaining";
delay(1000);

}*/
// clrscr();
}
getch();
}
6)
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<iomanip.h>
#include<string.h>
int mp=0,fp=0,ma=0,fa=0,mf=0,ff=0;
class student
{
public:
char sname[20],result[10];
int rno,m[10],scode,total;
float per;
void read()
{
cout<<"\n enter student number:";
cin>>rno;
cout<<"\n enter student name:";
gets(sname);
cout<<"\n enter gender code:";
cin>>scode;
for(int i=0;i<=9;i++)
{
cout<<"\n enter marks "<<i+1<<":";
cin>>m[i];
}
int c=0;
total=0;
for(i=0;i<=9;i++)
{
total=total+m[i];
if(m[i]<35)
{
c++;
}
}
per=total/10;

if(c==0)
{
if(scode==1)
{
mp++;
}
if(scode==2)
{
fp++;
}
if(per<48)
{
strcpy(result,"pass");
}
if(per>48 && per<60)
{
strcpy(result,"second");
}
if(per>60 && per<70)
{
strcpy(result,"first");
}
if(per>70)
{
strcpy(result,"dist");
}

if(c==1 || c==2)
{
if(scode==1)
{
ma++;
}
if(scode==2)
{
fa++;
}
strcpy(result,"ATKT");

}
if(c>2)
{
if(scode==1)
{
mf++;
}
if(scode==2)
{
ff++;
}
strcpy(result,"Fail");
/* if(per<35)
{
per=0;
}*/

}
void disp()
{
//
cout<<"\n"<<setw(3)<<rno<<setw(15)<<sname<<setw(4)<<m[0]<<setw(4)<
<m[1]<<setw(4)<<m[2]<<setw(4)<<m[3]<<setw(4)<<m[4]<<setw(4)<<m[5]
<<setw(4)<<m[6]<<setw(4)<<m[7]<<setw(4)<<m[8]<<setw(4)<<m[9]<<set
w(5)<<total<<setw(6)<<per<<setw(10)<<result;
cout<<"\n"<<setw(3)<<rno;
cout<<setw(15)<<sname;
for(int i=0;i<=9;i++)
{
cout<<setw(4)<<m[i];
}
/* cout<<setw(4)<<m[1];
cout<<setw(4)<<m[2];
cout<<setw(4)<<m[3];
cout<<setw(4)<<m[4];
cout<<setw(4)<<m[5];
cout<<setw(4)<<m[6];
cout<<setw(4)<<m[7];
cout<<setw(4)<<m[8];
cout<<setw(4)<<m[9]; */
cout<<setw(5)<<total;
cout.precision(2);
cout<<setw(6)<<per;
cout<<setw(10)<<result;
}

};
void main()
{
int n;
student s[50];
clrscr();
cout<<"\n enter total student:";
cin>>n;
for(int i=0;i<=n-1;i++)
{
s[i].read();
}
cout<<"\n student marksheet";
cout<<"\n ####### #########";
cout<<"\n";
cout<<"\n"<<setw(3)<<"No"<<setw(15)<<"Name"<<setw(4)<<"m1"<
<setw(4)<<"m2"<<setw(4)<<"m3"<<setw(4)<<"m4"<<setw(4)<<"m5"<<set
w(4)<<"m6"<<setw(4)<<"m7"<<setw(4)<<"m8"<<setw(4)<<"m9"<<setw(5)
<<"m10"<<setw(6)<<"total"<<setw(6)<<"per"<<setw(8)<<"result";
cout<<"\n--------------------------------------------------------------------------
-----";
for(i=0;i<=n-1;i++)
{
s[i].disp();
}
cout<<"\n-----------------------------------------------------------------------------
--";

cout<<"\n"<<setw(8)<<"srno"<<setw(10)<<"result"<<setw(10)<<"male"<<s
etw(10)<<"female"<<setw(10)<<"total";

cout<<"\n"<<setw(8)<<"1"<<setw(10)<<"pass"<<setw(10)<<mp<<setw(10)
<<fp<<setw(10)<<mp+fp;
cout<<"\n"<<setw(8)<<"2"<<setw(10)<<"fail"<<setw(10)<<mf<<setw(10)<
<ff<<setw(10)<<mf+ff;

cout<<"\n"<<setw(8)<<"3"<<setw(10)<<"ATKT"<<setw(10)<<ma<<setw(1
0)<<fa<<setw(10)<<ma+fa;

getch();
}

ASSIGNMENT – 4 [INHERITANCE]

1)
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iomanip.h>
class student
{
public:int sno,m[5];
char sname[30];
void read()
{
cout<<"\n enter student no:";
cin>>sno;
cout<<"\n enter student name:";
gets(sname);
for(int i=0;i<=4;i++)
{
cout<<"enter marks:";
cin>>m[i];
}

};
class result:public student
{
public:float total,per;
char result[10];
void calc()
{
total=m[0]+m[1]+m[2]+m[3]+m[4];
int c=0;
if(m[0]<30)
{
c++;
}
if(m[1]<30)
{
c++;
}
if(m[2]<30)
{
c++;
}
if(m[3]<30)
{
c++;
}
if(m[4]<30)
{
c++;
}
if(c==0)
{
per=total/5;
if(per>=70)
{
strcpy(result,"A");
}
if(per<70 && per>=60)
{
strcpy(result,"B");
}
if(per<60 && per>=50)
{
strcpy(result,"C");
}
if(per<50 && per>=30)
{
strcpy(result,"D");
}
if(per<30)
{
strcpy(result,"FAIL");
}

}
else
{
per=0;
strcpy(result,"--");
}

}
void disp()
{
cout<<"\n"<<setw(5)<<sno;
cout<<setw(20)<<sname;
cout<<setw(5)<<m[0];
cout<<setw(5)<<m[1];
cout<<setw(5)<<m[2];
cout<<setw(5)<<m[3];
cout<<setw(5)<<m[4];
cout<<setw(8)<<total;
cout.precision(2);
cout<<setw(8)<<per;
cout<<setw(8)<<result;

}
};
void main()
{
int n;
result r[50];
clrscr();
cout<<"\n enter total student:";
cin>>n;
for(int i=0;i<=n-1;i++)
{
r[i].read();
r[i].calc();
}
cout<<"\n"<<setw(5)<<"number"<<setw(20)<<"name"<<setw(5)<<"m
1"<<setw(5)<<"m2"<<setw(5)<<"m3"<<setw(5)<<"m4"<<setw(5)<<"m5"<
<setw(8)<<"total"<<setw(8)<<"per"<<setw(8)<<"result";
for(i=0;i<=n-1;i++)
{
r[i].disp();
}
getch();
}
3)
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iomanip.h>
class student
{
public:int sno;
char sname[50];

};
class marks:public student
{
public:int m[5];
void read()
{
cout<<"\n enter student no:";
cin>>sno;
cout<<"\n enter student name:";
gets(sname);
for(int i=0;i<=4;i++)
{
cout<<"enter marks:";
cin>>m[i];
}

};
class result:public marks
{
public:float total,per;
char result[10];
void calc()
{
total=m[0]+m[1]+m[2]+m[3]+m[4];
int c=0;
if(m[0]<30)
{
c++;
}
if(m[1]<30)
{
c++;
}
if(m[2]<30)
{
c++;
}
if(m[3]<30)
{
c++;
}
if(m[4]<30)
{
c++;
}
if(c==0)
{
per=total/5;
if(per>=70)
{
strcpy(result,"A");
}
if(per<70 && per>=60)
{
strcpy(result,"B");
}
if(per<60 && per>=50)
{
strcpy(result,"C");
}
if(per<50 && per>=30)
{
strcpy(result,"D");
}
if(per<30)
{
strcpy(result,"FAIL");
}

}
else
{
per=0;
strcpy(result,"--");
}

}
void disp()
{

cout<<"\n"<<setw(5)<<sno<<setw(20)<<sname<<setw(5)<<m[0]<<setw(5)<
<m[1]<<setw(5)<<m[2]<<setw(5)<<m[3]<<setw(5)<<m[4]<<setw(8)<<total
<<setw(8)<<per<<setw(8)<<result;

}
};
void main()
{
int n;
result r[50];
clrscr();
cout<<"\n enter total student:";
cin>>n;
for(int i=0;i<=n-1;i++)
{
r[i].read();
r[i].calc();
}
cout<<"\n"<<setw(5)<<"number"<<setw(20)<<"name"<<setw(5)<<"m
1"<<setw(5)<<"m2"<<setw(5)<<"m3"<<setw(5)<<"m4"<<setw(5)<<"m5"<
<setw(8)<<"total"<<setw(8)<<"per"<<setw(8)<<"result";
for(i=0;i<=n-1;i++)
{
r[i].disp();
}
getch();
}
4)
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<iomanip.h>
class account
{
public:int acno;
char achname[20];
account()
{
acno=123;
strcpy(achname,"nilesh");

}
account(int tacno,char tachname[20])
{
acno=tacno;
strcpy(achname,tachname);
}
};
class type:public account
{
public:char actype[10];
type():account()
{
strcpy(actype,"saving");
}
type(int tacno,char tachname[20],char tactype[10])
{
acno=tacno;
strcpy(achname,tachname);
strcpy(actype,tactype);

}
void disp()
{

cout<<"\n"<<setw(10)<<acno<<setw(20)<<achname<<setw(15)<<acty
pe;

};
void main()
{ int a;
char b[20],c[10];
cout<<"\n enter acouunt number:";
cin>>a;
cout<<"enter acouunt hodler name:";
gets(b);
cout<<"enter account type:";
gets(c);
clrscr();
type t1,t2(999,"abc","current"),t3(a,b,c);
t1.disp();
t2.disp();
t3.disp();
getch();
}
5)
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<iomanip.h>
class publication
{
public:char title[50];
float price;

};
class book:public publication
{
public:int pagecount;
void getdata()
{
cout<<"\n enter book title:";
gets(title);
cout<<"\n enter book price:";
cin>>price;
cout<<"\n enter total page:";
cin>>pagecount;

}
void putdata()
{
cout<<"\n book title="<<title;
cout<<"\n book price="<<price;
cout<<"\n book page="<<pagecount;
}
};
class tape:public publication
{
public:float playtime;
void getdata()
{
cout<<"\n enter tape title:";
gets(title);
cout<<"\n enter tape price:";
cin>>price;
cout<<"\n enter tape playtime:";
cin>>playtime;

}
void putdata()
{
cout<<"\n\n tape title="<<title;
cout<<"\n tape price="<<price;
cout<<"\n tape playtime="<<playtime;

};
void main()
{
book b;
tape t;
clrscr();
b.getdata();
t.getdata();
b.putdata();
t.putdata();
getch();
}

ASSIGNMENT-5 [FUNCTION / OPERATOR OVERLOADING]


FUNCTION OVERLOADING

1)
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class test
{
public:
void volume(float l)
{
cout<<"\n volume of cube="<<l*l*l;
}
void volume(float r,float h)
{
cout<<"\n volume of cylindar="<<3.14*r*r*h;
}
void volume(float l,float b,float h)
{
cout<<"\n volume of rect="<<l*b*h;
}

};
void main()
{
test t;
clrscr();
t.volume(10);
t.volume(2,3);
t.volume(4,5,6);
getch();
}
4)
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class demo
{
public:
int n,r;
void reverse(char s[50])
{

cout<<"\n enter string:";


gets(s);

cout<<"\n reverse string="<<strrev(s);


}
void reverse()
{
r=0;
cout<<"\n enter number:";
cin>>n;

while(n!=0)
{
r=r*10;
r=r+n%10;
n=n/10;
}
cout<<"\n reverse number="<<r;

}
};
void main()
{
char t[50];
demo r;
clrscr();
r.reverse(t);
r.reverse();
getch();
}
OPERATOR OVERLOADING

1)
#include<iostream.h>
#include<conio.h>
class Month
{
public:
int mno;
void Get();
void operator ++();
};
void Month :: Get()
{
cout<<"\n Enter the Month No. (1-12) : ";
cin>>mno;
}
void Month :: operator ++()
{
if(mno>=1 && mno<=12)
{
mno++;

if(mno==13)
{
mno=1;
}
cout<<"\n Next Month No. is : "<<mno;
}
}
void main()
{
clrscr();
Month m;
m.Get();
++m;
getch();
}
2)
#include<iostream.h>
#include<conio.h>
class Vector
{
public:
int h[6],p[6],i, A[6],S[6],M[6];
Vector(int [],int []);
void operator +();
void operator -();
void operator *();
void disp();
};

Vector :: Vector(int a[],int b[])


{
for(i=1;i<=5;i++)
{
h[i]=a[i];
p[i]=b[i];
}
}

void Vector :: operator +()


{
for(i=1;i<=5;i++)
{
A[i]=h[i]+p[i];
}
}
void Vector :: operator -()
{
for(i=1;i<=5;i++)
{
S[i]=h[i]-p[i];
}
}
void Vector :: operator *()
{
for(i=1;i<=5;i++)
{
M[i]=h[i]*p[i];
}
}

void Vector :: disp()


{
for(i=1;i<=5;i++)
{

cout<<"\n============================================
=";
cout<<"\n The addition of "<<i<<" two element is : "<<A[i];
cout<<"\n The substraction of "<<i<<" two element is : "<<S[i];
cout<<"\n The multiplication of "<<i<<"two element is :
"<<M[i];

cout<<"\n============================================
=";
}
}

void main()
{
int a[6],b[6],i;
clrscr();
for(i=1;i<=5;i++)
{
cout<<"\n Enter the 1st vector's "<<i<<" element : ";
cin>>a[i];
}
for(i=1;i<=5;i++)
{
cout<<"\n Enter the 2nd vector's "<<i<<" element : ";
cin>>b[i];
}
Vector V(a,b);
+V;
-V;
*V;
V.disp();
getch();
}
7)
#include<iostream.h>
#include<conio.h>
class Calender
{
public:
int dd,mm,yy;
Calender()
{
cout<<"\n Enter date for Default constructor ";
cout<<"\n----------------------------------------------";
cout<<"\n Enter the Date : ";
cin>>dd;
cout<<"\n Enter the Month : ";
cin>>mm;
cout<<"\n Enter the Year : ";
cin>>yy;
}
Calender(int d,int m,int y)
{

dd=d;
mm=m;
yy=y;
cout<<"\n Enter date for Parametrized constructor ";
cout<<"\n----------------------------------------------";
cout<<"\n Enter the Date : ";
cin>>dd;
cout<<"\n Enter the Month : ";
cin>>mm;
cout<<"\n Enter the Year : ";
cin>>yy;
}
/*~Calender()
{
delete ;
}*/
void operator ++();
void disp();
};
void Calender :: operator ++()
{
if(mm==12 && dd==31)
{
dd=1;
mm=1;
yy++;
}
if(dd<31)
{
dd++;
}
if(mm<12)
{
mm++;
}
}
void Calender :: disp()
{

cout<<"\n Tommorow is : "<<dd<<"-"<<mm<<"-"<<yy;

}
void main()
{
clrscr();
int d,m,y;
Calender C,C1(d,m,y);
clrscr();
cout<<"\n output of deafault constructor ";
++C;
C.disp();
cout<<"\n output of parameterized constructor ";
++C1;
C1.disp();
getch();
}

You might also like