欢迎来到天天文库
浏览记录
ID:40531686
大小:48.50 KB
页数:10页
时间:2019-08-04
《C++代码设备信息管理系统64047906》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#include#include#includeusingnamespacestd;structequipment{intid;//设备编号charname[25];//名称charmodel[25];//型号intprice;//价格chardate[10];//购买日期};//动态数组类模板///////////////////////////////////////templateclassArray{private:T*po
2、inter;intsize;intcapacity;voidcapacity_increase();public:Array():pointer(0),size(0),capacity(0){};explicitArray(int);Array(constArray&);~Array(){delete[]pointer;};intlength(){returnsize;};//长度constArray&operator=(constArray&);T&operator[](intn){if(n>=size
3、
4、n<0){cerr<<"数组中无该元素"<5、{returnpointer[n];}};T*operator+(intn){returnpointer+n;};voidinsert(intn,TpT);//在第n(n从0开始计)个元素前面插入pTvoiderase(intn);//删除第n个元素voidpush_back(T);//从后插入voidprint(){//打印for(inti=0;iArray::Array(intn){pointer=newT[capacity=(s6、ize=n)*2];}templateArray::Array(constArray&rh){pointer=newT[rh.capacity];size=rh.size;for(inti=0;iconstArray&Array::operator=(constArray&rh){delete[]pointer;size=rh.size;capacity=rh.capa7、city;pointer=newT[rh.capacity];for(inti=0;ivoidArray::capacity_increase(){if(capacity==0){capacity=1;}T*temp=newT[capacity*=2];for(inti=0;i8、eT>voidArray::push_back(TpT){if(size==capacity){capacity_increase();}pointer[size++]=pT;}templatevoidArray::insert(intn,TpT){if(n>=size9、10、n<0){cerr<<"InsertError"<n;i--){pointer[i]=pointer[i-1];}pointer[n]11、=pT;}templatevoidArray::erase(intn){if(n>=size12、13、n<0){cout<<"EraseError"<
5、{returnpointer[n];}};T*operator+(intn){returnpointer+n;};voidinsert(intn,TpT);//在第n(n从0开始计)个元素前面插入pTvoiderase(intn);//删除第n个元素voidpush_back(T);//从后插入voidprint(){//打印for(inti=0;iArray::Array(intn){pointer=newT[capacity=(s
6、ize=n)*2];}templateArray::Array(constArray&rh){pointer=newT[rh.capacity];size=rh.size;for(inti=0;iconstArray&Array::operator=(constArray&rh){delete[]pointer;size=rh.size;capacity=rh.capa
7、city;pointer=newT[rh.capacity];for(inti=0;ivoidArray::capacity_increase(){if(capacity==0){capacity=1;}T*temp=newT[capacity*=2];for(inti=0;i8、eT>voidArray::push_back(TpT){if(size==capacity){capacity_increase();}pointer[size++]=pT;}templatevoidArray::insert(intn,TpT){if(n>=size9、10、n<0){cerr<<"InsertError"<n;i--){pointer[i]=pointer[i-1];}pointer[n]11、=pT;}templatevoidArray::erase(intn){if(n>=size12、13、n<0){cout<<"EraseError"<
8、eT>voidArray::push_back(TpT){if(size==capacity){capacity_increase();}pointer[size++]=pT;}templatevoidArray::insert(intn,TpT){if(n>=size
9、
10、n<0){cerr<<"InsertError"<n;i--){pointer[i]=pointer[i-1];}pointer[n]
11、=pT;}templatevoidArray::erase(intn){if(n>=size
12、
13、n<0){cout<<"EraseError"<
此文档下载收益归作者所有