哪位前辈帮下忙,
要做一个“教学设备管理系统”的课程设计任务书
哪个大哥帮我写下删除的代码
要求:
1)输入记录:将每一 个教学设备编号,设备名称,生产厂家,购置日期,台数,单价,及备注作为一个记录,该软件能建立一个新的数据文件(用数组存放)或给以建立好的数据文件增加记录。
2)显示记录:根据用户提供的记录或根据设备编号显示一个或几个设备的记录。
3)修改记录:可以对数据的任意记录的数据进行修改并在修改后对记录内容进行显示。
4)删除记录:可以删除文件中的任意一个记录并且还可以恢复被删除的记录
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
class Shebei //定义一个设备类
{
private: //私有成员声明
string name; //设备名称
int name_num; //设备编号
string company; //生产厂家
int buytime; //购买时间
int taishu; //购买台数
int danjia; //设备单价
string zuoyong;//设备说明
public: //公有成员声明
void getdata() //输入设备信息
{ cin>>name>>name_num>>company>>
buytime>>taishu>>danjia>>zuoyong;}
void disp()//输出设备信息
{
cout<<left<<setw(12)<<name<<setw(8)
<<name_num<<company<<setw(12)<<setw(12)<<buytime
<<setw(12)<<taishu<<setw(12)<<danjia
<<setw(12)<<zuoyong<<endl;}
int getname_num() //调用设备编号
{return name_num;}
};
//设备信息显示
void outDate()
{ ifstream input("mynote.dat",ios::out);
Shebei shebei;
cout<<"显示记录:"<<endl;
cout<<left<<setw(12)<<"设备名称"<<setw(8)
<<"设备编号"<<setw(12)<<"生产厂家"<<setw(12)
<<"购买时间"<<setw(12)<<"台数"<<setw(12)
<<"单价"<<setw(12)<<"备注"<<endl; //输出设备信息
input.read((char*)&shebei,sizeof(shebei));
while(input)
{ shebei.disp();
input.read((char*)&shebei,sizeof(shebei));
}
}
//查找设备
void searchByName()
{ int sname_num;
bool ifFind=false;
Shebei shebei;
ifstream flie("myNote.dat");
flie.seekg(0);
cout<<"输入要查找的设备编号:"; //按编号查找
cin>>sname_num;
cout<<left<<setw(12)<<"设备名称"<<setw(8)
<<"设备编号"<<setw(12)<<"生产厂家"<<setw(12)
<<"购买时间"<<setw(12)<<"台数"<<setw(12)
<<"单价"<<setw(12)<<"备注"<<endl; //输出要查找的设备信息
while(flie.read((char*)&shebei,sizeof(shebei)))
{if(shebei.getname_num()==sname_num) //输入的编号与原设备编号对比
{shebei.disp();
ifFind=true;
break;
}
};
if(!ifFind) cout<<"没有该设备!"<<endl;
flie.close();
}
//增加设备记录
void addDate()
{ fstream file("mynote.dat",ios::out|ios::app);
Shebei shebei;
cout<<"增加记录(设备名称 设备编号 生产厂家 购买时间 台数 单价 备):"<<endl;
shebei.getdata();
file.write((char*)&shebei,sizeof(shebei)); //写入设备信息
file.close();
}
//主程序
void main()
{ int select;
do
{ cout<<"选择 (1:显示数据 2:按设备编号查找 3:增加设备 其他数字:退出):";
cin>>select;
switch(select)
{
case 1:outDate();break;
case 2:searchByName();break;
case 3:addDate();break;
default:break;
}
}while(select==1||select==2||select==3||select==4);
}