Professional Documents
Culture Documents
Experiment: 11: Aim: To Study Inheritance in C++. Learning Outcomes: Learner Would Be Able To
Experiment: 11: Aim: To Study Inheritance in C++. Learning Outcomes: Learner Would Be Able To
Experiment: 11: Aim: To Study Inheritance in C++. Learning Outcomes: Learner Would Be Able To
Experiment: 11
PART A
Implement inheritance.
Task 1: Assume that a bank maintains two kinds of accounts for customers, one called as
savings and the other as current account. The savings account provides compound interest
and withdrawal facilities but no cheque book facility. The current account provides cheque
book facility but no interest. Current account holders should also maintain a minimum
balance and if the balance falls below this level a service charge is imposed. Create a class
account that stores customer name, account number and type of account. From this derive the
classes cur_acct and sav_acct to make them more specific to their requirements. Include
necessary member functions in order to achieve the following tasks:
(a) Accept the deposit from a customer and update the balance.
(e) Check for the minimum balance, impose penalty, necessary and update the balance.
PART B
Students must submit the soft copy as per following segments within two hours of
the practical. The soft copy must be uploaded on the portal at the end of the
practical. The filename should be PPS_batch_rollno_experimentno Example:
PPS_B2_B001_Exp1
Task 1:
#include <iostream>
class account
public:
string name;
void getdata()
void display()
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
cout << "The name of the customer is: " << name << endl;
cout << "The account number of the customer is: " << accno << endl;
};
public:
int balance;
void getdata()
account::getdata();
void display()
account::display();
cout << "The balance of the customer is: " << balance << endl;
void deposit()
int dep;
balance += dep;
void withdraw()
int wit;
else
balance -= wit;
};
public:
int balance;
void getdata()
account::getdata();
void display()
account::display();
cout << "The balance of the customer is: " << balance << endl;
void deposit()
int dep;
balance += dep;
void withdraw()
int wit;
else
balance -= wit;
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
void interest()
};
int main()
cur_acct c;
sav_acct s;
int ch;
cout << "Enter\n(1) for current account\n(2) for savings account: ";
if (ch == 1)
c.getdata();
c.deposit();
c.display();
c.withdraw();
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
c.display();
else if (ch == 2)
s.getdata();
s.deposit();
s.display();
s.withdraw();
s.display();
s.interest();
s.display();
else
}
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
Task 2:
#include <bits/stdc++.h>
class employee
public:
string name;
int empno;
void getdata()
{
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
void display()
cout << "The name of the employee is: " << name << endl;
cout << "The employee number of the employee is: " << empno << endl;
};
public:
string sub;
string pub;
void getdata()
employee::getdata();
void display()
{
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
employee::display();
cout << "The subject of the teacher is: " << sub << endl;
cout << "The publication of the teacher is: " << pub << endl;
};
public:
int speed;
void getdata()
employee::getdata();
void display()
employee::display();
cout << "The speed of the typist is: " << speed << endl;
};
public:
string grade;
void getdata()
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
employee::getdata();
void display()
employee::display();
cout << "The grade of the officer is: " << grade << endl;
};
public:
void getdata()
typist::getdata();
void display()
typist::display();
};
public:
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
int dailywage;
void getdata()
typist::getdata();
cout << "Enter the daily wage of the casual typist: ";
void display()
typist::display();
cout << "The daily wage of the casual typist is: " << dailywage << endl;
};
int main()
teacher t;
regular r;
casual c;
officer o;
int ch;
cout << "Enter\n(1) For teacher\n(2) For regular typist\n(3) For casual typist\n(4)
For officer: ";
if (ch == 1)
t.getdata();
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
t.display();
else if (ch == 2)
r.getdata();
r.display();
else if (ch == 3)
c.getdata();
c.display();
else if (ch == 4)
o.getdata();
o.display();
else
}
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
Conclusion (Learning Outcomes): Reflect on the questions answered by you jot down your
learnings about the Topic: Structure and Union