| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 309 人关注过本帖
标题:c对txt的添加 修改 和 条件查询。。。
取消只看楼主 加入收藏
woshihsz
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2011-9-2
结帖率:50%
收藏
 问题点数:0 回复次数:0 
c对txt的添加 修改 和 条件查询。。。
c对txt的添加 修改 和 条件查询。。。
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

struct guest
{
string id;
string name;
string address;
string date;
string ps;
guest(string i,string p,string a,string d,string s):id(i),name(p),address(a),date(d),ps(s) {next = NULL;}
guest* next;};

class guest_mgr{
private:
guest* head;
public:
  guest_mgr();
  bool add_people(string id,string name,string address,string date,string ps);
  bool alt_people(string id,string name,string address,string date,string ps);
  bool look_file(string filename);
  void print_people();
  ~guest_mgr();
}



bool guest_mgr::add_people(string id,string name,string address,string date,string ps){
if(NULL==head)
  return false;
guest* p = head;
while(NULL!=p->next){
  p = p->next;
}
guest* newguest = new guest(id,name,address,date,ps);
p->next = newguest;
newguest->next = NULL;
return true;
}

bool guest_mgr::look_file(string filename)
{
if stream inobj(filename.c_str());
if(!inobj){
  cout<<"open file failed.\n";
  return false;
}
guest *t,*p;
string sid,sname,saddress,sdate,sps;
p = head;
while(!inobj.eof()){  
  inobj>>sid>>sname>>saddress>>sdate>>sps;
  t = new guest(sid,sname,saddress,sdate,sps);
  p->next = t;
  p = t;
}
t->next = NULL;
return true;
}

bool guest_mgr::chk_people(string id){
if(NULL==head)
  return false;
guest *p = head;
while(NULL!=p->next&&id!=p->id){
  p = p->next;  
}
if(NULL!=p->next){
  return true;
}
else if(NULL==p->next&&id==p->id)
  return true;
return false;
}

bool guest_mgr::chk_people(string id,string name,string address,string date,string ps){
if(NULL==head)
  return false;
guest *p = head;
while(NULL!=p->next&&id!=p->id){
  p = p->next;  
}
if(NULL!=p->next){
  if(name==p->name)
   return true;
}
else if(NULL==p->next&&id==p->id)
  if(name==p->name)
   return true;
return false;
}


void guest_mgr::print_people(){
if(NULL==head){
  cout<<"no guest in the list.\n";
  return;
}
guest* p = head;
while(NULL!=p){
  cout<<p->id<<" "<<p->name<<" "<<p->address" "<<p->date" "p->ps<<"\n";
  p=p->next;
}
cout<<endl;
}

guest_mgr* mylist;//在菜单函数中要用到,不要移动它
string fn = "data.txt";//同上

void add(){
cout<<"\n-------------------Add Guest----------------------\n";
string id,name,address,date,contents,ps;
  cout<<"ID:";
cin>>id;
  cout<<"name:";
cin>>name;
  cout<<"Address:";
cin>>address;
  cout<<"Date:";
cin>>date;
  cout<<"Contents:";
cin>>contents;
  cout<<"Ps:";
cin>>ps;
if(mylist->add_people(id,name,address,date,contents,ps)){
  cout<<"\nadd guest successful.\n";
}
else{
  cout<<"sorry,the system is wrong.\n";
}
cout<<"\n-------------------Add Guest----------------------\n";
}



void menu(){
int c;
cout<<"\n****************************Main Menu****************************\n";
cout<<"1.添加信息\t2.修改信息\t3.查询信息\t4.退出";
cout<<"\n****************************Main Menu****************************\n";
cin>>c;
switch(c){
case 1:add();break;
case 2:look();break;
case 3:look();break;
default:mylist->write_file(fn);exit(0);
}
}

void main(){
mylist = new guest_mgr();
mylist->look_file(fn);
while(1)
  menu();
cout<<endl;
}


我想实现 c对txt的添加 修改 和 条件查询。。。。
怎么改?
搜索更多相关主题的帖子: private address include 
2011-09-02 15:19
快速回复:c对txt的添加 修改 和 条件查询。。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049647 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved