0% found this document useful (0 votes)
3 views

OOP ASS 2

The document contains code for three separate programming assignments in C++. The first assignment involves creating a class for books and displaying their details, the second focuses on an academic system for managing student and teacher data, and the third is a bank account management system. Each section includes class definitions, methods for data handling, and user interaction through console input and output.

Uploaded by

s2024105070
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

OOP ASS 2

The document contains code for three separate programming assignments in C++. The first assignment involves creating a class for books and displaying their details, the second focuses on an academic system for managing student and teacher data, and the third is a bank account management system. Each section includes class definitions, methods for data handling, and user interaction through console input and output.

Uploaded by

s2024105070
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

NAME:BABAR USMAN KHAN

ID:S2024105070

SECTION:Y2

OOP ASSIGNMENT 02

Q1

#include<iostream>

using namespace std;

class Book

public:

int noofpages,price,a=1;;

string type;

int readdata()

cout<<"enter the no of pages "<<endl;

cin>>noofpages;

cout<<"Enter price "<<endl;

cin>>price;

cout<<"Enter the type of book foreign or local"<<endl;

cin>>type;

int displaydata()

cout<<a<<"\t\t"<<noofpages<<"\t\t\t"<<price<<"\t\t"<<type<<endl;
a++; }};

int main()

Book a[10];

for(int p=0;p<=9;p++)

a[p].readdata();}

cout<<"SR.no.\t\t"<<"No of pages\t\t"<<"price\t\t"<<"Type\t\t"<<endl;

cout<<"------\t\t"<<"-----------\t\t"<<"-----\t\t"<<"----"<<endl;

for(int d=0;d<=9;d++)

a[d].displaydata();

(Q NO 2)

#include<iostream>

using namespace std;

class academicsystem

public:
int id,age,marks,cnic,salary,summ=0,sums=0,avgmr,avgsal;

int student()

cout<<"Enter ID of student"<<endl;

cin>>id;

cout<<"Enter age of student"<<endl;

cin>>age;

cout<<"Enter marks of student"<<endl;

cin>>marks;

summ=summ+marks; }

int teacher()

cout<<"Enter CNIC of teacher"<<endl;

cin>>cnic;

cout<<"Enter age of teacher"<<endl;

cin>>age;

cout<<"Enter salary of teacher"<<endl;

cin>>salary;

sums=sums+salary;

int displaytstd()

cout<<"ID of student\t\t"<<"Age of student\t\t"<<"Marks of student\t\


t"<<endl;

cout<<"*************\t\t"<<"**************\t\
t"<<"****************\t\t"<<endl;

cout<<id<<"\t\t "<<age<<"\t\t "<<marks<<" \t\t"<<endl;

int displayteacher()
{

cout<<"CNIC of teacher\t\t"<<"Age of teacher\t\


t"<<"Salary of teacher\t\t"<<endl;

cout<<"***************\t\t"<<"**************\t\
t"<<"*****************\t\t"<<endl;

cout<<cnic<<"\t\t "<<age<<"\t\t
bb"<<salary<<endl;

int average()

avgmr=summ/5;

cout<<"average marks are:"<<avgmr<<endl;

int averageteacher()

{avgsal=sums/5;

cout<<"average salary is:"<<avgsal<<endl;

};

int main()

academicsystem a,S[5],T[5];

int b,c,f=0,e=0,h,i,j,minm,mins,minage,minaget,ma;

cout<<"Enter 1 to READ Data of a STUDENT.Enter 2 to READ Data of a TEACHER"<<endl;

cin>>ma;

if(ma==1)
{

for(int g=0;g<5;g++)

S[g].student();

}}

if(ma ==2)

for(int g=0;g<5;g++)

T[g].teacher();

cout<<"Enter 3 to DISPLAY Data of a particular STUDENT"<<endl;

cout<<"Enter 4 to DISPLAY Data of a particular TEACHER.Enter 5 to DISPLAY Data of ALL STUDENTS.Enter


6 to DISPLAY Data of ALL TEACHERS"<<endl;

cout<<"Enter 7 to DISPLAY AVERAGE MARKS of ALL STUDENTS.Enter 8 to DISPLAY AVERAGE SALARY of


ALL TEACHERS.Enter 9 to DISPLAY data of Teachers having MINIMUM SALARY"<<endl;
cout<<"Enter 10 to DISPLAY data of Students having Maximum MARKS.Enter 11 to DISPLAY data of all
Students and all Teachers having the same AGE"<<endl;

cout<<"Enter 12 to DISPLAY data of all Students and all Teachers having an AGE greater than the
AVERAGE AGE of all the Students and the Teachers"<<endl;

cin>>b;

if(b==3)

cout<<"whoms data do you want to see enter the serial number"<<endl;

cin>>h;

S[h].displaytstd();

if(b==4)

cout<<"whoms data do you want to see enter the serial number "<<endl;

cin>>j;

T[j].displayteacher();

if(b==5)

for(int m=0;m<5;m++)

cout<<S[m].displaytstd();

if(b==6)

for(int l=0;l<5;l++)

