第七章 文件和结构体 7.2 结构体 P140

/********************************
 * 程序来源:董老师一本通
 * 程序名称:140 7.2
 * 章    节:7.2 结构体 
 * 作    者:[email protected]
 * 运行测试:通过
 *******************************/
//#include   //万能头文件,不建议使用
#include 
#include 
#include 
using namespace std;

//struct
struct student{
    string name;
    double math;
    double chinese;
    double totle;
}stu[100];

//main() star
int main() {
    //code here
    int n;    //count
    cin >> n;
    
    for(int i=0; i> stu[i].name >> stu[i].math >> stu[i].chinese;
        
        stu[i].totle = stu[i].math + stu[i].chinese;
    }
    
    //冒泡排序 
    for(int i=n-1; i>0; i--) {
        for(int j=0; j

测试:
输入数据:

4
sd 23 89
ss 67 56
gg 89 76
gs 67 90

输出数据:

student list:
gg      89      76      165
gs      67      90      157
ss      67      56      123
sd      23      89      112

--------------------------------
Process exited after 29.75 seconds with return value 0
请按任意键继续. . .

你可能感兴趣的:(第七章 文件和结构体 7.2 结构体 P140)