Professional Documents
Culture Documents
OOP_LAB-6
BISAM AHMAD
Task-1:
#include<iostream>
#include<string>
using namespace std;
struct library
{
char title[20];
int identifier;
char author[20];
char genere[20];
int found;
bool flag1 = true;
bool flag2 = true;
bool flag3 = true;
Output:
Task-2:
#include <iostream>
#include <string>
using namespace std;
struct player
{
char name[20];
int home_runs;
int hits;
};
int main()
{
player players[3];
int index;
char choice;
bool flag = true;
string player_name;
do
{
cout << endl;
cout << "Input data " << endl;
cout << "Update player " << endl;
cout << "Output data " << endl;
cout << "Exit" << endl;
cout << "Enter your choice = ";
cin >> choice;
switch (choice)
{
case 'i':
players[0].input(players);
break;
case 'u':
cin.ignore();
cout << "Enter player name = ";
cin >> player_name;
players[0].update(players, player_name);
break;
case 'e':
cout << "Program Terminated " << endl;
flag = false;
break;
case 'o':
players[0].output(players);
break;
default:
cout << "Invalid choice " << endl;
break;
}
} while (flag);
system("pause");
return 0;
}
Output:
Task-4:
#include<iostream>
#include<string>
using namespace std;
class person
{
private:
string name;
int age;
bool male;
string occupation;
bool cook;
public:
void inputs(string &n, int &age, bool &male, string &occupation, bool &cook)
{
char choice;
cout << "Enter name = ";
cin >> n;
cout << "Enter age = ";
cin >> age;
cout << "Enter occupation = ";
cin >> occupation;
cout << "Are you male (y/n) = ";
cin >> choice;
if (choice == 'y')
{
male = true;
}
else
{
male = false;
}
cout << "Can you cook (y/n) = ";
cin >> choice;
if (choice == 'y')
{
cook = true;
}
else
{
cook = false;
}
}
void intidata(string n, int age, bool male, string occupation, bool cook, person
p[2],int i)
{
p[i].name = n;
p[i].age = age;
p[i].male = male;
p[i].occupation = occupation;
p[i].cook = cook;
}
void output(person p[2],int i)
{
cout << "Name = " << p[i].name << endl;
cout << "Age = " << p[i].age << endl;
if (p[i].male == true)
{
cout << "You are male" << endl;
}
else
{
cout << "You are not male" << endl;
}
cout << "Occupation = " << p[i].occupation << endl;
if (p[i].cook == true)
{
cout << "You can cook" << endl;
}
else
{
cout << "You cannot cook" << endl;
}
}
};
int main()
{
person p[2];
string n;
int age;
bool male;
string occupation;
bool cook;
for (int i = 0; i < 2; i++)
{
p[0].inputs(n, age, male, occupation, cook);
p[0].intidata(n, age, male, occupation, cook,p,i);
}
for (int i = 0; i < 2; i++)
{
p[0].output(p,i);
}
system("pause");
return 0;
}
Output:
Task-5:
#include <iostream>
#include <string>
class BankAccount
{
private:
int account_number;
double balance;
string owner_name;
public:
void Account(int num, double bal, string name)
{
account_number = num;
balance = bal;
owner_name = name;
}
void dis()
{
cout << " Account Holder :" << owner_name << endl;
cout << " Account Number :" << account_number << endl;
cout << " Current Balance :" << balance << endl;
}
double check_balance()
{
return balance;
}
};
int main()
{
int acc1, acc2;
double bal1, bal2;
string name1, name2;
cout << "Enter Account number: ";
cin >> acc1;
cout << "Enter Balance : ";
cin >> bal1;
cout << "Enter Account Holder Name : ";
cin >> name1;
cout << " 2nd Account \n " << endl;
cout << "Enter Account number: ";
cin >> acc2;
cout << "Enter Balance : ";
cin >> bal2;
cout << "Enter Account Holder Name : ";
cin >> name2;
cout << "Enter amount to deposit into account number " << acc1 << " : ";
cin >> deposit_amount;
user1.deposit(deposit_amount);
cout << "Enter amount to withdraw from account number " << acc1 << ": ";
cin >> withdraw_amount;
user1.withdraw(withdraw_amount);
cout << "Enter amount to deposit into account number " << acc2 << ": ";
cin >> deposit_amount;
user2.deposit(deposit_amount);
cout << "Enter amount to withdraw from account number " << acc2 << ": ";
cin >> withdraw_amount;
user2.withdraw(withdraw_amount);
user1.dis();
cout << " 2nd Account \n " << endl;
user2.dis();
system("pause");
return 0;
}
Output: