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

Assignment # 1 :-

Course title:

Object Oriented Program

Course code:

SE-104

Submitted to:

Mr.Naveed Abbas

Submitted by:

Huzaifa muqeet

Roll no:

22014198-051

Section:

BS-SE-22 A

Department:

Software engineering
OOP LAB TASK

Q#1.

Writer class player that contain attributes for the player attibutes average and
team. Write three function to input change and display these attributes also write
a constructor that ask input to initialized all the attributes.

Ans.
#include <iostream>
using namespace std;

class player{
private:
char team[120];
double average;
public:
player(){
cout<<"Enter player team: ";
cin.getline(team,120);
cout<<"Enter player's average: ";
cin>>average;
}

void display();
int changer();
};

void player :: display(){


cout<<"Player's Team is "<<team<<endl<<"Player's average is "<<average<<"\n\n";
}

int player :: changer(){


char op;
line_26:
cout<<"Do you want to change existing values (Y,N): ";
cin>>op;
if(op == 'Y' || op == 'y'){
cin.ignore();
cout<<endl<<"Enter Player's Team: ";
cin.getline(team,120);
cout<<"Enter Player's averge: ";
cin>>average;
return 0;
}
else if( op == 'N' || op == 'n' ){
return 0;
}
else{
cout<<"Invalid choice\n";
goto line_26;
}
}

int main (){


player a1;
a1.display();
a1.changer();
a1.display();
cout<<"Program has been ended\n";
return 0;
}

Output:
Enter player team: colombia
Enter player's average: 14
Player's Team is colombia
Player's average is 14

Do you want to change existing values (Y,N): Y

Enter Player's Team: russia


Enter Player's averge: 17
Player's Team is russia
Player's average is 17

Program has been ended


Q#2.

Define a class for a bank account that includes the following data members
name of the depositor account number type of account balance amount in the
account. Ji class also contain the following member function Constructed to assign
initial values. Devotional functions to deposit some amount it should accept the
amount as perameters. The functions to withdraw and amount after checking the
balance it should accept the amount as parameters. Display function to display
name and balance.

Ans.

#include <iostream>
using namespace std;

class BankAccount {
private:
string name;
int accountNumber;
string accountType;
float balance;

public:
BankAccount(string n, int aN, string aT, float b) {
name = n;
accountNumber = aN;
accountType= aT;
balance = b;
}

void deposit(float amount) {


balance += amount;
}

void withdraw(float amount) {


if (balance >= amount) {
balance -= amount;
}
else {
cout << "Insufficient balance" << endl;
}
}

void display() {
cout << "Name: " << name << endl;
cout << "Account Number: " << accountNumber << endl;
cout << "Account Type: " << accountType << endl;
cout << "Balance: " << balance << endl<<endl;
}
};

int main() {
BankAccount account1("Hanzala", 22014198060, "current", 10099.0);
account1.display();

account1.deposit(599.0);
account1.display();

account1.withdraw(999.0);
account1.display();

return 0;
}

Output:

Name: Huzaifa
Account Number: 539361580
Account Type: current
Balance: 10099

Name: Huzaifa
Account Number: 539361580
Account Type: current
Balance: 10698

Name: Huzaifa
Account Number: 539361580
Account Type: current
Balance: 9699

<========================>

You might also like