0% found this document useful (0 votes)
5 views

Program 1

Uploaded by

amuneebfb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Program 1

Uploaded by

amuneebfb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Program.

1:
#include <iostream>
#include <string>
using namespace std;

class Media {
protected:
string title;
int publicationYear;

public:
Media(const string& title, int publicationYear)
: title(title), publicationYear(publicationYear) {}

virtual void display() const {


cout << "Title: " << title << ", Publication Year: " << publicationYear << endl;
}
};

class PrintedMedia : public Media {


protected:
int pageCount;

public:
PrintedMedia(const string& title, int publicationYear, int pageCount)
: Media(title, publicationYear), pageCount(pageCount) {}

void display() const override {


Media::display();
cout << "Page Count: " << pageCount << endl;
}
};

class RecordedMedia : public Media {


protected:
double duration;

public:
RecordedMedia(const string& title, int publicationYear, double duration)
: Media(title, publicationYear), duration(duration) {}

void display() const override {


Media::display();
cout << "Duration: " << duration << " minutes" << endl;
}
};

class Book : public PrintedMedia {


private:
string author;
string genre;

public:
Book(const string& title, int publicationYear, int pageCount, const string&
author, const string& genre)
: PrintedMedia(title, publicationYear, pageCount), author(author),
genre(genre) {}
void display() const override {
PrintedMedia::display();
cout << "Author: " << author << ", Genre: " << genre << endl;
}
};

class Magazine : public PrintedMedia {


private:
int issueNumber;
string category;

public:
Magazine(const string& title, int publicationYear, int pageCount, int
issueNumber, const string& category)
: PrintedMedia(title, publicationYear, pageCount),
issueNumber(issueNumber), category(category) {}

void display() const override {


PrintedMedia::display();
cout << "Issue Number: " << issueNumber << ", Category: " << category <<
endl;
}
};

class Audio : public RecordedMedia {


private:
string artist;
string genre;
public:
Audio(const string& title, int publicationYear, double duration, const string&
artist, const string& genre)
: RecordedMedia(title, publicationYear, duration), artist(artist), genre(genre)
{}

void display() const override {


RecordedMedia::display();
cout << "Artist: " << artist << ", Genre: " << genre << endl;
}
};

class Video : public RecordedMedia {


private:
string director;
string genre;

public:
Video(const string& title, int publicationYear, double duration, const string&
director, const string& genre)
: RecordedMedia(title, publicationYear, duration), director(director),
genre(genre) {}

void display() const override {


RecordedMedia::display();
cout << "Director: " << director << ", Genre: " << genre << endl;
}
};
int main() {
Book book("To Kill a Mockingbird", 1960, 281, "Harper Lee", "Fiction");
Magazine magazine("National Geographic", 2023, 84, 5, "Nature");
Audio audio("Bohemian Rhapsody", 1975, 5.55, "Queen", "Rock");
Video video("The Shawshank Redemption", 1994, 142.0, "Frank Darabont",
"Drama");

book.display();
cout << endl;
magazine.display();
cout << endl;
audio.display();
cout << endl;
video.display();

return 0;
}

Program.2:
#include <iostream>
#include <string>
using namespace std;

class Person {
protected:
string name;
int ID;

public:
Person(const string& name, int ID) : name(name), ID(ID) {}

virtual void display() const {


cout << "Name: " << name << ", ID: " << ID;
}
};

class Committees : virtual public Person {


protected:
string committeeName;
string role;

public:
Committees(const string& name, int ID, const string& committeeName, const
string& role)
: Person(name, ID), committeeName(committeeName), role(role) {}

void display() const override {


Person::display();
cout << ", Committee: " << committeeName << ", Role: " << role;
}
};

class Faculty : virtual public Person {


protected:
string department;
string researchArea;

public:
Faculty(const string& name, int ID, const string& department, const string&
researchArea)
: Person(name, ID), department(department), researchArea(researchArea) {}

void display() const override {


Person::display();
cout << ", Department: " << department << ", Research Area: " <<
researchArea;
}
};

class Staff : virtual public Person {


protected:
string department;
string jobTitle;

public:
Staff(const string& name, int ID, const string& department, const string&
jobTitle)
: Person(name, ID), department(department), jobTitle(jobTitle) {}

void display() const override {


Person::display();
cout << ", Department: " << department << ", Job Title: " << jobTitle;
}
};

class FacultyCommitteeMember : public Faculty, public Committees {


public:
FacultyCommitteeMember(const string& name, int ID, const string&
department, const string& researchArea, const string& committeeName, const
string& role)
: Person(name, ID), Faculty(name, ID, department, researchArea),
Committees(name, ID, committeeName, role) {}

void display() const override {


Person::display();
cout << ", Faculty - ";
Faculty::display();
cout << ", Committee: " << committeeName << ", Role: " << role;
}
};

class StaffCommitteeMember : public Staff, public Committees {


public:
StaffCommitteeMember(const string& name, int ID, const string& department,
const string& jobTitle, const string& committeeName, const string& role)
: Person(name, ID), Staff(name, ID, department, jobTitle), Committees(name,
ID, committeeName, role) {}
void display() const override {
Person::display();
cout << ", Staff - ";
Staff::display();
cout << ", Committee: " << committeeName << ", Role: " << role;
}
};

int main() {
FacultyCommitteeMember facultyMember("John Doe", 1001, "Computer
Science", "AI", "Research Committee", "Chair");
StaffCommitteeMember staffMember("Jane Smith", 2001, "Administration", "HR
Manager", "Staff Committee", "Member");

facultyMember.display();
cout << endl;
staffMember.display();
cout << endl;

return 0;
}

You might also like