作业四:老师学生类
来源:互联网 发布:u盘文件怎样移动到mac 编辑:程序博客网 时间:2024/04/29 08:24
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <string>
#include <stdlib.h>
using namespace std;
class student
{
public:
int snum;
string name;
char sex;
string subject;
float score;
public:
void add()
{
ofstream infile("sdata.txt",ios::app);
if(infile == NULL)
{
cout << "file : data.txt open error!" << endl;
exit(-1);
}
cout<<"please enter 一个学生的:学号,姓名,性别,专业,总分"<<endl;
string in;
cin>>in;
infile<<"/n"+in;
}
void display()
{
ifstream infile("sdata.txt");
if(infile == NULL)
{
cout << "file : data.txt open error!" << endl;
exit(-1);
}
string line;
vector< vector<string> > output;
while(getline(infile, line))
{
string word;
stringstream instream(line);
vector<string> lineVec;
while(getline(instream,word,','))
lineVec.push_back(word);
output.push_back(lineVec);
}
cout<<"学生信息:"<<endl;
cout<<"学号"<<"姓名"<<"性别"<<"专业"<<"总分"<<endl;
vector< vector<string> >::const_iterator outIter = output.begin();
for(; outIter != output.end(); outIter++)
{
vector<string>::const_iterator inIter = outIter->begin();
for(; inIter != outIter->end(); inIter++)
{
cout << *inIter;
if((inIter + 1) != outIter->end())
cout <<" "<<" ";
else
cout << endl;
}
}
cout<<"数据输出完毕!"<<endl;
}
};
class teacher
{
public:
int tnum;
string name;
char sex;
string collage;
string tsubject;
public:
void display()
{
ifstream infile("tdata.txt");
if(infile == NULL)
{
cout << "file : data.txt open error!" << endl;
exit(-1);
}
string line;
vector< vector<string> > output;
while(getline(infile, line))
{
string word;
stringstream instream(line);
vector<string> lineVec;
while(getline(instream,word,','))
lineVec.push_back(word);
output.push_back(lineVec);
}
cout<<"老师信息:"<<endl;
cout<<"工号"<<" 姓名 "<<"性别 "<<"院系 "<<"所授课程 "<<endl;
vector< vector<string> >::const_iterator outIter = output.begin();
for(; outIter != output.end(); outIter++)
{
vector<string>::const_iterator inIter = outIter->begin();
for(; inIter != outIter->end(); inIter++)
{
cout << *inIter;
if((inIter + 1) != outIter->end())
cout <<" "<<" ";
else
cout << endl;
}
}
cout<<"数据输出完毕!"<<endl;
}
void add()
{
ofstream infile("tdata.txt",ios::app);
if(infile == NULL)
{
cout << "file : data.txt open error!" << endl;
exit(-1);
}
cout<<"please enter 一个老师的:工号,姓名,性别,院系,所授课程"<<endl;
string in;
cin>>in;
infile<<"/n"+in;
}
};
void main()
{
student st;
teacher te;
st.display();
te.display();
st.add();
st.display();
te.add();
te.display();
}
//sdata.txt//学生数据
008,zk,male,imis,500
009,wh,male,imis,500
010,lqh,male,imis,500
001,yjy,female,imis,500
//tdata.txt//老师数据
211,yj,female,lxy,c++
212,tf,female,lxy,c++
#include <sstream>
#include <fstream>
#include <vector>
#include <string>
#include <stdlib.h>
using namespace std;
class student
{
public:
int snum;
string name;
char sex;
string subject;
float score;
public:
void add()
{
ofstream infile("sdata.txt",ios::app);
if(infile == NULL)
{
cout << "file : data.txt open error!" << endl;
exit(-1);
}
cout<<"please enter 一个学生的:学号,姓名,性别,专业,总分"<<endl;
string in;
cin>>in;
infile<<"/n"+in;
}
void display()
{
ifstream infile("sdata.txt");
if(infile == NULL)
{
cout << "file : data.txt open error!" << endl;
exit(-1);
}
string line;
vector< vector<string> > output;
while(getline(infile, line))
{
string word;
stringstream instream(line);
vector<string> lineVec;
while(getline(instream,word,','))
lineVec.push_back(word);
output.push_back(lineVec);
}
cout<<"学生信息:"<<endl;
cout<<"学号"<<"姓名"<<"性别"<<"专业"<<"总分"<<endl;
vector< vector<string> >::const_iterator outIter = output.begin();
for(; outIter != output.end(); outIter++)
{
vector<string>::const_iterator inIter = outIter->begin();
for(; inIter != outIter->end(); inIter++)
{
cout << *inIter;
if((inIter + 1) != outIter->end())
cout <<" "<<" ";
else
cout << endl;
}
}
cout<<"数据输出完毕!"<<endl;
}
};
class teacher
{
public:
int tnum;
string name;
char sex;
string collage;
string tsubject;
public:
void display()
{
ifstream infile("tdata.txt");
if(infile == NULL)
{
cout << "file : data.txt open error!" << endl;
exit(-1);
}
string line;
vector< vector<string> > output;
while(getline(infile, line))
{
string word;
stringstream instream(line);
vector<string> lineVec;
while(getline(instream,word,','))
lineVec.push_back(word);
output.push_back(lineVec);
}
cout<<"老师信息:"<<endl;
cout<<"工号"<<" 姓名 "<<"性别 "<<"院系 "<<"所授课程 "<<endl;
vector< vector<string> >::const_iterator outIter = output.begin();
for(; outIter != output.end(); outIter++)
{
vector<string>::const_iterator inIter = outIter->begin();
for(; inIter != outIter->end(); inIter++)
{
cout << *inIter;
if((inIter + 1) != outIter->end())
cout <<" "<<" ";
else
cout << endl;
}
}
cout<<"数据输出完毕!"<<endl;
}
void add()
{
ofstream infile("tdata.txt",ios::app);
if(infile == NULL)
{
cout << "file : data.txt open error!" << endl;
exit(-1);
}
cout<<"please enter 一个老师的:工号,姓名,性别,院系,所授课程"<<endl;
string in;
cin>>in;
infile<<"/n"+in;
}
};
void main()
{
student st;
teacher te;
st.display();
te.display();
st.add();
st.display();
te.add();
te.display();
}
//sdata.txt//学生数据
008,zk,male,imis,500
009,wh,male,imis,500
010,lqh,male,imis,500
001,yjy,female,imis,500
//tdata.txt//老师数据
211,yj,female,lxy,c++
212,tf,female,lxy,c++
- 作业四:老师学生类
- 学生 忘带作业挨老师骂
- 学生 老师 类
- 学生老师类
- 老师&&学生
- 第四单元老师学生类(zuoye)
- 第二章作业,学生类
- 课后作业之学生类
- 学生作业
- 学生作业
- 学生作业
- 学生作业
- 学生作业~~
- 老师布置的C++实践作业:C++编写的学生系统
- 一起作业网 肖盾:如何打动投资人,说服老师,造福学生
- 学生与老师
- 谁是老师,谁是学生?
- 项目四--学生类Student
- 高级语言反汇编程序的函数调用过程
- WTL 学习笔记 -- ActiveX
- big-endian和little-endian这两个术语的由来
- 作业一:日期
- 抽象工厂的例子
- 作业四:老师学生类
- 汇编指令
- 一个shell脚本解多个压缩文件(改别人的代码)
- 作业三:集合类
- letter to Miss Xie
- 大话西游经典台词
- 作业二:大整数加减
- javascript 常用代码大全
- JS取得上传图片的大小