Anno775 2022-04-11 22:18 采纳率: 20%
浏览 12

请问这个要怎么改? 出了很多错误,写完自己很自信,运行很卑微。。 (目的是要求出性价比最高的商品)

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
#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;
}

运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

1条回答 默认 最新

  • 非西昂 2022-04-11 22:24
    关注

    1.28行new Product[3];先补全下吧
    2.a应该是类的对象吧,从这个代码上看没有声明

    评论

报告相同问题?

问题事件

  • 创建了问题 4月11日

悬赏问题

  • ¥15 铜与钢双金属板叠加在一起每种材料300mm长,18mm宽,4mm厚一端固定并加热至80℃,当加热端温度保持不变时另一端的稳态温度。ansys
  • ¥15 django5安装失败
  • ¥15 Java与Hbase相关问题
  • ¥15 后缀 crn 游戏文件提取资源
  • ¥15 ANSYS分析简单钎焊问题
  • ¥20 bash代码推送不上去 git fetch origin master #失败了
  • ¥15 LOL外服加入了反作弊系统,现在游戏录像rofl文件离线都无法打开
  • ¥15 在centos7安装conda
  • ¥15 c#调用yolo3 dll文件获取的数据对不上
  • ¥20 WPF 如何实现多语言,label 和cs(live Charts)中是否都能翻译