次のエラーが発生し続けます。
"overloaded function not found in 'pizza'"
これは、以下の機能を参照しvoid outputDescription
ています。double computePrice
何が悪いのかわかりません。
私は C++ の初心者ですが、コードは正しく見えます。これは授業用です。少なくとも 1 つのミューテーター関数と 1 つのアクセサー関数、価格を計算する関数、およびピザの説明を出力する関数が必要です。
これが私のコードです:
#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;
}