今天没有讲新东西,而是做了一天的题目,下面是用链表写的一个查询成绩的小程序,写的并不好吧:
#include<iostream>
#include<string>
using namespace std;
class student{
public:
string name;//学生姓名
int xuehao;//学号
string banji; //班级
int cj; //成绩
int cj1;
int all;
student *next;
private:
};
void main(){
student *head;
student mn;
head = &mn;
mn.name = "王小二";
mn.xuehao = 1;
mn.banji = "三年二班";
mn.cj = 90;
mn.cj1 = 95;
mn.all = mn.cj + mn.cj1;
student mn1;
mn.next = &mn1;
mn1.name = "何小洋";
mn1.xuehao = 2;
mn1.banji = "三年二班";
mn1.cj = 80;
mn1.cj1 = 85;
mn1.all= mn1.cj + mn1.cj1;
mn1.next = NULL;
cout << "姓名 " << head->name << endl;
cout << "学号 " << head->xuehao<< endl;
cout << "班级 " << head->banji << endl;
cout << "语文成绩 " << head->cj << endl;
cout << "英语成绩 " << head->cj1 << endl;
cout << "总成绩 " << head->all << endl;
cout << "姓名 " << head->next->name << endl;
cout << "学号 " << head->next->xuehao << endl;
cout << "班级 " << head->next->banji << endl;
cout << "语文成绩 " << head->next->cj << endl;
cout << "英语成绩 " << head->next->cj1 << endl;
cout << "总成绩 " << head->next->all << endl;
/*while (head != NULL){
cout << "姓名 " << head->name << endl;
cout << "学号 " << head->xuehao<< endl;
cout << "班级 " << head->banji << endl;
cout << "语文成绩 " << head->cj << endl;
cout << "英语成绩 " << head->cj1 << endl;
cout << "总成绩 " << head->all << endl;
head = head->next;
}*/
int j;
cout << "请输入你要查询的方式:1.学号查询 2.姓名查询" << endl;
cin >> j;
if (j == 1){
while (1){
int i;
cout << "请输入你要查找的学生的学号" << endl;
cin >> i;
switch (i){
case 1:
cout << "姓名 " << head->name << endl;
cout << "学号 " << head->xuehao << endl;
cout << "班级 " << head->banji << endl;
cout << "语文成绩 " << head->cj << endl;
cout << "英语成绩 " << head->cj1 << endl;
cout << "总成绩 " << head->all << endl;
break;
case 2:
cout << "姓名 " << head->next->name << endl;
cout << "学号 " << head->next->xuehao << endl;
cout << "班级 " << head->next->banji << endl;
cout << "语文成绩 " << head->next->cj << endl;
cout << "英语成绩 " << head->next->cj1 << endl;
cout << "总成绩 " << head->next->all << endl;
break;
}
}
}
else {
while (1){
cout << "请输入你要查询的学生的姓名" << endl;
string a;
cin >> a;
if (a == mn.name){
cout << "姓名 " << head->name << endl;
cout << "学号 " << head->xuehao << endl;
cout << "班级 " << head->banji << endl;
cout << "语文成绩 " << head->cj << endl;
cout << "英语成绩 " << head->cj1 << endl;
cout << "总成绩 " << head->all << endl;
}
else if (a == mn1.name){
cout << "姓名 " << head->next->name << endl;
cout << "学号 " << head->next->xuehao << endl;
cout << "班级 " << head->next->banji << endl;
cout << "语文成绩 " << head->next->cj << endl;
cout << "英语成绩 " << head->next->cj1 << endl;
cout << "总成绩 " << head->next->all << endl;
}
}
}
system("pause");
}