3 回答
TA贡献1780条经验 获得超1个赞
void menu() { .... } //如果要将menu写在main后面,这里加:void menu();
void insert();
void display();
void locate();
void modify();
void save(); //类似这样将要调用的函数头写在这个位置即可
int main() { int choose; student v;
do {
menu(); cin>>choose;
switch(choose) {
case1:v.insert();break;
case2:v.display();break;
case3:v.locate();break;
case4:v.modify();break;
case5:v.save();break;
case6:v.load();break;
default:break;
}
}
while(choose!=0);
}
TA贡献1829条经验 获得超4个赞
你的serch函数定义都写到main里面去了,不缩进看不出来吧
应该是这样
#include <iostream>#include <fstream>#include <string>using namespace std;class student{ public: string name; string id; string rage; string chinese; int chinesenum; string math; int mathnum; string english; int englishnum; student *next; };void serch( student *a ){ string *rage2; cout << "输入籍贯" << endl; cin >> *rage2; int i = 0; student *n; n = a; while ( n ) { if ( !strcmp( n->rage, *rage2.c_str() ) ) i++; n = n->next; } cout << rage2 << "有" << i << "人" << endl;}void main(){ student *head; student *p = new student; head = p; student *q = new student; fstream iflie( "input.txt", ios::in | ios::binary ); while ( iflie.peek() != EOF ) { iflie >> p->name >> p->id >> p->rage >> p->chinese >> p->chinesenum >> p->math >> p->mathnum >> p->english >> p->englishnum; cout << p->name << ' ' << p->id << ' ' << p->rage << ' ' << p->chinese << ' ' << p->chinesenum << ' ' << p->math << ' ' << p->mathnum << ' ' << p->english << ' ' << p->englishnum << endl; p->next = q; p = q; q = new student; } iflie.close(); delete p; delete q; serch( head );}
- 3 回答
- 0 关注
- 173 浏览
添加回答
举报