Gu-f


私信TA

用户名:2417225563

访问量:13673

签 名:

等  级
排  名 1139
经  验 3038
参赛次数 7
文章发表 20
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:看到这个题,很显然小于100个中的所有学生都具有公共的部分,所以我们优先考虑类。

注意事项:此处的学生的学号(num)不是之前遇到的纯数字,所以不能用int型,而是使用string型。具体的解释部分请看注释。

参考代码:

#include<iostream>
#include<iomanip>
#include <algorithm>
#include<stdio.h>
using namespace std;//命名空间
class students //学生类
{
public:   //公共部分声明输入输出方法
    void inputs();
    void prints();
private:  //私有部分定义学生的各项属性
    string num;  //学号
    string name;  //名字
    int score1;  //分数1
    int score2;  //分数2
    int score3;  //分数3
};
int main()  //主函数
{
    students a[100];  //数组a具有students类的所有属性
    int b,i;
    cin>>b;  //控制输入的学生数
    for(i=0;i<b;i++)  //循环进行读入数据
        a[i].inputs();
    for(i=0;i<b;i++)  //循环进行输出数据
        a[i].prints();
    return 0;
}
void students::inputs()  //定义输入函数
{
    cin>>num>>name>>score1>>score2>>score3;   
}
void students::prints()  //定义输出函数
{
    cout<<num<<","<<name<<","<<score1<<","<<score2<<","<<score3<<endl;
}
 

0.0分

14 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区

哇,写的好详细啊,点个赞。
2019-12-28 15:55:54
  • «
  • 1
  • »