cout<<T[l].displayteacher();
}

if(b==7)

a.average();

if(b==8)

a.averageteacher();

if(b==9)

{mins=T[0].salary;

for(int n=1;n<5;n++)

if(T[0].salary<T[n].salary)

mins=T[n].salary;

cout<<"maximum salary teacher"<<T[n].salary<<"of"<<T[n].cnic<<endl;

if(b==10)

minm=S[0].marks;

for(int x=1;x<5;x++)
{

if(S[0].marks<S[x].marks)

minm=S[x].marks;

}}

cout<<"maximim marks"<<S[x].marks<<"of"<<S[x].id;

if(b==11)

for(int z=0;z<i;z++)

for(int J=0;J<c;j++)

if(S[J].age==T[z].age)

cout<<"the
student"<<S[J].id<<endl<<S[J].age<<"has the same age as the
teacher"<<T[z].cnic<<endl<<T[z].age<<endl;

for(int r=0;r<c;r++)

for(int k=0;k<i;k++)
{

if(S[r].age==T[k].age)

cout<<"the
student"<<S[r].id<<endl<<S[r].age<<"has the same age as the
teacher"<<T[k].cnic<<endl<<T[k].age<<endl;

if(b==12)

for(int z=0;z<5;z++)

for(int J=0;J<5;j++)

if(S[J].age==T[z].age)

cout<<"the
student"<<S[J].id<<endl<<S[J].age<<"has the same age as the
teacher"<<T[z].cnic<<endl<<T[z].age<<endl;

}
}

for(int r=0;r<5;r++)

for(int k=0;k<5;k++)

if(S[r].age==T[k].age)

cout<<"the
student"<<S[r].id<<endl<<S[r].age<<"has the same age as the
teacher"<<T[k].cnic<<endl<<T[k].age<<endl;

(Q NO 3)

#include <iostream>

#include <vector>

#include <string>

using namespace std;

class BankAccount {
public:

int accountNumber;

string accountName;

double balance;

BankAccount(int accountNumber, string accountName, double balance) {

accountNumber = accountNumber;

accountName = accountName;

balance = balance;

void deposit(double amount) {

balance += amount;

void withdraw(double amount) {

if (balance >= amount) {

balance -= amount;

} else {

cout << "Insufficient balance!" << endl;

void displayDetails() {

cout << "Account Number: " << accountNumber << endl;

cout << "Account Name: " << accountName << endl;

cout << "Balance: " << balance << endl;

};
class Bank {

public:

vector<BankAccount> accounts;

void createAccount() {

if (accounts.size() < 10) {

int accountNumber;

string accountName;

double balance;

cout << "Enter account number: ";

cin >> accountNumber;

cout << "Enter account name: ";

cin >> accountName;

cout << "Enter initial balance: ";

cin >> balance;

BankAccount newAccount(accountNumber, accountName, balance);

accounts.push_back(newAccount);

cout << "Account created successfully!" << endl;

} else {

cout << "Maximum limit of accounts reached!" << endl;

void removeAccount() {

int accountNumber;

cout << "Enter account number to remove: ";


cin >> accountNumber;

int accounts.erase(accountNumber);

cout << "Account removed successfully!" << endl;

return;

cout << "Account not found!" << endl;

void depositMoney() {

int accountNumber;

double amount;

cout << "Enter account number: ";

cin >> accountNumber;

cout << "Enter amount to deposit: ";

cin >> amount;

for (auto& account : accounts) {

if (account.accountNumber == accountNumber) {

account.deposit(amount);

cout << "Deposit successful!" << endl;

return;

}
cout << "Account not found!" << endl;

void withdrawMoney() {

int accountNumber;

double amount;

cout << "Enter account number: ";

cin >> accountNumber;

cout << "Enter amount to withdraw: ";

cin >> amount;

for (auto& account : accounts) {

if (account.accountNumber == accountNumber) {

account.withdraw(amount);

cout << "Withdrawal successful!" << endl;

return;

cout << "Account not found!" << endl;

void checkAccountDetails() {

int accountNumber;

cout << "Enter account number: ";

cin >> accountNumber;


for (const auto& account : accounts) {

if (account.accountNumber == accountNumber) {

account.displayDetails();

return;

cout << "Account not found!" << endl;

void displayMenu() {

cout << "Bank Account System" << endl;

cout << "1. Create a new account" << endl;

cout << "2. Remove an account" << endl;

cout << "3. Deposit money" << endl;

cout << "4. Withdraw money" << endl;

cout << "5. Check account details" << endl;

cout << "6. Quit" << endl;

};

int main() {

Bank bank;

while (true) {

bank.displayMenu();

int choice;

cout << "Enter your choice: ";


cin >> choice;

switch (choice) {

case 1:

bank.createAccount();

break;

case 2:

bank.removeAccount();

break;

case 3:

bank.depositMoney();

break;

case 4:

bank.withdrawMoney();

break;

case 5:

bank.checkAccountDetails();

break;

case 6:

return 0;

default:

cout << "Invalid choice. Please try again." << endl;

return 0;

You might also like