C++编写一个程序,

来源:百度知道 编辑:UC知道 时间:2024/06/06 13:43:59
对已有若干学生数据(包括学号、姓名和成绩),要求输出这些学生数据并计算输出平均分和学生总人数

#include<iostream>
#include<string>
using namespace std;
struct Stud
{
int number;
string name;
double mark;
};
int main()
{
Stud *stud;
int num;
cout<<"how many students: ";
cin>>num;
stud=new Stud[num];
double SumOfMark=0;
for(int i=0;i<num;i++)
{
cout<<"student's number: ";
cin>>stud[i].number;
cout<<"student's name: ";
getline(cin,stud[i].name);
cout<<"student's mark: ";
cin>>stud[i].mark;
SumOfMark+=stud[i].mark;
}
cout<<"The students' information are: "<<endl;
for(i=0;i<num;i++)
cout<<stud[i].number<<" - "<<stud[i].name<<" - "<<stud[i].mark<<endl;
cout<<"number of students is: