是用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;
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!