问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
#include<iostream>
using namespace std;
class Product{
private:
char name[20];
int price;
int score;
public:
void Input(){
cout<<"Please input the name:"<<endl;
cin>>name;
cout<<"Ok!"<<endl;
cout<<"Please input the price and score of this product:"<<endl;
cin>>price>>score;
cout<<"Yes!"<<endl;
}
double Contrast(){
return score/price;
}
void Print(){
}
};
int main(){
new Product[3];
for(int i=1; i<4; i++)
{
Product[i-1].Input();
Product[i-1].Print();
Product[i-1].Contrast();
}
double MaxRatio=0;
double MaxRatio = a->Contrast();
int num=0;
for(int i=1; i<4; i++)
{
if(a[i-1].Contrast()>MaxRatio)
{
MaxRatio = a->Contrast();
num=i;
}
}
a[num-1].Print();
return 0;
}
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果