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

OPPs Assignment

Question 1 :
#include<iostream.h>
#include<conio.h>
#include<string.h>
class bank
{
char name[20];
int ano;
char atype[20];
float bal;
public:
void get(int no,char *n,char *t,float b)
{
strcpy(name,n);
ano=no;
strcpy(atype,t);
bal=b;
}
float deposit()
{
float amt;
cout<<“\nEnter amount: “;
cin>>amt;
bal=bal+amt;
return bal;
}
float withdrw()
{
float amt;
cout<<“\nHow many Rupees withdraw: “;
cin>>amt;
bal=bal-amt;
return bal;
}
void disp()
{
cout<<“\n\nAccount number: “<<ano;
cout<<“\n\nName: “<<name;
cout<<“\n\nAccount type: “<<atype;
cout<<“\n\nDeposit Amount: “<<deposit();
cout<<“\n\nAfter Withdraw Amount balnace: “<<withdrw();
}
};
void main()
{
int n;
char nm[20],t[20];
float a;
bank bk;
clrscr();
cout<<“\nEnter Account no.: “; cin>>n;
cout<<“\nEnter Name: “; cin>>nm;
cout<<“\nEnter account type: “; cin>>t;
cout<<“\nEnter balance amount: “;cin>>a;
bk.get(n,nm,t,a);
bk.disp();
getch();
}
Question 2 :
Question 3 :
#include<iostream>
using namespace std;
int hms_to_sec(int hr,int min, int sec);
int main()
{
int hr,min,sec;
int result =hms_to_sec(hr,min,sec);
cout << "result = " << result;
system("pause");
return 0;
}
int hms_to_sec(int hr,int min, int sec)
{
int seconds =0;
cout << "please enter hr" << endl;
cin >> hr;
cout << "please enter min" << endl;
cin >> min;
cout << "please enter sec" << endl;
cin >> sec;
seconds = (hr*60*60)+(min*60)+sec;
return seconds;
}
Question 4 :
#include<iostream.h>
#include<conio.h>
class electricity
{ char name[20];
int unit;
float Rs;
public:
void get()
{
cout<<“\nEnter the Name & Unit’s of Electricity user: \n”;
cin>>name>>unit;
}
void check()
{
if(unit<=100)
{
Rs=unit*0.40;
Rs=Rs+150;
}
else if(unit<=200||unit>100)
{
Rs=unit*0.50;
Rs=Rs+150;
}
else if(unit<=300||unit>200)
{
Rs=unit*0.60;
Rs=Rs+150;
}}
void disp()
{
if(Rs>=250)
{
Rs=Rs+0.15;
}
cout<<name<<” \t”<<Rs<<endl;
}
};
void main()
{
int n,i;
electricity e[10];
clrscr();
cout<<“\nHow many electricity User: \n”;
cin>>n;
for(i=0;i<n;i++)
{
e[i].get();
e[i].check();
}
cout<<“\nElectricity User’s: \n”;
cout<<“\nName\t Total cost(Rs)\n”;
cout<<“=================================\n”;
for(i=0;i<n;i++)
{
e[i].disp();
}
getch();
}
Question 5 :
#include<iostream.h>
#include<conio.h>
class power
{
public:
inline int square(int n)
{
return n*n;
}
inline int cube(int n)
{
return n*n*n;
}
};
void main()
{
int n,r;
power p;
clrscr();
cout<<“\nEnter the Number: \n” ;
cin>>n;
r=p.square(n);
cout<<“\nSquare of “<<n<<” = “<<r<<endl;
r=p.cube(n);
cout<<“\nCube of “<<n<<” = “<<r<<endl;
getch();
}

You might also like