0% found this document useful (0 votes)
40 views5 pages

C++ Programming Assignments Solutions

The document contains 5 programming questions related to C++ classes. Question 1 defines a Bank class with methods to get, deposit, withdraw, and display account details. Question 2 and 3 are left blank. Question 4 defines an Electricity class to calculate electricity bills based on units consumed. Question 5 defines a Power class with inline square and cube methods to calculate powers of a number.

Uploaded by

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

C++ Programming Assignments Solutions

The document contains 5 programming questions related to C++ classes. Question 1 defines a Bank class with methods to get, deposit, withdraw, and display account details. Question 2 and 3 are left blank. Question 4 defines an Electricity class to calculate electricity bills based on units consumed. Question 5 defines a Power class with inline square and cube methods to calculate powers of a number.

Uploaded by

Battle King
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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;
[Link](n,nm,t,a);
[Link]();
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=[Link](n);
cout<<“\nSquare of “<<n<<” = “<<r<<endl;
r=[Link](n);
cout<<“\nCube of “<<n<<” = “<<r<<endl;
getch();
}

You might also like