设计一学生注册信息登记程序,该程序要求达到以下要求:
a.学生信息包括姓名,学号,性别;
b.学生信息要求能够循环从键盘输入,如果输入0 0 0,则退出输入;
c.将所有输入的学生信息按文本文件的方式存储到一名为stureginfo.txt的文件中,文件中存储信息的格式如下:
姓名:张三
学号:10521030146
性别:男
d.停止输入后,程序读出存储到stureginfo.txt文件中的所有信息,并显示在屏幕上。
//tips:同班同学请删去主函数,并将Student函数变成主函数以及注释数据变动即可避免抄袭。
#include<iostream>
#include<fstream>
using namespace std;
void Student()
{
char name[4];//4->3
long long code;
char sex[1];
while (true)
{
cout << "请输入学生姓名:";
cin >> name;
cout << "请输入学生学号:";
cin >> code;
cout << "请输入学生性别:";
cin >> sex;
cout << endl;
if (code == 0)
break;
else
{
FILE * file;//file->随便起一个变量名
errno_t err;
err = fopen_s(&file, "stureginfo.txt", "a");
fprintf(file, "姓名:%s\n学号:%lld\n性别:%s\n\n", name, code, sex);
fclose(file);
}
}
cout << "已完成学生输入,下面展示所有注册学生信息:"<<endl;//汉字同意变动
char buffer[1024];
ifstream files("stureginfo.txt");
while (!files.eof())//当到达文本末返回true
{
files.getline(buffer, 1024);
cout << buffer << endl;
}
}
int main()
{
cout << "******************************************************" <<endl;
cout << "* *" << endl;
cout << "* 欢迎使用学生注册信息登记程序 *" <<endl;
cout << "* *"<<endl;
cout << "******************************************************" <<endl<< endl;
system("pause");
cout << endl;
Student();
}
作业实属不易,请多多支持。(关注,点赞)