3 回答

TA貢獻1780條經(jīng)驗 獲得超1個贊
void menu() { .... } //如果要將menu寫在main后面,這里加:void menu();
void insert();
void display();
void locate();
void modify();
void save(); //類似這樣將要調(diào)用的函數(shù)頭寫在這個位置即可
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條經(jīng)驗 獲得超4個贊
你的serch函數(shù)定義都寫到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 關注
- 194 瀏覽
添加回答
舉報