我不断收到以下错误:
"overloaded function not found in 'pizza'"
这指的是void outputDescription
和double computePrice
功能,下面。我不知道出了什么问题。
我是 C++ 的初学者,但代码看起来不错。这是上课用的。我应该至少有 1 个 mutator 函数和 1 个 accessor 函数,一个计算价格的函数和一个输出比萨饼描述的函数。
这是我的代码:
#include <iostream>
#include <string>
using namespace std;
class pizza
{
public:
void getOrder (string, string, int, int) ;
void outputDescription (string&, string&, int&, int&) const;
double computePrice (string&, int&, int&) const;
private:
string type;
string size;
int pepperoni;
int cheese;
};
int main ()
{
pizza customerpizza;
double price;
string type;
string size;
int pepperoni;
int cheese;
customerpizza.getOrder (type, size, pepperoni, cheese);
customerpizza.outputDescription (type, size, pepperoni, cheese);
price = customerpizza.computePrice (size, pepperoni, cheese);
cout << "Total cost is $" << price << ".\n";
system("PAUSE");
return 0;
}
void pizza::getOrder (string type, string size, int pepperoni, int cheese)
{
int pizzaType;
int pizzaSize;
cout << "Please choose 1 for deep dish, 2 for hand tossed, or 3\n"; cout << " for pan pizza.\n";
cin >> pizzaType;
switch(pizzaType)
{
case 1: type = "deep dish";
break;
case 2: type = "hand tossed";
break;
case 3: type = "pan";
break;
default: cout << "You entered an invalid choice. Please\n";
cout << " enter 1 for deep dish, 2 for hand\n";
cout << " tossed, or 3 for pan pizza.\n";
}
cout << "Please choose 1 for small, 2 for medium, or 3 for\n";
cout << " large pizza.\n";
cin >> pizzaSize;
switch(pizzaSize)
{
case 1: size = "small";
break;
case 2: size = "medium";
break;
case 3: size = "large";
break;
default: cout << "You entered an invalid choice. Please\n";
cout << " enter 1 for small, 2 for medium, or\n";
cout << " 3 for large pizza.\n";
}
cout << "How many pepperoni servings on this pizza?\n";
cin >> pepperoni;
cout << "How many cheese servings on this pizza?\n";
cin >> cheese;
}
void pizza::outputDescription (string type, string size, int pepperoni, int cheese)
{
cout << "You ordered a " << size << << type << " pizza with \n";
cout << pepperoni << " servings of pepperoni and "<< cheese << endl;
cout << "servings of cheese.\n";
}
double pizza::computePrice (string size, int pepperoni, int cheese)
{
double price;
if (size = "small")
{
price = 10 + (2 * (pepperoni + cheese));
}
else if (size = "medium")
{
price = 14 + (2 * (pepperoni + cheese));
}
else if (size = "large")
{
price = 17 + (2 * (pepperoni + cheese));
}
return price;
}