C++语言程序

来源:百度知道 编辑:UC知道 时间:2024/09/28 10:00:27
那个高手能帮我做一个C++程序 要求 能输入学生的姓名 学号 成绩
输出 总人数 平均成绩 及格人数 不及格人数
如果能再有C写一个更好! 如果有C的话 再加50分
先谢谢了 !
可以用一个不用链表的吗?
因为链表我不太熟!
如有其他 电科零五级学生来找答案 请在找其他的吧 这份已经有人用了 谢谢 合作

C++和C语言我在算法上没有任何改变
我建议使用链表,虽然链表的功能都可以用数组实现。而链表在对于不知道规模的数组处理上优于数组,例如动态分配内存,而每个节点都只多用1个next指针而已。如果要用数组来实现的话,可以先申请10个单元,然后每次增加都判断一次是否越界,如果越界就申请一块20个单元的数组,然后把前十项复制过去,在各项复杂度上都很吃亏。
你不熟不代表老师知道你不熟~是吧~

C++版:

#include<iostream>
#include<string>
using namespace std;

struct stud{
string name;
int num;
int score;
stud *next;
};

int main() {
stud *head=new stud;
stud *temp=head;

cout<<"input the student's number, with -1 ended: ";
int n;
cin>>n;
while(n>=0) {
temp->next=new stud;
temp->num=n;
cout<<"input the student's name: ";
cin>>temp->name;
cout<<"input the student's score: ";
cin>>temp->score;
cout<<"input the next student's number, with -1 ended: ";
cin>>n;
temp=temp