解题思路:看到这个题,很显然小于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 人评分
C语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:560 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:574 |
C语言训练-列出最简真分数序列* (C语言代码)浏览:603 |
1051(奇了怪了)浏览:645 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:607 |
川哥的吩咐 (C语言代码)浏览:609 |
C语言训练-8除不尽的数 (C语言代码)浏览:1396 |
分解质因数 (C++代码)浏览:1469 |
C语言训练-斐波纳契数列 (C语言代码)浏览:593 |
1218题求大神帮忙看看怎么不能过浏览:688 |