c++ oop programming

Thread Starter

mike9407

Joined Jan 4, 2016
3
Code:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//Attractionlass--------------------------------------------------------->Start
class Attraction
{
    protected:
    int id;
    string name;
    int typeID;
    public:
    Attraction(int id,string name,int typeID):id(id),name(name),typeID(typeID){}
    void setId(int id){this->id=id;}
    void setName(string name){this->name=name;}
    void setTypeID(int typeID){this->typeID=typeID;}
    int getTypeID(){return typeID;}
    int getId(){return id;}
    string getName(){return name;}
    virtual void display() = 0;


};

//Attraction Class------------------------------------------------------->End
//Sport Class------------------------------------------------------------>Start
class Sport :public Attraction
{
private:
    int ageLimit;
public:
    void SetAgeLimit(int age);
    int GetAgeLimit();

};
void Sport::SetAgeLimit(int age)
{
    this->ageLimit = age;
}
int Sport::GetAgeLimit()
{
    return ageLimit;
}
//Sport Class------------------------------------------------------------>End
//Culture Class---------------------------------------------------------->Start
class Culture :public Attraction
{
private:
    double EntranceFee;
public:
    Culture(int id,string name,int typeID,double EntranceFee):Attraction(id,name,typeID),EntranceFee(EntranceFee){}
    void SetEntryFee(double _price);
    double GetEntryFee();
};
void Culture::SetEntryFee(double _price)
{
    EntranceFee = _price;
}
double Culture::GetEntryFee()
{
    return EntranceFee;
}
//Culture Class----------------------------------------------------------->End
//Shopping Class---------------------------------------------------------->Start
class Shopping :public Attraction
{
private:
    // vector<string*>malls;
    // vector<string*>markets;
    string areas;
    int businesshours;
    int contact;

public:
    Shopping(int id,string name,int typeID,string areas,int businesshours, int contact)
    :Attraction(id,name,typeID),areas(areas),businesshours(businesshours),contact(contact){
        cout << "Shopping class created";
    }

    void display() {
        cout << "\n\n\nShopping name : " << name << endl;
        cout << "Shopping TYPEID : " << typeID << endl;
        cout << "Areas : " << areas << endl;
        cout << "Business hours : " << businesshours << endl;
        cout << "Contact : " << contact << endl;
    }
};

//Shopping Class---------------------------------------------------------->End
//City Class-------------------------------------------------------------->Start
class City
{
private:
    int id;
    string name;
    int populations;
    int nooftourist;
    vector<Attraction*>attractions;
public:
    City(int id,string name,int populations,int nooftourist):id(id),name(name),populations(populations),nooftourist(nooftourist){}
    void setId(int _id);
    void setName(string _name);
    int getId();
    string getName();
    void display(){}
    vector<Attraction*>&getAttractions() { return attractions;}

};
void City::setId(int _id)
{
    id = _id;
}
void City::setName(string _name)
{
    name = _name;
}

int City::getId()
{
    return id;
}
string City::getName()
{
    return name;

}
vector<City> cities;

City* citySelection(bool& hasSelectedCity, bool& toLoop)
{
    ///do bubble sort
    for (int i = 0 ; i < cities.size() - 1 ; i++)
    {
        for (int j = 0 ; j < cities.size() - 1 ; j++)
        {
            string val1 = cities.at(j).getName();
            string val2 = cities.at(j+1).getName();
            if ( val1 > val2 )
            {
                string temp = val1;
                cities.at(j).setName(val2);
                cities.at(j+1).setName(temp);
            }
        }
    }


    City* targetCity = nullptr;
    for(int i = 0; i < (int)cities.size(); i ++)
    {
        cities.at(i).display();
    }
    cout << "Please select the city by entering the name" << endl;
    cout << "To stop the program enter \"break\"" << endl;
    string input;
    getline(cin, input);
    if(input == "break") toLoop = false;
    for(int i = 0; i < (int)cities.size(); i ++)
    {
        City tempCity = cities.at(i);
        if(tempCity.getName() == input)
        {
            targetCity = &cities.at(i);
            break;
        }
    }
    if(targetCity!=nullptr)
    {
        hasSelectedCity = true;
    }
    return targetCity;
}

void askcity(){
    vector<City*>cities;
    cities.push_back(new City(111,"Kuala Lumpur",80000,4000));
    cities.push_back(new City(112,"Malacca City",30000,1500));
    cities.push_back(new City(113,"Ipoh",70000,3500));

    for (int i = 0; i < cities.size(); i++)
    {
        cout<<i+1<<"."<<cities[I]->getName()<<endl;
    }
    for (int i = 0; i < cities.size(); i++)
    {
        delete cities[I];
    }
}

void asktype(){

    int selection;
    cin>>selection;

    if(selection==1||selection==2||selection==3)
    {
        cout<<1<<"."<<"Sport"<<endl;
        cout<<2<<"."<<"Culture"<<endl;
        cout<<3<<"."<<"Shopping"<<endl;
        cout<<4<<"."<<"All"<<endl;

    }
}

//City Class-------------------------------------------------------------->End
int main()

{
    askcity();
    asktype();
    vector<Attraction*>attractions;
    attractions.push_back(new Attraction(11,"Pavillion",3));
    attractions.push_back(new Attraction(12,"Midvalley",3));
    attractions.push_back(new Attraction(13,"Times Square",3));
    attractions.push_back(new Attraction(14,"Ipoh Parade",3));
    attractions.push_back(new Attraction(15,"Kinta City",3));
    attractions.push_back(new Attraction(16,"Aeon Station 18",3));
    attractions.push_back(new Attraction(17,"Dataran Pahlawan Melaka Megamall",3));
    attractions.push_back(new Attraction(18,"Jusco Melaka Shopping Centre",3));
    attractions.push_back(new Attraction(19,"Mahkota Parade",3));
    attractions.push_back(new Attraction(20,"Petronas Tower",2));
    attractions.push_back(new Attraction(21,"Menara KL",2));
    attractions.push_back(new Attraction(22,"China Town",2));
    attractions.push_back(new Attraction(23,"The Baba Nyonyas",2));
    attractions.push_back(new Attraction(24,"The Portuguese",2));
    attractions.push_back(new Attraction(25,"A¡¦Famosa",2));
    attractions.push_back(new Attraction(26,"Perak Tong",2));
    attractions.push_back(new Attraction(27,"Sam Poh Tong Temple",2));
    attractions.push_back(new Attraction(28,"The Ipoh Heritage Trail",2));
    attractions.push_back(new Attraction(29,"Camp5 Climbing Gym",1));
    attractions.push_back(new Attraction(30,"First In Malaysia GAC Adventure Consultant Sdn Bhd",1));
    attractions.push_back(new Attraction(31,"Extreme Park, Sunway Lagoon",1));
    attractions.push_back(new Attraction(32,"Tiara Golf melaka",1));
    attractions.push_back(new Attraction(33,"Malacca International Motorsport Circuit",1));
    attractions.push_back(new Attraction(34,"Tun Fatimah Stadium",1));



    int input;
    cin>>input;
    if(input==4)
    {
        for(int i=0;i<attractions.size();i++)
            cout<<i+1<<"."<<attractions[I]->getName()<<endl;

    }

}
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:

spinnaker

Joined Oct 29, 2009
7,830
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?
 

WBahn

Joined Mar 31, 2012
29,976
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.
 
Top