CS304 Assignment 2 Solution and Discussion
-
Assignment No. 02
Semester: Fall 2019
CS304- Object Oriented ProgrammingTotal Marks: 20
Due Date: 28/11/2019
Uploading instructions:
• Your assignment should be in .CPP format (Any other formats like scan images, PDF, zip, doc, rar and bmp etc. will not be accepted).
• Save your assignment with your ID (e.g. bc000000000.CPP).
• No assignment will be accepted through email.Rules for Marking:
It should be clear that your assignment will not get any credit if:
• The assignment is submitted after due date.
• The submitted assignment does not open, execute or file is corrupted.
• Your assignment is copied from internet, handouts or from any other student.
(Strict disciplinary action will be taken in this case).Lectures Covered:
This assignment covers Lecture # 7-15.
Assignment
Consider the following part of class diagram which is showing composition relationship between League and Franchise classes.
Tasks to do:
You are required to write C++ code to create Franchise and League classes. Your classes should contain data members, constructors and member functions according to the given diagram. You also need to implement composition relationship between these classes.
Your output should be same as sample output.
Sample Output:
Best of luck!
NOTE: Do not put any query on MDB about this assignment, if you have any query then email at [email protected]. Furthermore, if any student found cheating from any other student or from online forums then he/she will be awarded ZERO right away and strict disciplinary action will be taken against the student.
Deadline: Your assignment must be uploaded/submitted on or before 28th November 2019.
-
Solution:
#include <iostream> using namespace std; class Franchise{ string name; string city; public: Franchise(){ name= ""; city=""; } void setname(string n){ name= n; } void setcity(string c){ city=c; } string getfname(){ return name; } string getfcity(){ return city; } }; class League{ private: string name; string year; string country; Franchise franchiseObject; public: League(string fname,string fcity,string n,string y,string c){ franchiseObject.setname(fname); franchiseObject.setcity(fcity); name=n; year=y; country=c; } void displayInfo(){ cout << "League name : " << name<<endl; cout << "League year : " << year<<endl; cout << "League country : " << country<<endl; cout << "Franchise name : " << franchiseObject.getfname()<<endl; cout << "Franchise city : " << franchiseObject.getfcity()<<endl; } }; int main() { League lg("Islamabad United","Islamabad","PSL","2020","PAKISTAN"); lg.displayInfo(); return 0; }
-
-
#include<iostream> #include<string> using namespace std; class Franchise{ private: string name; string city; public: Franchise(); void setName(string); void setCity(string); string getName(); string getCity(); }; Franchise::Franchise(){ } void Franchise::setName(string n){ name = n; } void Franchise::setCity(string c){ city = c; } string Franchise::getName(){ return name; } string Franchise::getCity(){ return city; } class league{ private: string naame; string country; int year; Franchise french; public: league(string , int, string , string , string); void displayInfo(); }; league::league(string n, int y, string c, string name, string city){ naame = n; country = c; french.setCity(city); city = french.getCity(); year = y; french.setName(name); name = french.getName(); } void league::displayInfo(){ cout"League Name:"naameendl; cout"League Year:"yearendl; cout"League County :"countryendl; cout"Franchise name:"french.getName()endl; cout"Frenchise City:"french.getCity()endl; } int main(){ league l("PSL",2020,"Pakistan","Sargodha Eagles","Sargodha"); l.displayInfo(); }
#include<iostream> #include<string> using namespace std; class Franchise{ private: string name; string city; public: Franchise(); void setName(string); void setCity(string); string getName(); string getCity(); }; Franchise::Franchise(){ } void Franchise::setName(string n){ name = n; } void Franchise::setCity(string c){ city = c; } string Franchise::getName(){ return name; } string Franchise::getCity(){ return city; } class league{ private: string naame; string country; int year; Franchise french; public: league(string , int, string , string , string); void displayInfo(); }; league::league(string n, int y, string c, string name, string city){ naame = n; country = c; french.setCity(city); city = french.getCity(); year = y; french.setName(name); name = french.getName(); } void league::displayInfo(){ cout"League Name :"naameendl; cout"League Year :"yearendl; cout"League County :"countryendl; cout"Franchise name :"french.getName()endl; cout"Frenchise City :"french.getCity()endl; }
-
-
Solution:
#include <iostream> using namespace std; class Franchise{ string name; string city; public: Franchise(){ name= ""; city=""; } void setname(string n){ name= n; } void setcity(string c){ city=c; } string getfname(){ return name; } string getfcity(){ return city; } }; class League{ private: string name; string year; string country; Franchise franchiseObject; public: League(string fname,string fcity,string n,string y,string c){ franchiseObject.setname(fname); franchiseObject.setcity(fcity); name=n; year=y; country=c; } void displayInfo(){ cout << "League name : " << name<<endl; cout << "League year : " << year<<endl; cout << "League country : " << country<<endl; cout << "Franchise name : " << franchiseObject.getfname()<<endl; cout << "Franchise city : " << franchiseObject.getfcity()<<endl; } }; int main() { League lg("Islamabad United","Islamabad","PSL","2020","PAKISTAN"); lg.displayInfo(); return 0; }