ZBLOG

本关任务:结构体数组的定义和使用。 相关知识 为了完成本关任务,你需要掌握: 结构体数组的定义; 引用结构体数组元素的成员项。 结构体数组的定义 struct student { char name[10]; int age; int score; }stu[3]; 引用结构体数组元素的成员项 例如,引用结构的成员项name,stu[i].name 编程要求 根据提示,在右侧编辑器代码文件中的 Begin-End 区间内补充代码,使得程序能够正确运行。 测试说明 平台会对你编写的...

#include <iostream>
using namespace std;

struct student {
    char name[10];
    int age;
    int score;
} stu[3];

int main() {
    // 补充代码,给结构体数组赋值
    strcpy(stu[0].name, "Lin Dan");
    stu[0].age = 28;
    stu[0].score = 100;

    strcpy(stu[1].name, "Feng Kun");
    stu[1].age = 25;
    stu[1].score = 92;

    strcpy(stu[2].name, "Yang Qin");
    stu[2].age = 27;
    stu[2].score = 60;

    // 输出结构体数组元素的成员项
    for (int i = 0; i < 3; i++) {
        cout << stu[i].name << "," << stu[i].age << "," << stu[i].score << endl;
    }

    return 0;
}

输出结果: Lin Dan,28,100 Feng Kun,25,92 Yang Qin,27,60


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=10565

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?