Object Oriented Programming (CC-1022)
Department of Informatics & Systems Spring’22
ASSIGNMENT # 03
Name:
Syeda ifrah zainab sheerazi
Id:
f2021105131
Section:
Y5
Object Oriented Programming (CC-1022)
Department of Informatics & Systems Spring’22
Question # 1:
Code:
#include <iostream>
#include<iostream>
using namespace std;
class Instructor
{
string lastname,firstname,officename;
public:
Instructor()
{
}
Instructor(string lname,string fname,string office)
{
lastname=lname;
firstname=fname;
officename=office;
}
Object Oriented Programming (CC-1022)
Department of Informatics & Systems Spring’22
Instructor(Instructor &ins)
{
lastname=[Link];
firstname=[Link];
officename=[Link];
}
void setname(string lname,string fname,string office)
{
lastname=lname;
firstname=fname;
officename=office;
}
void print()
{
cout<<"Last name="<<lastname<<endl;
cout<<"First name="<<firstname<<endl;
cout<<"Office name="<<officename<<endl;
cout<<"-----------------------------"<<endl;
}
~Instructor()
{
cout<<"instructor destructor executed"<<endl;
}
};
class TextBook
Object Oriented Programming (CC-1022)
Department of Informatics & Systems Spring’22
{
string title,author,publisher;
public:
TextBook()
{
}
TextBook(string t,string auth,string pub)
{
title=t;
author=auth;
publisher=pub;
}
TextBook(TextBook &ins)
{
title=[Link];
author=[Link];
publisher=[Link];
}
void settext(string t,string auth,string pub)
{
title=t;
author=auth;
publisher=pub;
}
void print()
Object Oriented Programming (CC-1022)
Department of Informatics & Systems Spring’22
{
cout<<"Title="<<title<<endl;
cout<<"Author="<<author<<endl;
cout<<"Publisher="<<publisher<<endl;
cout<<"-----------------------------"<<endl;
}
~TextBook()
{
cout<<"textbook destructor executed"<<endl;
}
};
class Course
{
string coursename;
Instructor instructor;
TextBook textBook;
public:
Course(string name,Instructor &inst,TextBook
&text):coursename(name),instructor(inst),textBook(text)
{
name=coursename;
}
void print()
{
cout<<"Course name="<<coursename<<endl;
cout<<"-----------------------------"<<endl;
Object Oriented Programming (CC-1022)
Department of Informatics & Systems Spring’22
[Link]();
[Link]();
}
~Course()
{
cout<<"course destructor executed"<<endl;
}
};
int main()
{
Instructor *i1=new Instructor("Kramer","Shaw","RH3010");
// [Link]("Kramer","Shaw","RH3010");
TextBook *t1=new TextBook("Starting with c++","Gradius","Addision");
// [Link]("Starting with c++","Gradius","Addision");
Course c1("Intro to computer science",*i1,*t1);
[Link]();
delete i1;
return 0;
}
Object Oriented Programming (CC-1022)
Department of Informatics & Systems Spring’22
Output screenshot: