Output:
};
int main()
{ int w,h;
rectangle s1;
cout<<"\nEnter the width of the rectangle ";
cin>>w;
cout<<"\n Enter the height of the rectangle ";
cin>>h;
s1.setwidth(w);
s1.setheight(h);
s1.area();
return 0;
}
Output:
return empno;
}
};
bool cmp(Employee e1,Employee e2)
{
e1.getnum()>e2.getnum();
}
int main()
{
Employee e[5];
int i;
for(i=0;i<5;i++)
{
e[i].accept();
}
for(i=0;i<5;i++)
{
e[i].display();
}
sort(e,e+5,cmp);
for(i=0;i<5;i++)
{
e[i].display();
}
return 0;
}
Output:
Conclusion: Here we learnt how to use the sort function and Boolean
function.
Program-4
Aim: Program for banking system in which a user can
deposit withdraw and calculate the compound interest
in the account.
Theory: Here we will use class to declare the balance
and the rate of interest and use constructor to initialize
their values respectively and use member function to
perform the various operation given to us and display
them using menu using the do while loop.
Source Code:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
class bank
{
private:
int balance;
float rate;
public:
bank(int b,float r)
{
rate = r;
balance = b;
}
void deposit()
{ int d;
cout<<"\n Enter the amount to be deposited : ";
cin>>d;
balance+=d;
}
void withdraw()
{ int c;
cout<<"\n Enter the amount to be withdrawn : ";
cin>>c;
if(balance>c)
{
cout<<"\n Amount withdrawn successfully";
balance=balance-c;
}
else
{
cout<<"\n Amount is not possible to be withdrawn because it exceeds your
current account balance";
}
}
void compound()
{ int a,t;
rate=(rate/100);
cout<<"\n Enter the time till which you want the compound interest to be applied :
";
cin>>t;
a=balance*pow(1+rate,t);
cout<<"\n the compound interest is : "<<a;
balance=a;
}
int getbalance()
{
return balance;
}
void menu()
{
char ch;
int ch1;
do
{
cout<<"\n============================================================
Menu ============================================================ ";
cout<<"\n\n\n\n\n\n 1. Deposit amount ";
cout<<"\n 2. Withdraw amount";
cout<<"\n 3. Calculate the compound interest ";
cout<<"\n 4. Check balance";
cout<<"\n 5. Exit";
cout<<"\n Enter the choice ";
cin>>ch;
switch(ch)
{
case '1':
deposit();
break;
case '2':
withdraw();
break;
case '3':
compound();
break;
case '4':
{
int h;
h=getbalance();
cout<<"\n Balance remaining in your account is : "<<h;
break;
}
case '5':
cout<<"\n Thanks for visiting the bank";
exit(1);
break;
}
cout<<"\n Want to enter more 1/2 (1:Yes,2:No)";
cin>>ch1;
cout<<ch1;
}while(ch1!=2);
}
};
int main()
{ int bal;
float r;
cout<<"\n Enter the balance : ";
cin>>bal;
cout<<"\n Enter the rate of interest : ";
cin>>r;
bank b(bal,r);
b.menu();
return 0;
}
Output:
}
int main()
{
int a,b;
char ch;
int ch1;
do
{
cout<<"\n============================================MENU====================
=====================";
cout<<"\n1. Swapping by value";
cout<<"\n2. Swapping by reference";
cout<<"\n3. Exit";
cout<<"\n Enter the choice";
cin>>ch;
switch(ch)
{
case '1':
{
cout<<"\n Enter the 2 numbers which are to be swapped";
cin>>a>>b;
swap_value(a,b);
}
break;
case '2':
{
cout<<"\n Enter the 2 numbers which are to be swapped";
cin>>a>>b;
swap_reference(&a,&b);
}
break;
case '3':
cout<<"\n Execution complete now exiting the program";
exit(1);
break;
}
cout<<"\n Want to enter more 1/2 1:Yes 2:No";
cin>>ch1;
}while(ch1!=2);
return 0;
}
Output:
};
int average(friendfunc1 x,friendfunc2 y)
{
return ((x.a+x.b+y.p+y.q+y.r)/5);
}
int main()
{
system("COLOR F4");
int avg;
friendfunc1 x;
friendfunc2 y;
x.getd1();
y.getd2();
avg=average(x,y);
cout<<"\n the average of 5 numbers is "<<avg;
return 0;
}
Output:
Output:
Output:
Output:
};
class daughter:public father
{
protected:
int age_daughter;
public:
daughter(int x,int z):age_daughter(x),father(z)
{}
void iam()
{
cout<<"\n She is the daughter , her age is : "<<age_daughter;
}
};
int main()
{
int x,y,z;
cout<<"\n Enter the age of the father";
cin>>z;
cout<<"\n Enter the age of the son ";
cin>>y;
cout<<"\n Enter the age of the daughter";
cin>>x;
father f(z);
son s(z,y);
daughter d(x,z);
f.iam();
s.iam();
d.iam();
father *f1;
f1=&f;
f1->iam();
f1=&s;
f1->iam();
f1=&d;
f1->iam();
return 0;
}
Output:
Output: