#include
#include
class result
{
long seatno;
int totalmarks;
int outofmarks;
void getdata();
void percentage();
void displaydata();
};
void result::getdata()
{
cout<<"Enter seatno,total marks,out of marks;
cin>>seatno>>totalmarks>>outofmarks;
}
void result::percentage()
{
percentage=(totalmarks)/(outofmarks)*100;
}
void result::display data()
{
cout<<"The percentage is<
}
void main()
{
result a;
a.getdata();
a.percentage();
a.displaydata();
getch();
} tdio.h>
#include
class result
{
long seatno;
int totalmarks;
int outofmarks;
void getdata();
void percentage();
void displaydata();
};
void result::getdata()
{
cout<<"Enter seatno,total marks,out of marks;
cin>>seatno>>totalmarks>>outofmarks;
}
void result::percentage()
{
percentage=(totalmarks)/(outofmarks)*100;
}
void result::display data()
{
cout<<"The percentage is<
}
void main()
{
result a;
a.getdata();
a.percentage();
a.displaydata();
getch();
}
12. Create a class to calculate the marksheet with the attributes seat no, total marks, out of marks for 10 students.
#include
#include
class result
{
long seatno;
int totalmarks;
int outofmarks;
public:
void getdata();
void percentage();
void displaydata();
};
void result::getdata()
{
cout<<"Enter seatno,total marks,out of marks;
cin>>seatno>>totalmarks>>outofmarks;
}
void result::percentage()
{
percentage=(totalmarks)/(outofmarks)*100;
}
void result::display data()
{
cout<<"The percentage is<
}
void main()
{
result a[10];
for(i=1;i<=10;i++)
{
a[i].getdata();
a[i].percentage();
a[i].displaydata();
}
getch();
} seatno;
int totalmarks;
int outofmarks;
public:
void getdata();
void percentage();
void displaydata();
};
void result::getdata()
{
cout<<"Enter seatno,total marks,out of marks;
cin>>seatno>>totalmarks>>outofmarks;
}
void result::percentage()
{
percentage=(totalmarks)/(outofmarks)*100;
}
void result::display data()
{
cout<<"The percentage is<
}
void main()
{
result a[10];
for(i=1;i<=10;i++)
{
a[i].getdata();
a[i].percentage();
a[i].displaydata();
}
getch();
}
13. to calculate the total salary using gross salary=basic + 47%DA + 30% HRA with attribute a.getdata b.calculate salary and c. show details.
#include
#include
class salary
{
float basic,HRA,DA;
float grosssalary;
public:
void getdata();
void calsalary();
void display();
};
void salary::getdata()
{
cout<<"Enter the basic salary \n";
cin>>basic;
DA=47/100*basic;
cout<
HRA=30/100*basic;
cout<
}
void salary::calsalary()
{
grosssalary=(basic+HRA=DA);
}
void salary::display()
{
cout<
}
void main()
{
clrscr();
salary s;
s.getdata();
s.calsalary();
s.display();
getch();
}
#include
class salary
{
float basic,HRA,DA;
float grosssalary;
public:
void getdata();
void calsalary();
void display();
};
void salary::getdata()
{
cout<<"Enter the basic salary \n";
cin>>basic;
DA=47/100*basic;
cout<
HRA=30/100*basic;
cout<
}
void salary::calsalary()
{
grosssalary=(basic+HRA=DA);
}
void salary::display()
{
cout<
}
void main()
{
clrscr();
salary s;
s.getdata();
s.calsalary();
s.display();
getch();
}
14. using switch statement. Create account class for following operators. 1. create account, 2.deposit, 3.withdraw. 4.bal enquiry 5.show details.
#include
#include
#include
class account
{
private:
long int actno;
char name[40];
float bal;
public:
account()
{
bal=500.00;
}
void createaccount()
{
cout<<" \n Enter ACT NO AND NAME \n";
cin>>actno>>name;
cout<<"\n Account is created sucessfully \n";
}
void deposit()
{
int deposit;
cout<<" \ n Enter Amt to Deposit \n";
Cin>>deposit;
bal=bal+deposit;
}
void withdraw()
{
int wd;
cout<<" \n Enter Amt to withdraw \n";
cin>>wd;
if(bal <= 500)
cout<<" \n Sorry! insufficient Amt \n";
else if(wd>=bal)
cout<<" \n Sorry! insufficient Amt \n";
else
bal=bal-wd;
}
void showdetails()
{
cout<<" \n--------------------Welcome to SBI----------------\n";
cout<<" \n A/c no.<
cout<<" \n Name"<
cout<<" \n Balance"<
cout<<" \n---------------------SBI--------------------------\n";
}
};
void main()
{
clrscr();
account a;
int op;
do{
cout<<"\n---------------------------------------------------\n";
cout<<"\n OPTION 1:- create A/c \n";
cout<<"\n OPTION 2:- Deposit \n";
cout<<"\n OPTION 3:- Withdrawn \n";
cout<<"\n OPTION 4:- Bal Enquiry \n";
cout<<"\n OPTION 5:- EXIT \n";
cout<<"\n Enter your choice \n";
cout<<"\n---------------------------------------------------\n";
cin>>op;
switch(op)
{
case1:a.create account();break;
case2:a.deposit();break;
case3:a.withdraw();break;
case4:a.showdetails();break;
case5:exit(0);
default:cout<<"Sorry!Invalid choice";
}
}
while(op!=5);
getch();
}
15. using switch statement. create a/c class for following operators for 10 persons - create a/c, deposit, withdraw, bal enquiry, show details.
#include
#include
#include
class account
{
private:
long int actno;
char name[40];
float bal;
public:
account()
{
bal=500.00;
}
void createaccount()
{
cout<<" \n Enter ACT NO AND NAME \n";
cin>>actno>>name;
cout<<"\n Account is created sucessfully \n";
}
void deposit()
{
int deposit;
cout<<" \ n Enter Amt to Deposit \n";
Cin>>deposit;
bal=bal+deposit;
}
void withdraw()
{
int wd;
cout<<" \n Enter Amt to withdraw \n";
cin>>wd;
if(bal <= 500)
cout<<" \n Sorry! insufficient Amt \n";
else if(wd>=bal)
cout<<" \n Sorry! insufficient Amt \n";
else
bal=bal-wd;
}
void showdetails()
{
cout<<" \n--------------------Welcome to SBI----------------\n";
cout<<" \n A/c no.<
cout<<" \n Name"<
cout<<" \n Balance"<
cout<<" \n---------------------SBI--------------------------\n";
}
};
void main()
{
clrscr();
account a[i];
int op;
for(i=1;i<=10,i++)
{
do
{
cout<<"\n---------------------------------------------------\n";
cout<<"\n OPTION 1:- create A/c \n";
cout<<"\n OPTION 2:- Deposit \n";
cout<<"\n OPTION 3:- Withdrawn \n";
cout<<"\n OPTION 4:- Bal Enquiry \n";
cout<<"\n OPTION 5:- EXIT \n";
cout<<"\n Enter your choice \n";
cout<<"\n---------------------------------------------------\n";
cin>>op;
switch(op)
{
case1:a[i].create account();break;
case2:a[i].deposit();break;
case3:a[i].withdraw();break;
case4:a[i].showdetails();break;
case5:exit(0);
default:cout<<"Sorry!Invalid choice";
}
}
while(op!=5);
}
getch();
} ";
cout<<"\n OPTION 2:- Deposit \n";
cout<<"\n OPTION 3:- Withdrawn \n";
cout<<"\n OPTION 4:- Bal Enquiry \n";
cout<<"\n OPTION 5:- EXIT \n";
cout<<"\n Enter your choice \n";
cout<<"\n---------------------------------------------------\n";
cin>>op;
switch(op)
{
case1:a[i].create account();break;
case2:a[i].deposit();break;
case3:a[i].withdraw();break;
case4:a[i].showdetails();break;
case5:exit(0);
default:cout<<"Sorry!Invalid choice";
}
}
while(op!=5);
getch();
}
16. to calculate area of rectangle using DEFAULT CONSTRUCTION.
a] Default constructor
#include
#include
class rectangle
{
int l,b;
float area;
public:
void rectangle()
{
l=10;
b=20;
}
void calculate()
{
area=l*b;
}
void show()
{
cout<<"area= "<
}
};
void main()
{
clrscr();
rectangle r;
r.getdata();
r.calculate();
r.show();
getch();
}
b] PARAMETERIZED Constructor
#include
#include
class rectangle
{
int l,b;
float A;
public:
rectangle(int p,int q)
{
l=p;
b=q;
}
void call()
{
a=l*b;
}
void display()
{
cout<<"\n Length & Breadth is "<
cout<<"\n Area is "<<;
}
};
void main()
{
clrscr();
rectangle r(10,20);
r.cal();
r.display();
getch();
}
17th- Unary operator for increament
#include
#include
class unary
{
int x,y,z;
public:
void getdata();
void operator+();
void show();
};
void unary::getdata(int a,int b,int c)
{
x=a;
y=b;
z=c;
}
void unary::show
{
cout<
}
void main()
{
clrscr();
unary s;
s.getdata(2,3,4);
+s;
s.show();
getch();
}
18- Binary to overload + operator
#include
#include
class binary
{
float a,b;
public:
binary(float x,float y)
{
a=x;
b=y;
}
binary operator +(binary)
};
binary operator +(binary b)
{
binary p;
p.a=a+b/a;
p.b=b+b/b;
return(p);
}
void main()
{
binary c1,c2;
c1(1.2,2.3);
c2(2.0,2.1);
c3=c1+c2;
c3.show();
getch();
}
19- using(18) friend function
#include
#include
class binary
{
float a,b;
public:
binary(float x,float y)
{
a=x;
b=y;
}
void friend operator+(binary);
};
void friend operator+(binary);
{
binary p;
p.a=a+b1.a;
p.b=b+b1.b;
return(p);
}
void main()
{
binary c1,c2;
c1(1.2,2.3);
c2(2.0,2.1);
c3=c1+c2;
c3.show();
getch();
}
20 - for + operator for string
#include
#include
#include
class string
{
char *p;
int n;
public:
string(){n=0;p=0;}
string(const char *s);
string(const string &s);
friend string operator +(const string & s.cout string &t);
friend void show(const string s);
};
string::string(const char*s)
{
n=strlen(s);
p=new data[n+1];
strcpy(p,s);
}
string::string(const string &s)
{
n=s.n;
p=new char[n+1];
strcpy(p,s.p);
}
string operator+(const string &s, const string &t)
{
string temp;
temp.n=s.n+t.n;
temp.p=new char[temp.n+1];
strcpy(temp.p,s.p);
strcat(temp.p,t.p);
return(temp);
}
void show(const string s)
{
cout<
}
void main()
{
show(s1)="Bharati";
show(s2)="Vidyapeeth";
show(t3);
getch();
}
No comments:
Post a Comment
You can ask your queries here and we will try to get back to you as soon as we will be done working with that..
Note: Only a member of this blog may post a comment.