#include "Student.h"
#include <fstream>
#include <iostream>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <string>
#include <conio.h>
using namespace std;
void getFileData(vector<Student> & rInfor);
void getRecord(char * file);
void main()
{
char* record = "record.txt";
ofstream fout(record, ios_base::out | ios_base::app);
vector<Student> infor;
int it = 0;
int choice;
getFileData(infor);//get data from the file
srand( time(NULL) );
while ( 1 )
{
cout << "1.开始点名 "
<< "2.显示所有同学点名情况 "
<< "3.清屏 "
<< "4.退出 " << endl;
while (!((cin >> choice) && choice > 0 && choice < 5))
{
cin.clear();
while (cin.get()!='\n')
{
continue;
}
cout << "你的输入有误,请重新输入!" << endl;
}
switch (choice)
{
case 1:
{
it = rand() % infor.size();
infor[it].setTime();
infor[it].getInformation(cout);
cout << "是否保存点名? <y or n>";
char temp;
temp = getch();
if (temp == 'y' || temp == 'Y')
{
cout << temp;
infor[it].getInformation(fout);
}
else
{
cout << temp;
}
cin.get();
cout << endl;
break;
}
case 2:
{
getRecord(record);
break;
}
case 3:
{
system("CLS");
break;
}
case 4:
{
exit( 1 );
}
}
}
//it = rand() % infor.size();
fout.close();
}
void getFileData(vector<Student> & rInfor)
{
char * fileName = "1.txt";
ifstream fin(fileName, ios_base::out | ios_base::app);
if (!fin.is_open())
{
cerr << "Could not open the file " << fileName << endl;
exit(EXIT_FAILURE);
}
while( !fin.eof() )
{
Student temp(fin);
rInfor.push_back( temp );
}
fin.clear();
fin.close();
}
void getRecord(char * file)
{
ifstream fin;
string temStr;
fin.open(file);
if (!fin.is_open())
{
cerr << "Could not open the file " << file << endl;
exit(EXIT_FAILURE);
}
while (!fin.eof())
{
getline(fin,temStr);
if (temStr.size() == 0)
{
continue;
}
else
{
cout << temStr << endl;
}
}
fin.clear();
fin.close();
}
随机点名系统(c++)
4星 · 超过85%的资源 需积分: 50 111 浏览量
2012-05-11
18:18:39
上传
评论 6
收藏 2KB RAR 举报
清竹小雨
- 粉丝: 132
- 资源: 41
最新资源
- 《CKA/CKAD应试指南/从docker到kubernetes 完全攻略》学习笔记 第1章docker基础(1.1-1.4)
- 基于python实现的水下压缩空气储能互补系统建模仿真与经济效益分析+源代码+论文
- 华中科技大学-自然语言处理实验,Bi-LSTM+CRF的中文分词框架,并且利用基于深度学习的方法进行中文命名实体识别++源码报告
- 基于动态罚函数的铁路车流分配与径路优化模型python源码
- 鱼群算法求解组环问题python源码+文档说明
- 基于决策优化的多波束测深测线规划模型MATLAB代码
- 课程设计-基于python实现的多目标优化算法求解带时间窗的车辆路径规划问题+源代码+文档说明+界面截图+pptx
- 基于通信信号与通信系统的MATLAB仿真源码-课程设计
- 嵌入式-信号机制(概念,发送,定时,捕捉,SIGCHLD 信号实现回收子进程)
- c语言管理系统大一大二笔记
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页