求帮忙
  • 板块灌水区
  • 楼主封禁用户
  • 当前回复1
  • 已保存回复1
  • 发布时间2020/12/6 16:54
  • 上次更新2023/11/5 06:30:24
查看原帖
求帮忙
363096
封禁用户楼主2020/12/6 16:54

哪位过路的大佬帮忙看一下我的程序?

#include<bits/stdc++.h>
#include<cstring>
using namespace std;
struct student
{
	string name;//姓名 
	char sex;//性别 
	float score;//学分 
	int birthday;//生日 
}a[100];
int main()
{
	int num,i=0;//i表示第几个学生 
	cout<<"Please input the following num to run the program."<<endl;
	cout<<"1.add student"<<endl;//新添加学生信息 
	cout<<"2.delete last student"<<endl;//删除最后一个学生信息 
	cout<<"3.display student list"<<endl;//打印输出当前系统含有的学生信息 
	cout<<"4.save the student list to the the database"<<endl;//存储学生信息至数据库 覆盖(可以使用database.txt模拟) 
	cout<<"5.read the student list from the database"<<endl;//从数据库读取学生信息更新当前学生信息内容 
	cout<<"6.exit the program"<<endl<<endl;//退出程序 
	cout<<"Input num:";
	for(;;)
	{
		cin>>num;
		switch(num)
		{
			case 1:
				if(i==100)
				{
					cout<<"学生信息已满!"<<endl;
					cout<<"Input num:";
					break;
				}
				else
				{
					cout<<"Enter name>";
					cin>>a[i].name >>a[i].sex >>a[i].score >>a[i].birthday ;
					i++;
					cout<<"Input num:";
					break;
				}
			case 2:
				if(i==0)
				{
					cout<<"当前还未有学生信息!请按1输入学生信息!"<<endl;
					cout<<"Input num:";
					break;
				}
				else
				{
					a[i-1].name="";
					a[i-1].sex =' ';
					a[i-1].score =NULL;
					a[i-1].birthday =NULL;
					i--;
					cout<<"Input num:";
					break;
				}
			case 3:
				if(i==0)
				{
					cout<<"当前没有任何学生信息!请按1添加学生信息!"<<endl;
					cout<<"Input num:";
				}
				else
					{
					for(int n=0;n<i;n++)
					{
						cout<<a[n].name<<" ";
						cout<<a[n].sex <<" ";
						cout<<a[n].score <<" ";
						cout<<a[n].birthday <<endl;
					}
					cout<<"Input num:";
				}
				break;
			case 4:
				freopen("学校学生管理软件.out","w",stdout);
				for(int n=0;n<i;n++)
				{
					cout<<a[n].name<<" ";
					cout<<a[n].sex <<" ";
					cout<<a[n].score <<" ";
					cout<<a[n].birthday<<endl;
				}
				fclose(stdout);
				cout<<"Input num:";
				break;
			case 5:
				cout<<freopen("学校学生管理软件.out","r",stdin)<<endl;
				fclose(stdin);
				cout<<"Input num:";
				cin>>num;
				break;
			case 6:
				return 0;
		}	
	}
}```
附:in文件内容为:Bob b 98 20070821
2020/12/6 16:54
加载中...