错误:预期';'在'{'之前 [英] Error: expected ';' before '{' token

查看:70
本文介绍了错误:预期';'在'{'之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <iostream>
#include <vector>
using namespace std;

int opt_user(){ /*Function to let user choose whether they want to list one or all type of attractions*/

    int input;

    cout<<"\n";
    cout<<"1.List of the all attractions \n";
    cout<<"2.Sports \n";
    cout<<"3.Culture \n";
    cout<<"4.Shopping \n";
    cout<<"Choose the attraction that you want! Enter based on the \n";
    cout<<"number that have listed according to the attraction: \n";
    cin>>input; /*input will be return back to main function*/
    return input;

}

class City{

      string name;
      int id;

public:

      City(int id=0, string name="NULL"):id(id), name(name){}
      void setID(); /*Let user choose city and set id and name*/
      string getName(); /*Return City name*/
      int getID();
};

int City::getID(){

    return id;
}

string City::getName(){

       return name;

}

void City::setID(){ /*A list of cities*/

     cout<<"The list of Cities according to alphabetical form: /n";

     vector<city>city;
     city.push_back(City(01, "Georgetown"));
     city.push_back(City(02, "Kuala Lumpur"));
     city.push_back(City(03, "Malacca"));

     for (int i=0; i<city.size();>     {
          cout<<i+1<<city[i].getName()<<endl; /*Display all the cities*/
     }

     cout<<"Choose a City that you want! Enter based on the number \n";
     cout<<"that have listed according to the City: \n"; /*Let users choose the desired city*/

     int x;
     string selectCity;
     cin>>x;
     this->id = x;
     selectCity = city[x-1].getName(); // User's input will be referred as the city's ID
     this->name = selectCity; /*Set city's name based on user's choice*/

}

class Attraction{

    int typeID;
    int Att_id;

    protected :

               string Att_name;

    public :

               Attraction(int typeID = 0, int Att_id = 0, string Att_name = "NULL"): Att_id(Att_id), typeID(typeID), Att_name(Att_name){}
               string get_attName();
               virtual int display(int id);
};

int Attraction::display(int id){

    cout<<"These are the list of attractions: \n";

    if(id == 1){

        vector<attraction> Georgetown_Att; /*Vector to store all attractions in georgetown*/
        Georgetown_Att.push_back(Attraction(1, 01, "Free Fall & Zip Lining"));
        Georgetown_Att.push_back(Attraction(2, 01, "Tree Swings & Water Park"));
        Georgetown_Att.push_back(Attraction(3, 02, "Khoo Kongsi Temple"));
        Georgetown_Att.push_back(Attraction(4, 02, "Sri Mariamman Temple"));
        Georgetown_Att.push_back(Attraction(5, 02, "St. George's Church"));
        Georgetown_Att.push_back(Attraction(6, 02, "Kapitan Keling Mosque"));
        Georgetown_Att.push_back(Attraction(7, 03, "Prangin Mall"));
        Georgetown_Att.push_back(Attraction(8, 03, "1st Avenue Mall"));

        for(int i = 0; i < Georgetown_Att.size(); i++)
        {
            cout << i+1 << ". " << Georgetown_Att[i].get_attName() << endl;
        }

        int input;
        cout<<"Choose the place you want in the form of the decimal \n";
        cout<<"number that have listed above: \n";
        cin>> input;
        cout << "The place you have choose is: " << Georgetown_Att[input-1].get_attName();  /*Display user's chosen attraction, [ans-1] because vector starts from 0*/
        return input;

    }

    else if(id == 2)
    {
        vector<attraction> KualaLumpur_Att; /*Vector to store all attractions in KL*/
        KualaLumpur_Att.push_back(Attraction(1, 01, "Bukit Jalil Golf"));
        KualaLumpur_Att.push_back(Attraction(2, 01, "Bukit Tabur"));
        KualaLumpur_Att.push_back(Attraction(3, 02, "Chan See Shu Yuen temple"));
        KualaLumpur_Att.push_back(Attraction(4, 02, "Batu Caves"));
        KualaLumpur_Att.push_back(Attraction(5, 02, "Cathedral of St.Mary"));
        KualaLumpur_Att.push_back(Attraction(6, 02, "Masjid Negara Mosque"));
        KualaLumpur_Att.push_back(Attraction(7, 03, "Berjaya Times Square"));
        KualaLumpur_Att.push_back(Attraction(8, 03, "Pavilion Shopping Mall"));

        for(int i = 0; i < KualaLumpur_Att.size(); i++){    /*To display all the attractions in KL*/

            cout << i+1 << "." << KualaLumpur_Att[i].get_attName() << endl;

        }

        int input;
        cout<<"Choose the place you want in the form of the decimal \n";
        cout<<"number that have listed above: \n";
        cin>> input;
        cout << "The place you have choose is: " << KualaLumpur_Att[input-1].get_attName();    /*Display user's choice of attraction,[ans-1] because vector starts from 0*/
        return input;
    }

    else
    {
        vector<attraction> Malacca_Att;
        Malacca_Att.push_back(Attraction(1, 01, "Tiara Melaka Golf & Country Club"));
        Malacca_Att.push_back(Attraction(2, 01, "Wonderland Theme Park "));
        Malacca_Att.push_back(Attraction(3, 02, "Cheng Hoon Teng Temple"));
        Malacca_Att.push_back(Attraction(4, 02, "Sri Poyyatha Vinayagar Moorthi"));
        Malacca_Att.push_back(Attraction(5, 02, "St. Francis Xavier's Church"));
        Malacca_Att.push_back(Attraction(6, 02, "Masjid Tranquerah "));
        Malacca_Att.push_back(Attraction(7, 03, "Mahkota Parade Mall"));
        Malacca_Att.push_back(Attraction(8, 03, "Dataran Pahlawan Megamall"));

        for(int i = 0; i < Malacca_Att.size(); i++)
        {cout << i+1 << ". " << Malacca_Att[i].get_attName() << endl;}    /*Display all attractions Malacca*/

        int input;
        cout<<"Choose the place you want in the form of the decimal \n";
        cout<<"number that have listed above: \n";
        cin>> input;
        cout << "The place you have choose is: " << Malacca_Att[input-1].get_attName();/*[ans-1] because vector starts from 0*/
        return input;
    }

}

class Sports: public Attraction
{

      int MinAge;
      int MaxAge;

public:

      Sports(int Att_id=0, int typeID=0, string Att_name="NULL", int MinAge=0, int MaxAge=0):Attraction(Att_id, typeID, Att_name), MinAge(MinAge), MaxAge(MaxAge){}
      string getSprtname();
      int getAgeMin()
      {
          return MinAge;
      }

      int getAgeMax()
      {
          return MaxAge;
      }
      virtual int display(int id);
};

string Sports::getSprtname()
{
       return Att_name;
}

int Sports::display(int id){

    cout<<"These are the list of Attractions \n";

    if(id==1)
    {
      vector<sports>Georgetown_sports;
      Georgetown_sports.push_back(Sports(1, 01, "Free Fall & Zip Lining",7,60));
      Georgetown_sports.push_back(Sports(2, 01, "Tree Swings & Water Park",7,60));

       for(int i=0; i<georgetown_sports.size();>       {
           cout<<i+1<<"."<<Georgetown_sports[i].getSprtname()<<endl;
       }
       cout<<"Choose the place that you want! Enter based on the \n";
       cout<<"number that have listed according to the attraction: \n";
       int input;
       cin>>input;
       cout<<"The place you have choose: "<<Georgetown_sports[input-1].getSprtname()<<endl
           <<"The Minimum age can enter: "<<Georgetown_sports[input-1].getAgeMin()<<",The Maximum age can enter: "<<Georgetown_sports[input-1].getAgeMax()<<endl;
    }
    else if(id==2)
    {
         vector<sports>KualaLumpur_sports;
         KualaLumpur_sports.push_back(Sports(1, 01, "Bukit Jalil Golf",18,60));
         KualaLumpur_sports.push_back(Sports(2, 01, "Bukit Tabur",18,60));

         for(int i=0; i<kualalumpur_sports.size();>          {
             cout<<i+1<<"."<<KualaLumpur_sports[i].getSprtname()<<endl;
          }
        cout<<"Choose the place that you want! Enter based on the \n";
        cout<<"number that have listed according to the attraction: \n";
        int input;
        cin>>input;
        cout<<"The place you have choose: "<<KualaLumpur_sports[input-1].getSprtname()<<endl
            <<"The Minimum age can enter: "<<KualaLumpur_sports[input-1].getAgeMin()<<",The Maximum age can enter: "<<KualaLumpur_sports[input-1].getAgeMax()<<endl;
    }
    else
    {
         vector<sports>Malacca_sports;
         Malacca_sports.push_back(Sports(1, 01, "Tiara Melaka Golf & Country Club",18,60));
         Malacca_sports.push_back(Sports(2, 01, "Wonderland Theme Park ",7,60));

         for(int i=0; i<malacca_sports.size();>          {
             cout<<i+1<<"."<<Malacca_sports[i].getSprtname()<<endl;
          }
         cout<<"Choose the place that you want! Enter based on the \n";
         cout<<"number that have listed according to the attraction: \n";
         int input;
         cin>>input;
         cout<<"The place you have choose: "<<Malacca_sports[input-1].getSprtname()<<endl
             <<"The Minimum age can enter: "<<Malacca_sports[input-1].getAgeMin()<<",The Maximum age can enter: "<<Malacca_sports[input-1].getAgeMax()<<endl;
    }

}

class Culture:public Attraction
{
      double Entrance_Fee;

 public:

      Culture(int Att_id=0, int typeID=0, string Att_name="NULL", double Entrance_Fee=0):Attraction(Att_id, typeID, Att_name), Entrance_Fee(Entrance_Fee){}
      string getCulname();
      double getEntFee();
      int display(int id);
};

double Culture::getEntFee(){

       return Entrance_Fee;

}

string Culture::getCulname(){

       return Att_name;

}

int Culture::display(int id){

    cout<<"These are the list of Attractions \n";

    if(id==1)
    {
       vector<culture>Georgetown_culture;
       Georgetown_culture.push_back(Culture(3, 02, "Khoo Kongsi Temple",0));
       Georgetown_culture.push_back(Culture(4, 02, "Sri Mariamman Temple",0));
       Georgetown_culture.push_back(Culture(5, 02, "St. George's Church",0));
       Georgetown_culture.push_back(Culture(6, 02, "Kapitan Keling Mosque",0));

       for(int i=0; i<georgetown_culture.size();>       {
           cout<<i+1<<"."<<Georgetown_culture[i].getCulname()<<endl;
       }
       cout<<"Choose the place that you want! Enter based on the \n";
       cout<<"number that have listed according to the attraction: \n";
       int input;
       cin>>input;
       cout<<"The place you have choose: "<<Georgetown_culture[input-1].getCulname()<<endl
           <<"The fees for the entrance: RM" <<Georgetown_culture[input-1].getEntFee()<<endl;
    }
    else if(id==2)
    {
         vector<culture>KualaLumpur_culture;
         KualaLumpur_culture.push_back(Culture(3, 02, "Chan See Shu Yuen temple",0));
         KualaLumpur_culture.push_back(Culture(4, 02, "Batu Caves",0));
         KualaLumpur_culture.push_back(Culture(5, 02, "Cathedral of St.Mary",0));
         KualaLumpur_culture.push_back(Culture(6, 02, "Masjid Negara Mosque",0));

         for(int i=0; i<kualalumpur_culture.size();>         {
             cout<<i+1<<"."<<KualaLumpur_culture[i].getCulname()<<endl;
         }
         cout<<"Choose the place that you want! Enter based on the \n";
         cout<<"number that have listed according to the attraction: \n";
         int input;
         cin>>input;
         cout<<"The place you have choose: "<<KualaLumpur_culture[input-1].getCulname()<<endl
             <<"The fees for the entrance: RM" <<KualaLumpur_culture[input-1].getEntFee()<<endl;
    }
    else
    {
         vector<culture>Malacca_culture;
         Malacca_culture.push_back(Culture(3, 02, "Cheng Hoon Teng Temple",0));
         Malacca_culture.push_back(Culture(4, 02, "Sri Poyyatha Vinayagar Moorthi",0));
         Malacca_culture.push_back(Culture(5, 02, "St. Francis Xavier's Church",0));
         Malacca_culture.push_back(Culture(6, 02, "Masjid Tranquerah ",0));

         for(int i=0; i<malacca_culture.size();>         {
             cout<<i+1<<"."<<Malacca_culture[i].getCulname()<<endl;
         }
         cout<<"Choose the place that you want! Enter based on the \n";
         cout<<"number that have listed according to the attraction: \n";
         int input;
         cin>>input;
         cout<<"The place you have choose: "<<Malacca_culture[input-1].getCulname()<<endl
             <<"The fees for the entrance: RM" << Malacca_culture[input-1].getEntFee()<<endl;
    }
  }

class Shopping:public Attraction{

      string MallName;

public:

      Shopping(int Att_id=0, int typeID=0, string MallName="NULL"):Attraction(Att_id, typeID), MallName(MallName){}
      string getShoppingName();
      int display(int id);

};

string Shopping::getShoppingName(){

       return MallName;

}

int Shopping::display(int id){

    cout<<"These are the list of Attractions \n";

    if(id==1)
    {
       vector<shopping>Georgetown_shopping;
       Georgetown_shopping.push_back(Shopping(6, 02, "Kapitan Keling Mosque"));
       Georgetown_shopping.push_back(Shopping(7, 03, "Prangin Mall"));
       Georgetown_shopping.push_back(Shopping(8, 03, "1st Avenue Mall"));

       for(int i=0; i<georgetown_shopping.size();>       {
           cout<<i+1<<"."<<Georgetown_shopping[i].getShoppingName()<<endl;
       }
       cout<<"Choose the place that you want! Enter based on the \n";
       cout<<"number that have listed according to the attraction: \n";
       int input;
       cin>>input;
       cout<<"The place you have choose: "<<Georgetown_shopping[input-1].getShoppingName()<<endl;
    }
    else if(id==2)
    {
         vector<shopping>KualaLumpur_shopping;
         KualaLumpur_shopping.push_back(Shopping(7, 03, "Berjaya Times Square"));
         KualaLumpur_shopping.push_back(Shopping(8, 03, "Pavilion Shopping Mall"));

       for(int i=0; i<kualalumpur_shopping.size();>       {
           cout<<i+1<<"."<<KualaLumpur_shopping[i].getShoppingName()<<endl;
       }
       cout<<"Choose the place that you want! Enter based on the \n";
       cout<<"number that have listed according to the attraction: \n";
       int input;
       cin>>input;
       cout<<"The place you have choose: "<<KualaLumpur_shopping[input-1].getShoppingName()<<endl;
    }
    else
    {
         vector<shopping>Malacca_shopping;
         Malacca_shopping.push_back(Shopping(7, 03, "Mahkota Parade Mall"));
         Malacca_shopping.push_back(Shopping(8, 03, "Dataran Pahlawan Megamall"));

       for(int i=0; i<malacca_shopping.size();>       {
           cout<<i+1<<"."<<Malacca_shopping[i].getShoppingName()<<endl;
       }
       cout<<"Choose the place that you want! Enter based on the \n";
       cout<<"number that have listed according to the attraction: \n";
       int input;
       cin>>input;
       cout<<"The place you have choose: "<<Malacca_shopping[input-1].getShoppingName()<<endl;
    }

}

int main(){

    cout<<"--------------------------------/n";
    cout<<"|| Welcome To Tourist System  ||/n";
    cout<<"--------------------------------/n";
    cout<<"/n";
    City y;
    y.setID();

    int id = y.getID();
    cout << "\nThe ID of the City: " << id << endl << "The name of the City: " << y.getName() << endl;

    int input = opt_user();

    if(input==1)
    {
        Attraction choice;      /*Create class based on the attraction wanted by the user*/
        choice.display(id);

    }
    else if(input==2) /*List only sports attraction*/
    {
        Sports choice;
        choice.display(id);
    }
    else if(input==3) /*List only Culture attractions in the chosen city*/
    {
        Culture choice;
        choice.display(id);
    }
    else(input==4) /*List all Shopping Malls in the chosen city*/
    {
        Shopping choice;
        choice.display(id);
    }

    cout << "\n\nEnd of program.\n";
    return 0;
}



[edit]Code block added - OriginalGriff[/edit]


[edit]Code block added - OriginalGriff[/edit]

推荐答案

void City::setID(){ /*A list of cities*/
 
     cout<<"The list of Cities according to alphabetical form: /n";
 
     vector<city>city;
     city.push_back(City(01, "Georgetown"));
     city.push_back(City(02, "Kuala Lumpur"));
     city.push_back(City(03, "Malacca"));
 
     for (int i=0; i<city.size();>     {
          cout<<i+1<<city[i].getName()<<endl; /*Display all the cities*/
     }



The for statement third from the bottom is not valid.


The for statement third from the bottom is not valid.


这篇关于错误:预期';'在'{'之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