Professional Documents
Culture Documents
Gharuan, Mohali
Assignment : OOPS
Institute/Department: University Institute of Engineering
1) Name
2) Account number
3) Type of account
4) Bal. amt
Member functions –
b. To deposit an account
c. To withdraw an account
Solution : #include<iostream>
#include<stdio.h>
#include<string.h>
class bank
int acno;
float bal;
public:
acno=acc_no;
strcpy(nm, name);
strcpy(acctype, acc_type);
bal=balance;
void deposit();
void withdraw();
void display();
};
void bank::deposit()
int damt1;
cin>>damt1;
bal+=damt1;
void bank::withdraw()
int wamt1;
cin>>wamt1;
if(wamt1>bal)
bal-=wamt1;
void bank::display()
cout<<"\n ----------------------";
int main()
int acc_no;
float balance;
cout<<"\n Enter Details: \n";
cout<<"-----------------------";
cin>>acc_no;
cin>>name;
cin>>acc_type;
cin>>balance;
b1.deposit();
b1.withdraw();
b1.display();
return 0;
OUTPUT :-
Q2. What is the difference between friend function and inline function? Explain with
examples.
Solution :
Q3. Write a function called hms_to_secs() that takes three int values—for hours,
minutes, and seconds—as arguments, and returns the equivalent time in seconds (type
long). Create a program that exercises this function by repeatedly obtaining a time value
in hours, minutes, and seconds from the user (format 12:59:59), calling the function,
and displaying the value of seconds it returns.
Solution: #include<iostream>
int main()
{
int hr,min,sec;
system("pause");
return 0;
seconds = (hr*60*60)+(min*60)+sec;
return seconds;
OUTPUT :-
Q4. An electricity board charges the following rates to users – For first 100 units : 40p
per unit – For next 200 units : 50p per unit – Beyond 300 units : 60p per unit All users
are charged a minimum of Rs.150. If the total cost is more than Rs.250.00 then an
additional charges of 15% are added. Write a C++ program using class to read the name
of users & number of units consumed & print out the charges with names.
Solution : #include<iostream>
class Electric
{
float unit;
char name[20];
public:
void accept()
cin>>name;
cin>>unit;
void print_bill();
};
void Electric::print_bill()
int bill=0;
bill=(500+(unit*0.40));
bill=(500+(unit*0.40)+(unit*0.50));
else if(unit>300)
bill=(500+(unit*0.60));
if(bill>250)
bill=(bill+(bill*(15/100)));
cout<<"\n Bill = "<<bill<<"\t"<<name;
int main()
Electric e[10];
int i,cnt;
cin>>cnt;
e[i].accept();
e[i].print_bill();
return 0;
OUTPUT :-
Q5. Write a program to find the cube of a number by showing use of inline
function.
Solution :
#include <iostream>
class cube
int a, acube;
public:
void geta();
void show();
};
void cube::geta()
cin >> a ;
void cube::cubea()
acube = a*a*a ;
}
void cube::show()
cout << endl << "Entered number(a)=" << a << endl << "Cube of a=" << acube << endl ;
int main()
cube c1;
c1.geta();
c1.cubea();
c1.show();
return 0;
OUTPUT :-