Professional Documents
Culture Documents
Problem - 01: Person
Problem - 01: Person
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
class Person
{
public:
Person() { for (int i = 0; i < 50; i++) { PhoneNum[i] = 0;} };
void display() {
cout << "\t\t\t\tI am in person" << endl;
}
void setVAL(int i)
{
this->Name[i] = "NULL";
bool strcheck = true;
int strcheck1 = 0;
while (strcheck == true)
{
cout << "\t\t\t\tName : "; cin >> this->Name[i];
stringstream ss(this->Name[i]);
if (ss >> strcheck1) { cout << "\t\t\t\tInputError" << endl; strcheck = true; }
else { strcheck = false; }
}
this->Adress[i] = "NULL";
strcheck = true;
strcheck1 = 0;
while (strcheck == true)
{
cout << "\t\t\t\tAdress : "; cin >> this->Adress[i];
stringstream ss(this->Adress[i]);
if (ss >> strcheck1) { cout << "\t\t\t\tInputError" << endl; strcheck = true; }
else { strcheck = false; }
}
this->Email[i] = "NULL";
strcheck = true;
strcheck1 = 0;
while (strcheck == true)
{
cout << "\t\t\t\tEmail : "; cin >> this->Email[i];
stringstream ss(this->Email[i]);
if (ss >> strcheck1) { cout << "\t\t\t\tInputError" << endl; strcheck = true; }
else { strcheck = false; }
}
cout << "\t\t\t\tTell : ";
while (!(cin >> PhoneNum[i]))
{
cout << "\t\t\t\tInputError" << endl;
cout << "\t\t\t\tTell : ";
cin.clear();
cin.ignore(50, '\n');
}
}
string getName(int i) { return this->Name[i]; };
string getAdress(int i) { return this->Adress[i]; };
string getEmail(int i) { return this->Email[i]; };
int getPhoneNum(int i) { return this->PhoneNum[i]; };
void checkO(int i)
{
cout << "\t\t\t\tName : " << this->getName(i) << endl;
cout << "\t\t\t\tAdress : " << this->getAdress(i) << endl;
cout << "\t\t\t\tEmail : " << this->getEmail(i) << endl;
cout << "\t\t\t\tPhone Number : " << this->getPhoneNum(i) << endl;
}
~Person() {};
private: string *Name=new string[50], *Adress=new string[50], *Email=new string[50]; int PhoneNum[50];
};
class Student:protected Person
{
public:
Student() { for (int i = 0; i < 50; i++) { CGPA[i] = 0; RollNum[i] = 0; } };
void display() {
cout << "\t\t\t\tEnter Number of Students you want to Enter Data : "; cin >> size;
cout << "\t\t\t\tI am in Student" << endl;
for (int i = 0; i < size; i++)
{
cout << "\n\t\t\t\tInput Data For Student " << i + 1 << endl;
StudentData.setVAL(i);
cout << "\t\t\t\tRoll Num : "; cin >> StudentData.RollNum[i];
cout << "\t\t\t\tCGPA : "; cin >> StudentData.CGPA[i];
}
for (int i = 0; i < size; i++)
{
cout << "\n\t\t\t\tOutput Data For Student " << i + 1 << endl;
StudentData.checkO(i);
cout << "\t\t\t\tRoll Num : " << StudentData.RollNum[i] << endl;
cout << "\t\t\t\tCGPA : " << StudentData.CGPA[i] << endl;
}
}
~Student() {};
private: int RollNum[50]; float CGPA[50]; int size = 0;
}StudentData;
class Employee :protected Person
{
public:
Employee() { for (int i = 0; i < 50; i++) { salary[i] = 0; } };
void display() {
cout << "\t\t\t\tI am in Employee" << endl;
cout << "\t\t\t\tEnter Number of Employees you want to Enter Data : "; cin >> size;
for (int i = 0; i < size; i++)
{
//cout << "\t\t\t\tInput Data For Employee " << i + 1 << endl;
obj.setVAL(i);
obj.office[i] = "NULL";
bool strcheck = true;
int strcheck1 = 0;
while (strcheck == true)
{
cout << "\t\t\t\tOffice : "; cin >> obj.office[i];
stringstream ss(obj.office[i]);
if (ss >> strcheck1) { cout << "\t\t\t\tInputError" << endl; strcheck =
true; }
else { strcheck = false; }
}
obj.setVAL(i);
obj.DateHired[i] = "NULL";
strcheck = true;
strcheck1 = 0;
while (strcheck == true)
{
cout << "\t\t\t\tDateHired : "; cin >> obj.DateHired[i];
stringstream ss(obj.DateHired[i]);
if (ss >> strcheck1) { cout << "\t\t\t\tInputError" << endl; strcheck =
true; }
else { strcheck = false; }
}
cout << "\t\t\t\tSalary : ";
while (!(cin >> obj.salary[i]))
{
cout << "\t\t\t\tInputError" << endl;
cout << "\t\t\t\tSalary : ";
cin.clear();
cin.ignore(50, '\n');
}
}
for (int i = 0; i < size; i++)
{
//cout << "\t\t\t\tInput Data For Employee " << i + 1 << endl;
obj.checkO(i);
cout << "\t\t\t\tOffice : " << obj.office[i] << endl;
cout << "\t\t\t\tDate Hired : " << obj.DateHired[i] << endl;
cout << "\t\t\t\tSalery : " << obj.salary[i] << endl;
}
}
~Employee() {};
private: string office[50], DateHired[50]; int salary[50]; int size = 0;
}obj;
class Faculty:protected Employee
{
public:
Faculty() { };
void display() {
cout << "\t\t\t\tI am in faculty" << endl;
cout << "\t\t\t\tEnter Number of Faculty you want to Enter Data : "; cin >> size;
for (int i = 0; i < size; i++)
{
cout << "\n\t\t\t\tInput Data For Faculty " << i + 1 << endl;
FacultyData.setVAL(i);
FacultyData.OfficeHours[i] = "NULL";
bool strcheck = true;
int strcheck1 = 0;
while (strcheck == true)
{
cout << "\t\t\t\tOfficeHours : "; cin >> FacultyData.OfficeHours[i];
stringstream ss(FacultyData.OfficeHours[i]);
if (ss >> strcheck1) { cout << "\t\t\t\tInputError" << endl; strcheck =
true; }
else { strcheck = false; }
}
FacultyData.Rank[i] = "NULL";
strcheck = true;
strcheck1 = 0;
while (strcheck == true)
{
cout << "\t\t\t\tRank : "; cin >> FacultyData.Rank[i];
stringstream ss(FacultyData.Rank[i]);
if (ss >> strcheck1) { cout << "\t\t\t\tInputError" << endl; strcheck =
true; }
else { strcheck = false; }
}
}
for (int i = 0; i < size; i++)
{
cout << "\n\t\t\t\tOutput Data For Faculty " << i + 1 << endl;
FacultyData.checkO(i);
cout << "\t\t\t\tOfficeHours : " << FacultyData.OfficeHours[i] << endl;
cout << "\t\t\t\tRank : " << FacultyData.Rank[i] << endl;
}
}
~Faculty() {};
private: string OfficeHours[50]; string Rank[50]; int size = 0;
}FacultyData;
class Staff:protected Employee
{
public:
Staff() { };
void display() {
cout << "\t\t\t\tI am in Staff" << endl;
cout << "\t\t\t\tEnter Number of Staff you want to Enter Data : "; cin >> size;
for (int i = 0; i < size; i++)
{
cout << "\n\t\t\t\tInput Data For Staff " << i + 1 << endl;
StaffData.setVAL(i);
StaffData.title[i] = "NULL";
bool strcheck = true;
int strcheck1 = 0;
while (strcheck == true)
{
cout << "\t\t\t\tTitle : "; cin >> StaffData.title[i];
stringstream ss(StaffData.title[i]);
if (ss >> strcheck1) { cout << "\t\t\t\tInputError" << endl; strcheck =
true; }
else { strcheck = false; }
}
cout << "\t\t\t\tTitle : "; cin >> StaffData.title[i];
}
for (int i = 0; i < size; i++)
{
cout << "\n\t\t\t\tOutput Data For Staff " << i + 1 << endl;
StaffData.checkO(i);
cout << "\t\t\t\tTitle : " << StaffData.title[i] << endl;
}
}
~Staff() {};
private: string title[50]; int size = 0;
}StaffData;
void call()
{
Student obj; Faculty obj2; Staff obj3;
int check = 0;
cout << "\t\t\t\tSelect The Type You want to Enter Data : \n\t\t\t\t1-Student\n\t\t\t\t2-
Faculty\n\t\t\t\t3-Staff : "; cin >> check;
switch (check) {
case 1: obj.display(); break;
case 2: obj2.display(); break;
case 3: obj3.display(); break;
default: break; }
}
int main()
{
call();
return 0;
}
Problem_02:
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
class staff
{
public:
staff() { };
void setVAL(int i)
{
this->Name[i] = "NULL";
bool strcheck = true;
int strcheck1 = 0;
while (strcheck == true)
{
cout << "\t\t\t\tName : "; cin >> this->Name[i];
stringstream ss(this->Name[i]);
if (ss >> strcheck1) { cout << "\t\t\t\tInputError" << endl;
strcheck = true; }
else { strcheck = false; }
}
this->Code[i] = "NULL";
strcheck = true;
strcheck1 = 0;
while (strcheck == true)
{
cout << "\t\t\t\tCode : "; cin >> this->Code[i];
stringstream ss(this->Code[i]);
if (ss >> strcheck1) { cout << "\t\t\t\tInputError" << endl;
strcheck = true; }
else { strcheck = false; }
}
}
string getName(int i) { return this->Name[i]; };
string getCode(int i) { return this->Code[i]; };
void checkO(int i)
{
cout << "\t\t\t\tName : " << this->getName(i) << endl;
cout << "\t\t\t\tCode : " << this->getCode(i) << endl;
}
~staff() {};
private:
}EducationOBJ;
class HighestQual:private Education
{
public:
HighestQual() {};
void display() {
cout << "\t\t\t\tEnter Number of HighestQualityTeachers you want to Enter
Data : "; cin >> size;
for (int i = 0; i < size; i++)
{
HighestQualOBJ.set(i);
HighestQualOBJ.Degree[i] = "NULL";
bool strcheck = true;
int strcheck1 = 0;
while (strcheck == true)
{
cout << "\t\t\t\tDegree : "; cin >> HighestQualOBJ.Degree[i];
stringstream ss(HighestQualOBJ.Degree[i]);
if (ss >> strcheck1) { cout << "\t\t\t\tInputError" << endl;
strcheck = true; }
else { strcheck = false; }
}
//HighestQualOBJ.set(i);
HighestQualOBJ.sports[i] = "NULL";
strcheck = true;
strcheck1 = 0;
while (strcheck == true)
{
cout << "\t\t\t\tSports : "; cin >> HighestQualOBJ.sports[i];
stringstream ss(HighestQualOBJ.sports[i]);
if (ss >> strcheck1) { cout << "\t\t\t\tInputError" << endl;
strcheck = true; }
else { strcheck = false; }
}
}
}
~HighestQual() {};
}HighestGeneralQualOBJ;
void call()
{
Teacher obj; Officer obj2; regular obj3; casual obj4;
int check = 0;
cout << "\t\t\t\tSelect The Type You want to Enter Data : \n\t\t\t\t1-
Teacher\n\t\t\t\t2-Officer\n\t\t\t\t3-RegularTypist : \n\t\t\t\t4-CasualTypist : "; cin
>> check;
switch (check) {
case 1: obj.display() ; break;
case 2: obj2.display(); break;
case 3: obj3.display(); break;
case 4 :obj4.display(); break;
default: break; }
}
int main()
{
call();
return 0;
Problem_04
#include<iostream>
#include<sstream>
#include<string>
#include<Windows.h>
using namespace std;
class ElectricCar
{
public:
ElectricCar() { Battery_Level = 30; };
void Recharge(char mode)
{
system("cls");
cout << "Battery Mode Charge : " << endl;
if (Battery_Level <= 100)
{
if (mode=='b')
{
Battery_Level--;
}
else
{
Battery_Level++;
}
}
else
{
cout << "Full Battery !.." << endl;
}
Show_Bat();
}
void Show_Bat()
{
cout << "Battery Level : \n" << Battery_Level << "%" << endl;
for (int i = 0; i < Battery_Level; i++)
{
cout << "|";
Sleep(100);
}
}
~ElectricCar(){};
private:double Fuel_Level;
};
class HybridCar :private ElectricCar, private PetrolCar
{
public:
HybridCar() { Running_Mode = 'N'; };
void LetGo()
{
cout << "Select Mode To Drive Vehicle : \n1-Enter 'b' for Battery Mode.\n2-
Enter 'f' for Fuel Mode."; cin >> call.Running_Mode;
Switch_Mode(call.Running_Mode);
}
void Switch_Mode(char mode)
{
if (mode == 'b')
{
call.Running_Mode = mode;
Run(call.Running_Mode);
}
else if (mode == 'f')
{
call.Running_Mode = mode;
Run(call.Running_Mode);
}
}
void Run(char mode)
{
if (mode == 'b')
{
call.Recharge(mode);
}
else if (mode == 'f')
{
call.Fill_Up(mode);
}
}
~HybridCar() {};
private:char Running_Mode;
}call;
void Drive()
{
HybridCar obj;
obj.LetGo();
}
int main()
{
Drive();
return 0;
}
Problem_06
#include<iostream>
#include<string>
using namespace std;
class Musicians
{
public:
Musicians() { String(); Wind(); Perc(); };
void String() {
StringV[0] = "veena"; StringV[1] = "guitar";
StringV[2] = "sitar"; StringV[3] = "sarod";
StringV[4] = "mandolin";
}
void Wind() {
WindV[0] = "flute"; WindV[1] = "clarinet sexaphone";
WindV[2] = "nadhaswaram"; WindV[3] = "piccolo";
}
void Perc() {
PercV[0] = "tabla"; PercV[1] = "mridangam";
PercV[2] = "bangos"; PercV[3] = "drums";
PercV[4] = "tambour";
}
void getString()
{
for (int i = 0; i < 5; i++)
{
cout << "StringEquipment " << i + 1 << " : " << StringV[i] << endl;
}
}
void getWind()
{
for (int i = 0; i < 4; i++)
{
cout << "WindEquipment " << i + 1 << " : " << WindV[i] << endl;
}
}
void getPerc()
{
for (int i = 0; i < 5; i++)
{
cout << "PercEquipment " << i + 1 << " : " << PercV[i] << endl;
}
}
~Musicians() {};
private:string StringV[5], WindV[4], PercV[5];
};
class TypeINS:protected Musicians
{
public:
TypeINS() { check = 'n'; };
void show()
{
cout << "Which type of instruments you want to show \na-String
Instruments\nb-Wind Instruments\nc-Percussion Instruments" << endl;
cin >> check;
switch (check) {
case 'a': getString(); break;
case 'b': getWind(); break;
case 'c': getPerc(); break;
default: break; }
}
~TypeINS() {};
private:char check;
};
int main()
{
TypeINS obj;
obj.show();
return 0;
}
Problem_07
#include<iostream>
#include<string>
using namespace std;
class PersonData
{
public:
PersonData() {};
void InputCustomerData()
{
cout << "FirstName : "; cin >> firstname;
cout << "lastName : "; cin >> lastname;
cout << "Adress : "; cin >> adress;
cout << "City : "; cin >> state;
}
void DisplayCustomerData()
{
cout << "FirstName : " << firstname << endl;
cout << "lastName : " << lastname << endl;
cout << "Adress : " << adress << endl;
cout << "City : " << state << endl;
}
~PersonData() {};
private: string firstname, lastname, adress, city, state;
};
class CustomerData:public PersonData
{
public:
CustomerData() { customernum = 0; mailinglist = true; boolcheck = 0; };
void InputCustomerData()
{
cout << "CustomerNumber : "; cin >> customernum;
cout << "You want to be in the mailing List if yes press 1 if no press 0 :
"; cin >> boolcheck;
if (boolcheck == 1) { mailinglist = true; }
else { mailinglist = false; }
}
void DisplayCustomerData()
{
cout << "CustomerNumber : " << customernum << endl;
cout << "Mailing List : ";
if (mailinglist == true) { cout << "Yes" << endl; }
else { cout << "No" << endl; }
}
~CustomerData() {};
private:int check;
};
int main()
{
BookInfo obj;
obj.call();
return 0;
}