c++ oop programming

Discussion in 'Homework Help' started by mike9407, Jan 4, 2016.

  1. mike9407

    Thread Starter New Member

    Jan 4, 2016
    3
    0
    Code (C):
    1.  
    2. #include <iostream>
    3. #include <vector>
    4. #include <string>
    5. using namespace std;
    6. //Attractionlass--------------------------------------------------------->Start
    7. class Attraction
    8. {
    9.     protected:
    10.     int id;
    11.     string name;
    12.     int typeID;
    13.     public:
    14.     Attraction(int id,string name,int typeID):id(id),name(name),typeID(typeID){}
    15.     void setId(int id){this->id=id;}
    16.     void setName(string name){this->name=name;}
    17.     void setTypeID(int typeID){this->typeID=typeID;}
    18.     int getTypeID(){return typeID;}
    19.     int getId(){return id;}
    20.     string getName(){return name;}
    21.     virtual void display() = 0;
    22.  
    23.  
    24. };
    25.  
    26. //Attraction Class------------------------------------------------------->End
    27. //Sport Class------------------------------------------------------------>Start
    28. class Sport :public Attraction
    29. {
    30. private:
    31.     int ageLimit;
    32. public:
    33.     void SetAgeLimit(int age);
    34.     int GetAgeLimit();
    35.  
    36. };
    37. void Sport::SetAgeLimit(int age)
    38. {
    39.     this->ageLimit = age;
    40. }
    41. int Sport::GetAgeLimit()
    42. {
    43.     return ageLimit;
    44. }
    45. //Sport Class------------------------------------------------------------>End
    46. //Culture Class---------------------------------------------------------->Start
    47. class Culture :public Attraction
    48. {
    49. private:
    50.     double EntranceFee;
    51. public:
    52.     Culture(int id,string name,int typeID,double EntranceFee):Attraction(id,name,typeID),EntranceFee(EntranceFee){}
    53.     void SetEntryFee(double _price);
    54.     double GetEntryFee();
    55. };
    56. void Culture::SetEntryFee(double _price)
    57. {
    58.     EntranceFee = _price;
    59. }
    60. double Culture::GetEntryFee()
    61. {
    62.     return EntranceFee;
    63. }
    64. //Culture Class----------------------------------------------------------->End
    65. //Shopping Class---------------------------------------------------------->Start
    66. class Shopping :public Attraction
    67. {
    68. private:
    69.     // vector<string*>malls;
    70.     // vector<string*>markets;
    71.     string areas;
    72.     int businesshours;
    73.     int contact;
    74.  
    75. public:
    76.     Shopping(int id,string name,int typeID,string areas,int businesshours, int contact)
    77.     :Attraction(id,name,typeID),areas(areas),businesshours(businesshours),contact(contact){
    78.         cout << "Shopping class created";
    79.     }
    80.  
    81.     void display() {
    82.         cout << "\n\n\nShopping name : " << name << endl;
    83.         cout << "Shopping TYPEID : " << typeID << endl;
    84.         cout << "Areas : " << areas << endl;
    85.         cout << "Business hours : " << businesshours << endl;
    86.         cout << "Contact : " << contact << endl;
    87.     }
    88. };
    89.  
    90. //Shopping Class---------------------------------------------------------->End
    91. //City Class-------------------------------------------------------------->Start
    92. class City
    93. {
    94. private:
    95.     int id;
    96.     string name;
    97.     int populations;
    98.     int nooftourist;
    99.     vector<Attraction*>attractions;
    100. public:
    101.     City(int id,string name,int populations,int nooftourist):id(id),name(name),populations(populations),nooftourist(nooftourist){}
    102.     void setId(int _id);
    103.     void setName(string _name);
    104.     int getId();
    105.     string getName();
    106.     void display(){}
    107.     vector<Attraction*>&getAttractions() { return attractions;}
    108.  
    109. };
    110. void City::setId(int _id)
    111. {
    112.     id = _id;
    113. }
    114. void City::setName(string _name)
    115. {
    116.     name = _name;
    117. }
    118.  
    119. int City::getId()
    120. {
    121.     return id;
    122. }
    123. string City::getName()
    124. {
    125.     return name;
    126.  
    127. }
    128. vector<City> cities;
    129.  
    130. City* citySelection(bool& hasSelectedCity, bool& toLoop)
    131. {
    132.     ///do bubble sort
    133.     for (int i = 0 ; i < cities.size() - 1 ; i++)
    134.     {
    135.         for (int j = 0 ; j < cities.size() - 1 ; j++)
    136.         {
    137.             string val1 = cities.at(j).getName();
    138.             string val2 = cities.at(j+1).getName();
    139.             if ( val1 > val2 )
    140.             {
    141.                 string temp = val1;
    142.                 cities.at(j).setName(val2);
    143.                 cities.at(j+1).setName(temp);
    144.             }
    145.         }
    146.     }
    147.  
    148.  
    149.     City* targetCity = nullptr;
    150.     for(int i = 0; i < (int)cities.size(); i ++)
    151.     {
    152.         cities.at(i).display();
    153.     }
    154.     cout << "Please select the city by entering the name" << endl;
    155.     cout << "To stop the program enter \"break\"" << endl;
    156.     string input;
    157.     getline(cin, input);
    158.     if(input == "break") toLoop = false;
    159.     for(int i = 0; i < (int)cities.size(); i ++)
    160.     {
    161.         City tempCity = cities.at(i);
    162.         if(tempCity.getName() == input)
    163.         {
    164.             targetCity = &cities.at(i);
    165.             break;
    166.         }
    167.     }
    168.     if(targetCity!=nullptr)
    169.     {
    170.         hasSelectedCity = true;
    171.     }
    172.     return targetCity;
    173. }
    174.  
    175. void askcity(){
    176.     vector<City*>cities;
    177.     cities.push_back(new City(111,"Kuala Lumpur",80000,4000));
    178.     cities.push_back(new City(112,"Malacca City",30000,1500));
    179.     cities.push_back(new City(113,"Ipoh",70000,3500));
    180.  
    181.     for (int i = 0; i < cities.size(); i++)
    182.     {
    183.         cout<<i+1<<"."<<cities[I]->getName()<<endl;
    184.     }
    185.     for (int i = 0; i < cities.size(); i++)
    186.     {
    187.         delete cities[I];
    188.     }
    189. }
    190.  
    191. void asktype(){
    192.  
    193.     int selection;
    194.     cin>>selection;
    195.  
    196.     if(selection==1||selection==2||selection==3)
    197.     {
    198.         cout<<1<<"."<<"Sport"<<endl;
    199.         cout<<2<<"."<<"Culture"<<endl;
    200.         cout<<3<<"."<<"Shopping"<<endl;
    201.         cout<<4<<"."<<"All"<<endl;
    202.  
    203.     }
    204. }
    205.  
    206. //City Class-------------------------------------------------------------->End
    207. int main()
    208.  
    209. {
    210.     askcity();
    211.     asktype();
    212.     vector<Attraction*>attractions;
    213.     attractions.push_back(new Attraction(11,"Pavillion",3));
    214.     attractions.push_back(new Attraction(12,"Midvalley",3));
    215.     attractions.push_back(new Attraction(13,"Times Square",3));
    216.     attractions.push_back(new Attraction(14,"Ipoh Parade",3));
    217.     attractions.push_back(new Attraction(15,"Kinta City",3));
    218.     attractions.push_back(new Attraction(16,"Aeon Station 18",3));
    219.     attractions.push_back(new Attraction(17,"Dataran Pahlawan Melaka Megamall",3));
    220.     attractions.push_back(new Attraction(18,"Jusco Melaka Shopping Centre",3));
    221.     attractions.push_back(new Attraction(19,"Mahkota Parade",3));
    222.     attractions.push_back(new Attraction(20,"Petronas Tower",2));
    223.     attractions.push_back(new Attraction(21,"Menara KL",2));
    224.     attractions.push_back(new Attraction(22,"China Town",2));
    225.     attractions.push_back(new Attraction(23,"The Baba Nyonyas",2));
    226.     attractions.push_back(new Attraction(24,"The Portuguese",2));
    227.     attractions.push_back(new Attraction(25,"A¡¦Famosa",2));
    228.     attractions.push_back(new Attraction(26,"Perak Tong",2));
    229.     attractions.push_back(new Attraction(27,"Sam Poh Tong Temple",2));
    230.     attractions.push_back(new Attraction(28,"The Ipoh Heritage Trail",2));
    231.     attractions.push_back(new Attraction(29,"Camp5 Climbing Gym",1));
    232.     attractions.push_back(new Attraction(30,"First In Malaysia GAC Adventure Consultant Sdn Bhd",1));
    233.     attractions.push_back(new Attraction(31,"Extreme Park, Sunway Lagoon",1));
    234.     attractions.push_back(new Attraction(32,"Tiara Golf melaka",1));
    235.     attractions.push_back(new Attraction(33,"Malacca International Motorsport Circuit",1));
    236.     attractions.push_back(new Attraction(34,"Tun Fatimah Stadium",1));
    237.  
    238.  
    239.  
    240.     int input;
    241.     cin>>input;
    242.     if(input==4)
    243.     {
    244.         for(int i=0;i<attractions.size();i++)
    245.             cout<<i+1<<"."<<attractions[I]->getName()<<endl;
    246.  
    247.     }
    248.  
    249. }
    250.  
    the top is my source code,

    User Requirements
    - A city has many attractions and the attractions can be classified into various types. To view the detailed information of an attraction, a tourist will first choose a city from a list of cities displayed in alphabetical order, the type of attraction from a list of attraction types and then the attraction itself. He can also choose a city and then choose from a list of all attractions in the city without choosing a type of attraction. The maximum number of attractions per city must not be fixed in the system.
    - The user interface has to be user-friendly so that users can navigate with ease. Design a console-based user interface for the system.


    how do i proceed to next in my main function
    can u guys help me?

    Mod edit: Code tags, moved to homework help
     
    Last edited by a moderator: Jan 4, 2016
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,884
    1,005
    This looks like homework that me. It is for you to do. And you are going to have to put in a whole lot more effort than asking how to proceed if you want any help at all. What are your specific questions?
     
  3. WBahn

    Moderator

    Mar 31, 2012
    17,743
    4,795
    Do you really expect people to review 250+ lines of unformatted, uncommented code (in terms of having any meaningful comments) and to then tell you how to proceed?

    State a specific issue you are having, what you have tried to do to solve it, and what problem your approach is having.
     
Loading...