Solved Assignment

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

2.

#include<iostream>
#include<string>
using namespace std;

class Student {
private:

long int roll_number;


string name;
string cnic;
string degree;
string address;

public:
// Default constructor
Student() {
roll_number = 0;
name = "";
cnic = "";
degree = "";
address = "";
}

// Overloaded constructor
Student(long int r, string n, string c, string d, string a) {
roll_number = r;
name = n;
cnic = c;
degree = d;
address = a;
}

// Getter functions
long int getRollNumber() {
return roll_number;
}

string getName() {
return name;
}

string getCnic() {
return cnic;
}

string getDegree() {
return degree;
}

string getAddress() {
return address;
}

// Setter functions
void setRollNumber(long int x) {
roll_number = x;
}
void setName(string x) {
name = x;
}

void setCnic(string x) {
cnic = x;
}

void setDegree(string x) {
degree = x;
}

void setAddress(string x) {
address = x;
}

// Print function
void print() {
cout << "Roll Number: " << roll_number << endl;
cout << "Name: " << name << endl;
cout << "CNIC: " << cnic << endl;
cout << "Degree: " << degree << endl;
cout << "Address: " << address << endl;
}
};

int main() {

Student s;

long int roll_number;


string name, cnic, degree, address;
cout<<"\t\tInput details of students"<<endl;
cout << "Enter Roll Number Of Student: ";
cin >> roll_number;
cout << "Enter Name Of Student: ";
cin>>name;
cout << "Enter CNIC Of Student: ";
cin>>cnic;
cout << "Enter Degree Of Student: ";
cin>>degree;
cout << "Enter Address Of Student: ";
cin>>address;
cout<<"\t\tinformation of s\n";
s.setRollNumber(roll_number);
s.setName(name);
s.setCnic(cnic);
s.setDegree(degree);
s.setAddress(address);
cout << "Enter Roll Number Of Student: "<<s.getRollNumber()<<endl;
cout << "Enter Name Of Student: "<<s.getName()<<endl;
cout << "Enter CNIC Of Student: "<<s.getCnic()<<endl;
cout << "Enter Degree Of Student: "<<s.getDegree()<<endl;
cout << "Enter Address Of Student: "<<s.getAddress()<<endl;

// Creating an object using the parameterized constructor


Student s1(123456, "QASIM RAZA", "35202-2382299-2", "Bachelor of Science",
"shad bagh");
cout<<"\t\tinformation of s1\n";
s1.setRollNumber(roll_number);
s1.setName(name);
s1.setCnic(cnic);
s1.setDegree(degree);
s1.setAddress(address);
cout << "Enter Roll Number Of Student: "<<s1.getRollNumber()<<endl;
cout << "Enter Name Of Student: "<<s1.getName()<<endl;
cout << "Enter CNIC Of Student: "<<s1.getCnic()<<endl;
cout << "Enter Degree Of Student: "<<s1.getDegree()<<endl;
cout << "Enter Address Of Student: "<<s1.getAddress()<<endl;

// Printing details of both students


cout << "\tDetails of Student s:" << endl;
s.print();

cout << "\tDetails of Student s1:" << endl;


s1.print();

return 0;
}

*****************************************************************
3.
#include<iostream>
#include<string>
using namespace std;

class BankAccount {
private:
// Attributes of bank account
string owner_name;
string account_type;
long int account_number;
double balance;

public:
// Setter functions
void setOwnerName(string x) {
owner_name = x;
}

void setAccountType(string x) {
account_type = x;
}

void setBalance(double x) {
balance = x;
}

void setAccountNumber(long int x) {


account_number = x;
}

// Getter functions
string getOwnerName() {
return owner_name;
}

string getAccountType() {
return account_type;
}

long int getAccountNumber() {


return account_number;
}

double getBalance() {
return balance;
}

// Default constructor
BankAccount() {
owner_name = " ";
account_type = " ";
account_number = 0;
balance = 0.0;
}

// Overloading constructor
BankAccount(string o, string a, double b, long int t) {
owner_name = o;
account_type = a;
account_number = t;
balance = b;

// Function to deposit amount


void depositAmount() {
double amount;
cout << "Enter amount to deposit: ";
cin >> amount;
balance += amount;
cout << "\tAmount deposited successfully......." << endl;
cout<<"NEW BALANCE: "<<balance<<endl;
}

// Function to withdraw amount


void withdrawAmount() {
double amount;
cout << "Enter amount to withdraw: ";
cin >> amount;
if (amount > balance) {
cout << "Insufficient balance." << endl;
} else {
balance -= amount;
cout << "\tAmount withdrawn successfully......." << endl;
cout << "NEW BALANCE: " << balance << endl;
}
}
//check balance
void checkbalance(){
cout<<"your current balance is: "<<balance;
}
};

int main() {
BankAccount a;
string owner_name = "QASIM RAZA";
string account_type = "saving";
long int account_number = 1122007788;
double balance = 150000.0;
cout << "\tAccount Holder Details" << endl;

// Creating object using overloaded constructor


BankAccount a1(owner_name, account_type, balance, account_number);

a1.setOwnerName(owner_name);
a1.setAccountNumber(account_number);
a1.setAccountType(account_type);
a1.setBalance(balance);
cout << "NAME: " << a1.getOwnerName() << endl;
cout << "ACCOUNT NUMBER: " << a1.getAccountNumber() << endl;
cout << "ACCOUNT TYPE: " << a1.getAccountType() << endl;
cout << "BALANCE: " << a1.getBalance() << endl;

// Deposit or withdraw amount


int choice;
cout << "\tCHECK BALANCE, DEPOSIT AND WITHDRAW AMOUNT\n";
cout << "PRESS 1: CHECK BALANCE\nPRESS 2: DEPOSIT\nPRESS 3: WITHDRAW\n";
cin >> choice;

switch(choice) {
case 1:
a1.checkbalance();
break;
case 2:
cout << "Current Balance: " << balance << endl;
a1.depositAmount();
break;
case 3:
cout << "Current Balance: " << balance << endl;
a1.withdrawAmount();
break;
default:
cout << "Invalid choice." << endl;
}
return 0;
}

You might also like