class Taocan { public: string mingzi; shiwu tc[3]; int price; Taocan() {} Taocan(string n, shiwu a, shiwu b, shiwu c) { mingzi = n; tc[0] = a; tc[1] = b; tc[2] = c; price = a.price + b.price + c.price - 10; } }; Taocan taocan[3] = { Taocan("鸡腿鸡翅套餐",zhucan[0],fushi[0],drink[0]),Taocan("鳕鱼鸡米花套餐",zhucan[1],fushi[1],drink[0]),Taocan("鸡肉卷薯条套餐",zhucan[2],fushi[2],drink[0]) };指出错误并修改
时间: 2024-01-10 13:02:15 浏览: 142
在代码中缺少 shiwu 类的定义,无法确定其成员变量和方法,需要先定义 shiwu 类才能使用。同时,也需要确保 zhucan、fushi 和 drink 数组已经定义并初始化。
修改后的代码如下:
```
class Shiwu {
public:
string name;
int price;
Shiwu() {}
Shiwu(string n, int p) {
name = n;
price = p;
}
};
Shiwu zhucan[3] = { Shiwu("原味香鸡腿", 18), Shiwu("香辣鸡腿", 20), Shiwu("新奥尔良烤翅", 15) };
Shiwu fushi[3] = { Shiwu("薯条", 8), Shiwu("鸡米花", 12), Shiwu("劲爆鸡米花", 15) };
Shiwu drink[3] = { Shiwu("可乐", 6), Shiwu("雪碧", 6), Shiwu("咖啡", 10) };
class Taocan {
public:
string name;
Shiwu tc[3];
int price;
Taocan() {}
Taocan(string n, Shiwu a, Shiwu b, Shiwu c) {
name = n;
tc[0] = a;
tc[1] = b;
tc[2] = c;
price = a.price + b.price + c.price - 10;
}
};
Taocan taocan[3] = {
Taocan("鸡腿鸡翅套餐", zhucan[0], fushi[0], drink[0]),
Taocan("鳕鱼鸡米花套餐", zhucan[1], fushi[1], drink[0]),
Taocan("鸡肉卷薯条套餐", zhucan[2], fushi[2], drink[0])
};
```
阅读全文