Docsity

Object-Oriented Programming Assignment Solutions in C++ for COMSATS University Islamabad, Summaries of Object Oriented Programming

Partial preview of the text

Download Object-Oriented Programming Assignment Solutions in C++ for COMSATS University Islamabad and more Summaries Object Oriented Programming in PDF only on Docsity!

Assignment No. 0 3

Object Oriented Programming

Student Name Nabeel Asghar

Registration Number

FA20-BEE- 012

Lecturer: Dr. Ajmal Khan

COMSATS UNIVERSITY ISLAMABAD

ATTOCK CAMPUS

Task#01:

Code:

#include #include<string.h> using namespace std; //Publication Class class Publication{ protected: string title; float price; public: Publication(string x="NULL",float y=0){ title=x; price=y; } void getdata(){ cout<<"\nEnter title: ";cin>>title; cout<<"Enter price: ";cin>>price; } void putdata(){ cout<<"Title: "<<title<<endl; cout<<"Price: "<<price<<endl; } };

void getdata(){ Publication::getdata(); cout<<"Enter playtime: ";cin>>time; } void putdata(){ Publication::putdata(); cout<<"Playtime: "<<time<<endl<<endl; } }; //Main Function int main(){ Book b1; Tape t1; t1.getdata(); b1.getdata(); t1.putdata(); b1.putdata(); }

Task#02:

Code:

#include #include<string.h> using namespace std; //Sales Class class Sales{ protected: float record[3];

public: void getdata(){ cout<<"Enter Sales of last 3 months: "; cin>>record[0]>>record[1]>>record[2]; } Void putdata(){ cout<<"First Month Sales: "<<record[0]<<endl; cout<<"Second Month Sales: "<<record[1]<<endl; cout<<"Third Month Sales: "<<record[2]<<endl<<endl; } }; //Publication Class class Publication{ protected: string title; float price; public: Publication(string x="NULL",float y=0){ title=x; price=y; } void getdata(){ cout<<"Enter title: ";cin>>title; cout<<"Enter price: ";cin>>price; }

//Tape Class class Tape: public Publication,public Sales{ private: float time; public: Tape(string x="NULL",float y=0,float z=0): Publication(x,y){ time=z; } void getdata(){ Publication::getdata(); cout<<"Enter playtime: ";cin>>time; Sales::setdata(); } void putdata(){ Publication::putdata(); cout<<"Playtime: "<<time<<endl; Sales::putdata(); } }; //Main Function int main(){ Book b1; Tape t1; t1.getdata(); b1.getdata(); b1.putdata();

t1.putdata(); }

Task#03:

Code:

#include #include using namespace std; //Date Structure struct Date{ int day; int month; int year; }; //Employee Class class Employee{ protected: string name; int number; Date hire; public: Employee(string x="NULL",int y=0){ name=x; number=y;} void get_data(){ cout<<"Enter Name: ";cin>>name;

Employee::get_data(); cout<<"Enter Shift: ";cin>>shift; cout<<"Enter Hourly Rate: ";cin>>rate; } float Calculate_salary(){ int hours;float salary; cout<<"\nEnter Hour Employee Worked: ";cin>>hours; if(shift==1){ salary=ratehours; return salary; } else if(shift==2){ salary=(rate+rate/2)hours; return salary; } } void display(){ int salary=Calculate_salary(); cout<<"Salary: "<<salary<<endl<<endl; }}; //Main Function int main(){ ProductionWorker person[5]; for(int i=0;i<5;i++){

person[i].set_data(); } for(int i=0;i<5;i++){ person[i].display(); } }

Task#04:

Code:

#include #include using namespace std; //Date Structure struct Date{ int day; int month; int year; }; //Employee Class class Employee{ protected: string name; int number; Date hire; public: Employee(string x="NULL",int y=0){ name=x;

annualSalary=z; } float Net_salary(){ int salary; return salary=annualSalary+bonus; } void Production_Goals(){ int goals; cout<<"Enter No. of goals: "; cin>>goals; if(goals>=15){ bonus=annualSalary((annualSalary/100)15); } else if(goals>=30){ bonus=annualSalary((annualSalary/100)30); } else{ bonus=0; } } }; //Main Function int main(){ ShiftSupervisor person1("Nabeel",12,2000); ShiftSupervisor person2("Adeel",13,3000),person3("Aqeel",14,4000);

ShiftSupervisor person4("Saad",15,5000),person5("Hassan",16,60000); //Bonus Calculation person1.Production_Goals(); person2.Production_Goals(); person3.Production_Goals(); person4.Production_Goals(); person5.Production_Goals(); //Displaying all data cout<<"Salary of person 1: "<<person1.Net_salary()<<endl; cout<<"Salary of person 2: "<<person2.Net_salary()<<endl; cout<<"Salary of person 3: "<<person3.Net_salary()<<endl; cout<<"Salary of person 4: "<<person4.Net_salary()<<endl; cout<<"Salary of person 5: "<<person5.Net_salary()<<endl; }