按要求补充编程片段 只要符合标准 秒采纳

img

img


按照要求填写编程片段(面向对象 类)private中int weith应该是weight的意思 不用修改就按weith即可 要运行的结果

是用c++吧
你题目的解答代码如下:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

class fruit
{
private:
    char name[10];
    char origin[10];
    int weith;
    int level;

public:
    void set(char *n,char *o, int w,int l)
    {
        strncpy(name,n,10);
        strncpy(origin,o,10);
        weith = w;
        level = l;
    }
    bool ok()
    {
        return weith >= 100 && level == 0;
    }
    char* getName()
    {
        return name;
    }
};


int main()
{
    int i,n;
    char name[10];
    char origin[10];
    int weith;
    int level;
    int orange=0,apple=0,peach=0;
    scanf("%d", &n);
    fruit f[n];        // 定义类的对象
    for (i = 0; i < n; i++)
    {
        scanf("%s%s%d%d", name,origin,&weith,&level);
        f[i].set(name,origin,weith,level);
    }
    for (i = 0; i < n; i++)
    {
        if (strncmp(f[i].getName(),"orange",10)==0)
            orange += f[i].ok();
        else if (strncmp(f[i].getName(),"apple",10)==0)
            apple += f[i].ok();
        else if (strncmp(f[i].getName(),"peach",10)==0)
            peach += f[i].ok();
    }
    printf("orange:%d; apple:%d; peach:%d;\n",orange,apple,peach);
    return 0;
}

如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!

img

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632