Solved Assignment
Solved Assignment
Solved Assignment
#include<iostream>
#include<string>
using namespace std;
class Student {
private:
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;
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;
}
// Getter functions
string getOwnerName() {
return owner_name;
}
string getAccountType() {
return account_type;
}
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;
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;
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;
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;
}