PL Finall
PL Finall
PL Finall
Code:
Output:
(2) Aim: Create a class called bank acc that has private member variables for acc no and balance.
Include member function to deposite and withdraw money from the acc and display the balance
amount for n consumers
Code:
#include <iostream>
class BankAccount {
private:
int accNo;
double balance;
public:
if (amount > 0) {
balance += amount;
cout << "Deposit successful for account " << accNo << endl;
} else {
cout << "Invalid deposit amount for account " << accNo << endl;
cout << "Withdrawal successful for account " << accNo << endl;
} else {
cout << "Insufficient funds or invalid withdrawal amount for account " << accNo << endl;
};
int main() {
int n;
cin >> n;
int accNo;
double balance;
cout << "Enter account number for consumer " << i + 1 << ": ";
cout << "Enter initial balance for consumer " << i + 1 << ": ";
cin >> balance;
int choice;
do {
cout << "\nMenu for account " << accNo << endl;
switch (choice) {
case 1: {
double depositAmount;
account.deposit(depositAmount);
break;
case 2: {
double withdrawAmount;
account.withdraw(withdrawAmount);
break;
case 3:
account.displayBalance();
break;
default:
return 0;
Output:
1. Deposit
2. Withdraw
3. Display Balance
4. Exit
1. Deposit
2. Withdraw
3. Display Balance
4. Exit
1. Deposit
2. Withdraw
3. Display Balance
4. Exit
Enter your choice: 3
Balance: 750.0
1. Deposit
2. Withdraw
3. Display Balance
4. Exit
1. Deposit
2. Withdraw
3. Display Balance
4. Exit
Balance: 2500.0
(3) Aim: Write a C++ program to print complex no. using constructor overloading ( use all three
types of constructor)
Code:
#include <iostream>
class Complex {
private:
double real;
double imag;
public:
cout << real << (imag >= 0 ? "+" : "") << imag << "i" << endl;
};
int main() {
Complex c1;
c1.display();
Complex c2(5.0);
c2.display();
Complex c3(c2);
c3.display();
return 0;
Output:
5+5i
5+5i
(4) Aim: Creta a class called e- bill with data members as integers 'u' denoting the amount of units of
electricity consumed, the task is to calculate the electricity bill with the help of below charges
Code:
#include <iostream>
class EBill {
private:
int units;
public:
int calculateBill() {
int billAmount = 0;
billAmount = units * 5;
return billAmount;
void displayBill() {
};
int main() {
int consumedUnits;
EBill bill(consumedUnits);
bill.displayBill();
return 0;
}
OUTPUT:
Code:
#include <iostream>
class Employee {
public:
};
private:
public:
};
private:
};
private:
public:
};
private:
public:
}
};
int main() {
SoftwareDeveloper dev;
Trainer trainer;
Tester tester;
Programmer programmer;
dev.displaySalary();
trainer.displaySalary();
tester.displaySalary();
programmer.displaySalary();
return 0;
Output:
Code:
Output:
(7) Aim: For hybrid inheritance for following scenario.
"Ferrari" Class derived from car and racing class, car class is derived from class vehicle.
Code:
Output:
(8) Aim: Write a C++ program to overload '+' operator.
Code:
Output:
(9) Aim: Create a template to find maximum value from given to values. ( values can be character,
integer, double or float).
Code:
(10)Aim: Write a C++ program to divide two numbers, throws an exception when the divisor is zero.
Code: