Untitled
unknown
plain_text
4 years ago
4.2 kB
8
Indexable
Program to copy #include <iostream> using namespace std; //Person class class Person { private: //private attributes string lastname; string firstname; public: //constructor Person(string lname, string fname) { lastname = lname; firstname = fname; } //display the last name and first name void display() { cout<<"Name: "<<lastname<<" "<<firstname<<endl; } }; //Customer class class Customer:public Person { private: //private attribute int numidentity; public: //constructor Customer(string lname, string fname, int icardNumber):Person(lname, fname) { numidentity = icardNumber; } //display the last name, first name and identity card number void display() { Person::display(); cout<<"Identity card Number: "<<numidentity<<endl; } }; //Owner class class Owner:public Person { private: //private attributes string nomclub; string adrclub; public: //constructor Owner(string lname, string fname, string nclub, string aclub):Person(lname, fname) { nomclub = nclub; adrclub = aclub; } //display the last name, first name, name of video club and address of club void display() { Person::display(); cout<<"Name of video club: "<<nomclub<<endl; cout<<"Address of video club: "<<adrclub<<endl; } }; //Date class class Date { private: //private attributes int day; int month; int year; public: //constructor Date(int dd=1, int mm=1, int yy=1900):day(dd), month(mm), year(yy){} //overload << to print date information friend ostream& operator<<(ostream&out, const Date&dt) { out<<"Date: "<<dt.day<<"-"<<dt.month<<"-"<<dt.year<<endl; return out; } }; //Movie class class Movie { private: //private attributes string title; string genre; string identifier; Date datetrans; public: //constructor Movie(string t="", string g="", string i="", Date d=0) { title = t; genre = g; identifier = i; datetrans = d; } //overload << operator that display the characteristics of a movie friend ostream& operator<<(ostream&out, const Movie&mov) { out<<"Movie title: "<<mov.title<<endl; out<<"Genre: "<<mov.genre<<endl; out<<"Identifier: "<<mov.identifier<<endl; out<<"Date of first transmission: "<<mov.datetrans<<endl; } //method returns the movie's title string getTitle() { return title; } }; //Organize class class Organize { private: //private attributes Movie *tabMovie; int nbMovie; int maxMovie; public: //constructor Organize(int max=10) { maxMovie = max; nbMovie = 0; tabMovie = new Movie[maxMovie]; } //destructor ~Organize() { delete[]tabMovie; } //Add Movies void add(Movie f) { if(nbMovie==maxMovie) { cout<<"Error: The table is full!"<<endl; return; } tabMovie[nbMovie] = f; nbMovie++; } //overload the operator << friend ostream& operator<<(ostream&out, const Organize&org) { for(int i=0; i<org.nbMovie; i++) { out<<org.tabMovie[i]; } return out; } //overload operator += able to add the right operand to the left Organize& operator +=(Movie f) { if(nbMovie==maxMovie) { cout<<"Error: The table is full!"<<endl; } else { tabMovie[nbMovie] = f; nbMovie++; } return *this; } void search_Movie(string title) { cout<<"Searching..."<<endl; for(int i=0; i<nbMovie; i++) { if(tabMovie[i].getTitle() == title) { cout<<tabMovie[i]<<endl; return; } } cout<<"Error: not found!"<<endl; } }; //main function int main() { //create an object of Person Person p("Doe", "John"); //display the name of the person cout<<"Person information: "<<endl; p.display(); cout<<endl; //create an object of Customer Customer c("Doe", "John", 2137); //display the last name, first name and identity card number cout<<"Customer information: "<<endl; c.display(); cout<<endl; //create an object of Owner Owner own("Doe", "John", "Recreation club", "Agra"); //display the last name, first name, name of video club and address of club cout<<"Owner information: "<<endl; own.display(); cout<<endl; //create an object of Date Date dt(21, 7, 2006); //display the date cout<<"Date information: "<<endl; cout<<dt<<endl; //create an object of Movie Movie mov("The Killer", "Action", "CBFC:A", dt); //display the Movie information cout<<"Movie information: "<<endl; cout<<mov; //create an object of Organize Organize org; //Add movie org.add(mov); //display the Organize information cout<<"Organize information: "<<endl; cout<<org; org.search_Movie("The Killer"); return 0; }
Editor is loading...