#include <iostream>
#include <string>
using namespace std;
struct fileinfo{
string id;
string name;
string type;
string date;
long size;
struct fileinfo *next;
};
typedef struct fileinfo FI;
FI *f=0;
void add(){
FI *p;
if(f==0){
f=new FI;
f->next=0;
p=f;
}
else{
p=f;
while(p->next!=0) p=p->next;
p->next=new FI;
p=p->next;
p->next=0;
}
cout<<"輸入文件號: ";
cin>>p->id;
cout<<"輸入文件名: ";
cin>>p->name;
cout<<"輸入文件屬性: ";
cin>>p->type;
cout<<"輸入文件創建日期: ";
cin>>p->date;
cout<<"輸入文件大小: ";
cin>>p->size;
}
void display(){
FI *p;
p=f;
cout<<"文件號 文件名 文件屬性 創建日期 大小(Byte)"<<endl;
while(p!=0){
cout<<p->id<<""<<p->name<<""<<p->type<<""<<p->date<<""<<p->size<<endl;
p=p->next;
}
}
void modify(){
FI *p;
string id;
cout<<"輸入文件號: ";
cin>>id;
p=f;
while(p!=0&&(p->id)!=id) p=p->next;
if(p==0) cout<<"此文件不存在。"<<endl;
else{
cout<<"文件號 文件名 文件屬性 創建日期 大小(Byte)"<<endl;
cout<<p->id<<""<<p->name<<""<<p->type<<""<<p->date<<""<<p->size<<endl;
int c;
cout<<"1.文件號 2.文件名 3.文件屬性 4.創建日期 5.大小"<<endl;;
cout<<"修改哪壹項?";
cin>>c;
if(c==1){
cout<<"輸入文件號: ";
cin>>p->id;
}
else if(c==2){
cout<<"輸入文件名: ";
cin>>p->name;
}
else if(c==3){
cout<<"輸入文件屬性: ";
cin>>p->type;
}
else if(c==4){
cout<<"輸入文件創建日期: ";
cin>>p->date;
}
else if(c==5){
cout<<"輸入文件大小: ";
cin>>p->size;
}
cout<<"文件號 文件名 文件屬性 創建日期 大小(Byte)"<<endl;
cout<<p->id<<" "<<p->name<<" "<<p->type<<" "<<p->date<<" "<<p->size<<endl;
}
}
void search(int c){
FI *p;
p=f;
if(c==1){
string name;
cout<<"輸入文件名: ";
cin>>name;
cout<<"文件號 文件名 文件屬性 創建日期 大小(Byte)"<<endl;
while(p!=0){
if((p->name)==name) cout<<p->id<<" "<<p->name<<" "<<p->type<<" "<<p->date<<" "<<p->size<<endl;
p=p->next;
}
}
else if(c==2){
string type;
cout<<"輸入文件屬性: ";
cin>>type;
cout<<"文件號 文件名 文件屬性 創建日期 大小(Byte)"<<endl;
while(p!=0){
if((p->type)==type) cout<<p->id<<" "<<p->name<<" "<<p->type<<" "<<p->date<<" "<<p->size<<endl;
p=p->next;
}
}
}
int main(){
int c;
do{
cout<<"(1)瀏覽數據 (2)增加數據 (3)修改數據 (4)查詢數據 (5)退出"<<endl;
cout<<"選擇哪項操作: ";
cin>>c;
if(c==1){
display();
}
else if(c==2){
add();
}
else if(c==3){
modify();
}
else if(c==4){
int i;
cout<<"1.文件名 2.文件屬性"<<endl;
cout<<"選擇哪項進行查詢: ";
cin>>i;
search(i);
}
else{
FI *p;
while(f!=0){
p=f->next;
delete f;
f=p;
}
break;
}
}while(1);
return 0;
}