2016-02-23 5 views
1

Я довольно новичок в C++, поэтому поговорим с пещерным человеком. Я пытаюсь заставить код работать в цикле, и когда цикл завершен, подсчитайте общее количество и все упорядоченное. Я сталкиваюсь с этой ошибкой, и я не уверен, почему.Ожидаемый неквалифицированный идентификатор до '.' token

[Ошибка] ожидаемый неквалифицированный идентификатор до '.' Маркер

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

string again; 
char pType, pSize, topping, temp; 
const int SMALL = 1; 
int type = 0, size = 0; 
const int MEDIUM = 2; 
const int LARGE = 3; 
const int DEEPDISH = 1; 
const int HANDTOSSED = 2; 
const int PAN = 3; 
double total = 0; 

class Pizza 
{ 
    private: 
      int type; 
      int size; 
      bool cheese;  
      bool pepperoni; 

    public: 
      Pizza(); 
      int getType(); 
      int getSize(); 
      bool getCheese(); 
      bool getPepperoni(); 
      void setType(int t); 
      void setSize(int s); 
      void setCheese(bool choice); 
      void setPepperoni(bool choice); 

    void outputDescription(); 
    double computePrice(); 
}; 

class Order 
{ 
private: 
    vector<Pizza> c; 

public: 
    Order(); 
    void customerOrder(); 
    void customerTotal(); 
    void customerinput(); 
}; 

Pizza::Pizza() 
{ 
    type = DEEPDISH; 
    size = SMALL; 
    cheese = pepperoni = false; 
} 

int Pizza::getType() 
{ 
    return type; 
} 

int Pizza::getSize() 
{ 
    return size; 
} 

bool Pizza::getCheese() 
{ 
    return cheese; 
} 

bool Pizza::getPepperoni() 
{ 
    return pepperoni; 
} 

void Pizza::setType(int t) 
{ 
    type = t; 
} 

void Pizza::setSize(int s) 
{ 
    size = s; 
} 

void Pizza::setCheese(bool choice) 
{ 
    cheese = choice; 
} 

void Pizza::setPepperoni(bool choice) 
{ 
    pepperoni= choice; 
} 

void Pizza::outputDescription() 
{ 
    switch (size) 
    { 
     case SMALL: 
     cout << "Small "; break; 
     case MEDIUM: 
     cout << "Medium "; break; 
     case LARGE: 
     cout << "Large "; break; 
     default: 
     cout << "Unknown" ; 
    } 

    switch (type) 
    { 
     case DEEPDISH: 
     cout << "deepdish "; break; 
     case HANDTOSSED: 
     cout << "hand tossed "; break; 
     case PAN: 
     cout << "pan "; break; 
     default: 
     cout << "Unknown"; 
    } 

    cout << "pizza"; 
} 

double Pizza::computePrice() 
{ 
    double cost = 0.0; 
    switch (size) 
    { 
    case SMALL: 
    cost += 10; break; 
    case MEDIUM: 
    cost += 14; break; 
    case LARGE: 
    cost += 17; break; 
    } 

    if (cheese) 
    cost += 2.0; 
    if (pepperoni) 
    cost += 2.0; 

    return cost; 
} 

Order custmizedTotal; 
Pizza myPizza; 
bool done=false; 
void Order::customerinput(){ 
while (again == "y"){ 
     cout << "What sized pizza, please enter S, M OR L: "; 
     cin >> pSize; 
     cin.clear(); 

     switch(pSize) 
     { 
      case 'S': case 's': 
      size = SMALL; break; 
      case 'M': case 'm': 
      size = MEDIUM; break; 
      case 'L': case 'l': 
      size = LARGE; break; 
     } 

     cout << "What type of pizza, enter D for Deepdish, H for Hand tossed, and P for Pan: "; 
     cin >> pType; 
     cin.clear(); 

     switch(pType) 
     { 
      case 'D': case 'd': 
      type = DEEPDISH; break; 
      case 'H': case 'h': 
      type = HANDTOSSED; break; 
      case 'P': case 'p': 
      type = PAN; break; 
     } 


     myPizza.setSize(size); 
     myPizza.setType(type); 

     cout << "Would you like cheese (y/n)? "; 
     cin >> topping; 
     cin.clear(); 

     if (topping == 'Y' || topping == 'y') 
      myPizza.setCheese(true); 

     cout << "Would you like pepperoni (y/n)? "; 
     cin >> topping; 
     cin.clear(); 

     if (topping == 'Y' || topping == 'y') 
      myPizza.setPepperoni(true); 


     cout << endl 
     << "Your order: "; 
     myPizza.outputDescription(); 
     cout << endl; 
     cout << "Price: $" << myPizza.computePrice() << endl; 

     cout << "Again? (y/n)"; 
     cin >> again; 


    } 
} 

void Order::customerTotal(){ 

    cout << "Your Total order is: " << endl; 
    for(int i=0; i<c.size(); i++) 
    { 
     c[i].outputDescription(); 
     cout << endl; 
     cout << c[i].computePrice(); 
     cout << endl; 
     total=total+c[i].computePrice(); 
    }  
    cout << "Totat Cost: $" << total; 
    cout << endl; 
    c.push_back(myPizza); 
} 

int main() 
{ 
    custmizedTotal.customerinput(); 
    //Order.customerinput(); 
    if(again != "y"){ 
     custmizedTotal.customerTotal(); 
    } 
    return 0; 
} 
+0

Возможный дубликат [ошибка: ожидаемый неквалифицированный идентификатор до '.' Token //(struct)](http://stackoverflow.com/questions/18062616/error-expected-unqualified-id-before-token-struct) – RyanfaeScotland

ответ

0

Заменить

int main(){ 
    Order.customerinput(); //error is here 
    if(again != "y"){ 
     custmizedTotal.customerTotal(); 
    } 
    return 0; 
} 

По:

int main(){ 
    custmizedTotal.customerinput(); // Change this line 
    if(again != "y"){ 
     custmizedTotal.customerTotal(); 
    } 
    return 0; 
} 

Вторая ошибка, что у вас есть, как вызвано тем, что вы забыли определить конструктор заказа.

Добавьте это в ваш код (выше основного метода()):

Order::Order(){ 
    // Set the initial values for order 
} 

Вы также забыли добавить метод CustomerOrder (но это не приводит к ошибке, так как вы не используете этот метод):

void Order::customerOrder() { 
} 
+0

Как в 'int main() {custmizedTotal.customerTotal(); } \t return 0; } – jibicax

+0

есть ... извините. Я обновлю ответ – W0rmH0le

+0

Я применил изменение, и я получил ошибку. [Ошибка] ld возвратил 1 статус выхода. С сообщением: undefined ссылка на 'Order :: Order() ' – jibicax

Смежные вопросы