c++说我很多函数定义不合法咋办? 5
intmain(){intchoose;studentv;do{menu();cin>>choose;switch(choose){case1:v.insert();br...
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);
} 展开
{
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);
} 展开
4个回答
展开全部
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);
}
2019-11-26 · 百度认证:云南新华电脑职业培训学校官方账号
云南新华电脑学校
云南新华电脑学校是经云南省教育厅批准成立的省(部)级重点计算机专业学校,采用三元化管理模式,教学设备先进,师资雄厚学生毕业即就业,学院引进了电商企业入驻,创建心为电商创业园区,实现在校即创业
向TA提问
关注
展开全部
c++标准不允许在一个函数内部定义另一个函数
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的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 );}
应该是这样
#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 );}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我完全看不懂的啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询