Oop Lab No 11
Oop Lab No 11
Oop Lab No 11
class Publication
{
private:
string title;
float price;
public:
void getData()
{
cout<<"\nEnter Title: ";
cin>>title;
cout<<"Enter Price: $";
cin>>price;
}
void putData()
{ cout<<"\nTitle: "<<title<<"\nPrice: "<<price;
}
};
class Book : public Publication
{
private:
int pages;
public:
void getData()
{ Publication::getData(); cout<<"Enter Pages: "; cin>>pages; }
void putData()
{ Publication::putData(); cout<<"nPages: "<<pages; }
};
void putData()
{ Publication::putData(); cout<<"\nMinutes: "<<minutes; }
};
int main()
{
Book b; Tape t;
b.getData();
t.getData();
cout<<"\a"<<endl;
b.putData();
cout<<endl;
t.putData();
cout<<endl;
return 0;
}
Task 2:
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
class publication
{
private:
string title;
float price;
public:
void getdata(void)
{
string t;
float p;
cout << "Enter title of publication: ";
cin >> t;
cout << "Enter price of publication: ";
cin >> p;
title = t;
price = p;
}
void putdata(void)
{
cout << "Publication title: " << title << endl;
cout << "Publication price: " << price << endl;
}
};
class sales
{
private:
float s1, s2, s3;
public:
void getdata(void)
{
cout << "Enter month 1 sale: $";
cin >> s1;
cout << "Enter month 2 sale: $";
cin >> s2;
cout << "Enter month 3 sale: $";
cin >> s3;
}
void putdata(void)
{
cout << "Month 1 sale: $" << s1 << endl;
cout << "Month 2 sale: $" << s2 << endl;
cout << "Month 3 sale: $" << s3 << endl;
}
};
class book :public publication,public sales
{
private:
int pagecount;
public:
void getdata(void)
{
publication::getdata();
sales::getdata();
cout << "Enter Book Page Count: ";
cin >> pagecount;
}
void putdata(void)
{
publication::putdata();
sales::putdata();
cout << "Book page count: " << pagecount << endl;
}
};
class tape :public publication,public sales
{
private:
float ptime;
public:
void getdata(void)
{
publication::getdata();
sales::getdata();
cout << "Enter tap's playing time: ";
cin >> ptime;
}
void putdata(void)
{
publication::putdata();
sales::putdata();
cout << "Tap's playing time: " << ptime << endl;
}
};
int main()
{
book b;
tape t;
b.getdata();
t.getdata();
b.putdata();
t.putdata();
_getch();
}
Task 3
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
class publication
{
private:
string title;
float price;
public:
void getdata(void)
{
string t;
float p;
cout << "Enter title of publication: ";
cin >> t;
cout << "Enter price of publication: ";
cin >> p;
title = t;
price = p;
}
void putdata(void)
{
cout << "Publication title: " << title << endl;
cout << "Publication price: " << price << endl;
}
};
class sales
{
private:
float s1, s2, s3;
public:
void getdata(void)
{
cout << "Enter month 1 sale: $";
cin >> s1;
cout << "Enter month 2 sale: $";
cin >> s2;
cout << "Enter month 3 sale: $";
cin >> s3;
}
void putdata(void)
{
cout << "Month 1 sale: $" << s1 << endl;
cout << "Month 2 sale: $" << s2 << endl;
cout << "Month 3 sale: $" << s3 << endl;
}
};
class book :public publication, public sales
{
private:
int pagecount;
public:
void getdata(void)
{
publication::getdata();
sales::getdata();
cout << "Enter Book Page Count: ";
cin >> pagecount;
}
void putdata(void)
{
publication::putdata();
sales::putdata();
cout << "Book page count: " << pagecount << endl;
}
};
class tape :public publication, public sales
{
private:
float ptime;
public:
void getdata(void)
{
publication::getdata();
sales::getdata();
cout << "Enter tap's playing time: ";
cin >> ptime;
}
void putdata(void)
{
publication::putdata();
sales::putdata();
cout << "Tap's playing time: " << ptime << endl;
}
};
class disk :public publication
{
private:
enum dtype
{CD,DVD};
dtype userchoice;
public:
void getdata(void)
{
char a;
publication::getdata();
cout << "Enter disk type (c or d) for CD and DVD: ";
cin >> a;
if (a == 'c')
userchoice = CD;
else
userchoice = DVD;
}
void putdata()
{
publication::putdata();
cout << "Disk type is: ";
if (userchoice == CD)
cout << "CD";
else
cout << "DVD";
}
};
int main()
{
disk d;
d.getdata();
d.putdata();
_getch();
}
TASK 4
#include <iostream>
using namespace std;
class BankAccount
{
public:
int accountNumber;
double Balance;
public:
BankAccount(int Accno,double Bal)
{
accountNumber = Accno;
Balance = Bal;
}
BankAccount()
{
}
public:
double getBal()
{
return(Balance);
}
int getAccNo()
{
return(accountNumber);
}
void setBal(double amount)
{
Balance = amount;
}
void setAccNo(int Accno)
{
accountNumber = Accno;
}
void virtual showAccNo()
{
cout << " ---------------------------------" << endl;
cout << " || Account Info " << endl;
cout << " ---------------------------------" << endl;
cout << " || Account Number :" << accountNumber << endl;
cout << " || Account Balance:" << Balance << endl;
cout << " ---------------------------------" << endl;
cout << endl;
}
public:
CheckingAccount(int pAccno,double pAmnt,double
pIntrst):BankAccount(pAccno,pAmnt)
{
Intrst = pIntrst;
minBal = 500;//By default
}
double retIntRate()
{
return(Intrst);
}
double retSerChge()
{
return(serChge);
}
void showAccNo()
{
cout << " ---------------------------------" << endl;
cout << " || Account Info " << endl;
cout << " ---------------------------------" << endl;
cout << " || Account Number :" << accountNumber << endl;
cout << " || Account Balance:" << Balance << endl;
cout << " ---------------------------------" << endl;
cout << endl;
}
};
class SavingAccount:BankAccount
{
double minBal;
public:
SavingAccount(int pAccno,double pAmnt):BankAccount(pAccno,pAmnt)
{
minBal = 500;
}
double depAmnt(double dAmnt)
{
Balance = Balance + dAmnt;
return(Balance);
}
double wdrawAmnt(double wAmnt)
{
if(wAmnt <= Balance)
Balance = Balance - wAmnt;
else
cout << "You have in sufficient funds!" << endl;
return(Balance);
}
void setMinBal(double mBal)
{
minBal = mBal;
}
void showAccNo()
{
cout << endl;
cout << " ---------------------------------" << endl;
cout << " || Account Info " << endl;
cout << " ---------------------------------" << endl;
cout << " || Account Number :" << accountNumber << endl;
cout << " || Account Balance:" << Balance << endl;
cout << " ---------------------------------" << endl;
cout << endl;
}
};
int main()
{
double amount;
int choice;
do
{
cout << endl;
cout << " Create an Account " << endl;
cout << " *****************************" << endl;
cout << " ** 1 - Checking Account **" << endl;
cout << " ** 2 - Saving Account **" << endl;
cout << " ** 3 - Exit **" << endl;
cout << " *****************************" << endl;
cin >> choice;
cout << endl;
if(choice==1)
{
cout << "Enter account number: " << endl;
int Accno;
cin >> Accno;
cout << "Enter opening balance: " << endl;
double newBal;
cin >> newBal;
double intRate;
cout << "Enter interest rate: " << endl;
cin >> intRate;
CheckingAccount obj(Accno,newBal,intRate);
int accChoice;
do
{
cout << endl;
cout << " *************************" << endl;
cout << " ** 1 - Deposit **" << endl;
cout << " ** 2 - Withdraw **" << endl;
cout << " ** 3 - Account Info **" << endl;
cout << " ** 4 - Exit **" << endl;
cout << " *************************" << endl;
cin >> accChoice;
cout << endl;
switch(accChoice)
{
case 1:
cout << "Enter amount: " << endl;
cin >> amount;
double dAmnt;
dAmnt = obj.depAmnt(amount);
cout << "Available balance: " << dAmnt << endl;
break;
case 2:
cout << "Enter amount: " << endl;
cin >> amount;
double wAmnt;
wAmnt = obj.wdrawAmnt(amount);
cout << "Available balance: "<< wAmnt << endl;
break;
case 3:
obj.showAccNo();
break;
}
}
while(accChoice!=4);
}
else if(choice==2)
{
cout << "Enter account number:" << endl;
int pAccno;
cin >> pAccno;
cout << "Enter opening balance:" << endl;
double pnewBal;
cin >> pnewBal;
double _irate;
cout << "Enter interest rate:" << endl;
cin >> _irate;
SavingAccount sObj(pAccno,pnewBal);
int pChoice;
do
{
cout << endl;
cout << " *************************" << endl;
cout << " ** 1 - Deposit **" << endl;
cout << " ** 2 - Withdraw **" << endl;
cout << " ** 3 - Account Info **" << endl;
cout << " ** 4 - Exit **" << endl;
cout << " *************************" << endl;
cin>>pChoice;
cout << endl;
switch(pChoice)
{
case 1:
cout << "Enter amount:" << endl;
cin >> amount;
double _dAmnt;
_dAmnt = sObj.depAmnt(amount);
cout << "Available balance: " << _dAmnt;
break;
case 2:
cout << "Enter amount:" << endl;
cin >> amount;
double _wamount;
_wamount = sObj.wdrawAmnt(amount);
cout << "Available balance: " << _wamount;
break;
case 3:
sObj.showAccNo();
break;
case 4:
break;
default:
cout << "Invalid choice";
break;
}
}
while(pChoice!=4);
}
}
while(choice!=3);
}
TASK 5
#include<iostream>
using namespace std;
class A
{
public:
A()
{
cout << "A's constructor called" << endl; }
};
class B
{
public:
B()
{
cout << "B's constructor called" << endl; }
};
int main()
{
C c;
return 0;
}