当前位置: 代码迷 >> C语言 >> 帮忙修改一下,好多错误啊 。
  详细解决方案

帮忙修改一下,好多错误啊 。

热度:514   发布时间:2008-06-25 12:55:39.0
帮忙修改一下,好多错误啊 。
#include<string.h>  
  #include<stdlib.h>
  #include<iomanip.h>  
  #include<stdio.h>  
  #include<conio.h>  
  #include<iostream.h>
  #include <fstream.h>
// #include  <TCHAR.h >
class Customer{
public:
    char m_ID[18];
    char m_name[10];
    int  m_age;
    char  m_sex[6];
    Customer(){};
    Customer(char *ID,char *name,int age,char *sex);
/*    void SaveCustomer(){
    fstream myfile1("customer.txt",ios::in|ios::out);
    Customer cus[5];
    for(int j=0;j<5;j++)
    {
        myfile1.write((char *)&cus,sizeof(cus));
    }
    myfile1.close();
    }*/

    void ShowCustomer(){
    cout<<m_ID<<"\t"<<m_name<<"\t"<<m_age<<"\t"<<m_sex<<endl;
    }
    };
    Customer::Customer(char *ID,char *name,int age,char *sex){
    strcpy(m_ID,ID);
    strcpy(m_name,name);
    m_age=age;
    strcpy(m_sex,sex);
    }
class Room{
public:
    int m_num;
    int m_floor;
    int m_price;
    int m_use;
    Room(){};
    Room(int num,int use);
    Room(int num,int floor,int price,int use);
/*    void SaveRoom(){
        fstream myfile2("room.txt",ios::in|ios::out);
        Room r[5];
    for(int j=0;j<count;j++)
    {
        myfile2.write((char *)&r,sizeof(r));
    }
    myfile2.close();
    }*/

    void ShowRoom(){
    cout<<m_num<<"\t"<<m_floor<<"\t"<<m_price<<"\t"<<m_use<<endl;
    }
};
    Room::Room(int num,int floor,int price,int use)
    {
    m_num=num;
    m_floor=floor;
    m_price=price;
    m_use=use;
    }
    Room::Room(int num,int use)
    {
    m_num=num;
    m_use=use;
    }

main()
{
  int count=5;
  Customer cus[5];
  Room    r[5];
  int i,j,age,num,floor,price,use;
  char ID[18],name[10],sex[6];
  fstream  myfile2("room.txt",ios::in|ios::out);
  fstream  myfile1("customer.txt",ios::in|ios::out);
  if(myfile2.is_open())
  {
  for(i=0;i<count;i++)
  {
  int id=100;
  r.m_num=i+100;
  r.m_floor=1;
  r.m_price=100;
  r.m_use=1;
  }
  myfile2.write((char *)&r,sizeof(r));
  myfile2.close();
  }
  else{cout<<"\n---文件打开失败--"<<endl;}
  for(;;)
  {
  cout<<"---------1.顾客登记---------"<<endl;
  cout<<"---------2.查询顾客信息---------"<<endl;
  cout<<"---------3.查询空房间---------"<<endl;
  cout<<"---------4.预订房间---------"<<endl;
  cout<<"---------5.退订房间---------"<<endl;
  cout<<"---------6.保存退出---------"<<endl;
  //cout<<"---------8.测试房间是否写入-----------"<<endl;
  //system("PAUSE");
  //exit(0);
  cout<<"  请选择操作:  "<<endl;
  cin>>i;
  fstream myfile2("room.txt",ios::in|ios::out);
  switch(i){
  case 1:
     if(count<=5){
     cout<<"请输入身份证号,姓名,年龄,性别:"<<endl;
     cin>>ID>>name>>age>>sex;
     cus=Customer(ID,name,age,sex);
     strcpy(cus.m_ID,ID);
      strcpy(cus.m_name,name);
     cus.m_age=age;
     strcpy(cus.m_sex,sex);
      myfile1.write((char*)&cus,sizeof(cus));
     myfile1.close();
     }else{cout<<"\n 存储空间已满!"<<endl;}
     cout<<"\n 你可以住在:"<<endl;
     for(i=0;i<count;i++){
         if(r.m_use=1){
         myfile2.read((char*)&r,sizeof(r));
         r.ShowRoom();
         }
         myfile2.close();
     }
      cout<<"\n 请你输入房间号:"<<endl;
     cin>>num;
     cout<<"\n 请确认使用(0->登记):  "<<endl;
     cin>>use;
     r=Room(num,use);
     r.m_num=num;
     r.m_use=use;
      for(i=0;i<count;i++){
         myfile2.write((char*)&r,sizeof(r));
         myfile2.close();
     }
     cout<<"\n 登记成功!"<<endl;
     //r.SaveRoom();
     // cus.SaveCustomer();
     break;

case 2:            //查询顾客信息
    if(count<=5){
    cout<<" 请输入身份证号:"<<endl;
    cin>>ID;
    for(i=0;i<count;i++){
        if(cus.m_ID==ID){
            myfile2.read((char*)&cus,sizeof(cus));
        cus.ShowCustomer();
        }
    }
    }else{cout<<"\n 错拉";}
    break;

case 3:            //查询空房间
    for(i=0;i<count;i++){
         if(r.m_use=1){
         myfile2.read((char*)&r,sizeof(r));
         r.ShowRoom();
         }
         myfile2.close();
     }//else{cout<<"\n 房间已满! "<<endl;}
        break;

case 4:          //预订房间
    if(count<=5){
     cout<<"请输入身份证号,姓名,年龄,性别:"<<endl;
     cin>>ID>>name>>age>>sex;
     cus=Customer(ID,name,age,sex);
     strcpy(cus.m_ID,ID);
      strcpy(cus.m_name,name);
     cus.m_age=age;
     strcpy(cus.m_sex,sex);
      myfile1.write((char*)&cus,sizeof(cus));
     myfile1.close();
     }else{cout<<"\n 住房已满!"<<endl;}
     cout<<"\n 你可以预订:"<<endl;
     for(i=0;i<count;i++){
         if(r.m_use=1){
         myfile2.read((char*)&r,sizeof(r));
         r.ShowRoom();
         }
         myfile2.close();
     }
      cout<<"\n 请你输入要预订的房间号:"<<endl;
     cin>>num;
     cout<<"\n 请确认使用(0->预订):  "<<endl;
     cin>>use;
     r=Room(num,use);
     r.m_num=num;
     r.m_use=use;
      for(i=0;i<count;i++){
         myfile2.write((char*)&r,sizeof(r));
         myfile2.close();
     }
     cout<<"\n 预订成功!"<<endl;
      break;

case 5:                  //退订房间
    cout<<"\n 请输入要退房顾客身份证:"<<endl;
    cin>>i;
    if(i<=count&&i>0){
        for(j=i;j<count;j++){cus[j-1]=cus;}
        count--;
        cout<<"\n 退房已成功!"<<endl;
    }else{cout<<"\n 输入错误!"<<endl;}
    break;

/*case 8:
      myfile2("room.txt",ios::in);
        for(int j=0;j<count;j++)
        {
        myfile2.read((char*)&r,sizeof(r));
        cout<<r[j.m_num<<"---"<<r[j].m_floor<<"---"<<r[j].m_price<<"---"<<r[j].m_use<<endl;
        }
        myfile2.close();
        break;
*/
case 6:
    fstream myfile1("customer.txt",ios::in|ios::out);
    for(j=0;j<count;j++){myfile1.write((char *)&cus,sizeof(cus));}
    myfile1.close();
    fstream myfile2("room.txt",ios::in|ios::out);
    for(j=0;j<count;j++){myfile2.write((char*)&r,sizeof(r));}
    myfile2.close();
    exit(0);
    }
  }
}
搜索更多相关的解决方案: ios  name  include  public  

----------------解决方案--------------------------------------------------------
Oh,so long!
You can give me 100RMB and I'll help you or you won't correct it there.
----------------解决方案--------------------------------------------------------
[bo][un]orzorz[/un] 在 2008-6-25 12:58 的发言:[/bo]

Oh,so long!
You can give me 100RMB and I'll help you or you won't correct it there.

比较恨假洋鬼子,尤其是收费的假洋鬼子。
我帮你改了。
申明:仅是编译通过,逻辑上正确性不明。

#include<string.h>  
#include<stdlib.h>
#include<iomanip>  
#include<stdio.h>  
#include<conio.h>  
#include<iostream>
#include <fstream>
using namespace std;
// #include  <TCHAR.h >
class Customer{
public:
    char m_ID[18];
    char m_name[10];
    int  m_age;
    char  m_sex[6];
    Customer(){};
    Customer(char *ID,char *name,int age,char *sex);
    /*    void SaveCustomer(){
    fstream myfile1("customer.txt",ios::in|ios::out);
    Customer cus[5];
    for(int j=0;j<5;j++)
    {
    myfile1.write((char *)&cus,sizeof(cus));
    }
    myfile1.close();
    }*/

    void ShowCustomer(){
        cout<<m_ID<<"\t"<<m_name<<"\t"<<m_age<<"\t"<<m_sex<<endl;
    }
};
Customer::Customer(char *ID,char *name,int age,char *sex){
    strcpy(m_ID,ID);
    strcpy(m_name,name);
    m_age=age;
    strcpy(m_sex,sex);
}
class Room{
public:
    int m_num;
    int m_floor;
    int m_price;
    int m_use;
    Room(){};
    Room(int num,int use);
    Room(int num,int floor,int price,int use);
    /*    void SaveRoom(){
    fstream myfile2("room.txt",ios::in|ios::out);
    Room r[5];
    for(int j=0;j<count;j++)
    {
    myfile2.write((char *)&r,sizeof(r));
    }
    myfile2.close();
    }*/

    void ShowRoom(){
        cout<<m_num<<"\t"<<m_floor<<"\t"<<m_price<<"\t"<<m_use<<endl;
    }
};
Room::Room(int num,int floor,int price,int use)
{
    m_num=num;
    m_floor=floor;
    m_price=price;
    m_use=use;
}
Room::Room(int num,int use)
{
    m_num=num;
    m_use=use;
}

void main()
{
    int count=5;
    Customer cus[5];
    Room    r[5];
    int i,j,age,num,floor,price,use;
    char ID[18],name[10],sex[6];
    fstream  myfile2("room.txt",ios::in|ios::out);
    fstream  myfile1("customer.txt",ios::in|ios::out);
    if(myfile2.is_open())
    {
        for(i=0;i<count;i++)
        {
            int id=100;
            r[i].m_num=i+100;
            r[i].m_floor=1;
            r[i].m_price=100;
            r[i].m_use=1;
        }
        myfile2.write((char *)&r,sizeof(r));
        myfile2.close();
    }
    else{cout<<"\n---文件打开失败--"<<endl;}
    for(;;)
    {
        cout<<"---------1.顾客登记---------"<<endl;
        cout<<"---------2.查询顾客信息---------"<<endl;
        cout<<"---------3.查询空房间---------"<<endl;
        cout<<"---------4.预订房间---------"<<endl;
        cout<<"---------5.退订房间---------"<<endl;
        cout<<"---------6.保存退出---------"<<endl;
        //cout<<"---------8.测试房间是否写入-----------"<<endl;
        //system("PAUSE");
        //exit(0);
        cout<<"  请选择操作:  "<<endl;
        cin>>i;
        fstream myfile2("room.txt",ios::in|ios::out);
        switch(i){
case 1:
    if(count<=5){
        cout<<"请输入身份证号,姓名,年龄,性别:"<<endl;
        cin>>ID>>name>>age>>sex;
        cus[count]=Customer(ID,name,age,sex);
        strcpy(cus[count].m_ID,ID);
        strcpy(cus[count].m_name,name);
        cus[count].m_age=age;
        strcpy(cus[count].m_sex,sex);
        myfile1.write((char*)&cus[count],sizeof(cus[count]));
        myfile1.close();
    }else{cout<<"\n 存储空间已满!"<<endl;}
    cout<<"\n 你可以住在:"<<endl;
    for(i=0;i<count;i++){
        if(r[i].m_use=1){
            myfile2.read((char*)&r[i],sizeof(r[i]));
            r[i].ShowRoom();
        }
        myfile2.close();
    }
    cout<<"\n 请你输入房间号:"<<endl;
    cin>>num;
    cout<<"\n 请确认使用(0->登记):  "<<endl;
    cin>>use;
    r[count]=Room(num,use);
    r[count].m_num=num;
    r[count].m_use=use;
    for(i=0;i<count;i++){
        myfile2.write((char*)&r[i],sizeof(r[i]));
        myfile2.close();
    }
    cout<<"\n 登记成功!"<<endl;
    //r.SaveRoom();
    // cus.SaveCustomer();
    break;

case 2:            //查询顾客信息
    if(count<=5){
        cout<<" 请输入身份证号:"<<endl;
        cin>>ID;
        for(i=0;i<count;i++){
            if(cus[i].m_ID==ID){
                myfile2.read((char*)&cus[i],sizeof(cus[i]));
                cus[i].ShowCustomer();
            }
        }
    }else{cout<<"\n 错拉";}
    break;

case 3:            //查询空房间
    for(i=0;i<count;i++){
        if(r[i].m_use=1){
            myfile2.read((char*)&r[i],sizeof(r[i]));
            r[i].ShowRoom();
        }
        myfile2.close();
    }//else{cout<<"\n 房间已满! "<<endl;}
    break;

case 4:          //预订房间
    if(count<=5){
        cout<<"请输入身份证号,姓名,年龄,性别:"<<endl;
        cin>>ID>>name>>age>>sex;
        cus[count]=Customer(ID,name,age,sex);
        strcpy(cus[count].m_ID,ID);
        strcpy(cus[count].m_name,name);
        cus[count].m_age=age;
        strcpy(cus[count].m_sex,sex);
        myfile1.write((char*)&cus[count],sizeof(cus[count]));
        myfile1.close();
    }else{cout<<"\n 住房已满!"<<endl;}
    cout<<"\n 你可以预订:"<<endl;
    for(i=0;i<count;i++){
        if(r[i].m_use=1){
            myfile2.read((char*)&r[i],sizeof(r[i]));
            r[i].ShowRoom();
        }
        myfile2.close();
    }
    cout<<"\n 请你输入要预订的房间号:"<<endl;
    cin>>num;
    cout<<"\n 请确认使用(0->预订):  "<<endl;
    cin>>use;
    r[count]=Room(num,use);
    r[count].m_num=num;
    r[count].m_use=use;
    for(i=0;i<count;i++){
        myfile2.write((char*)&r[i],sizeof(r[i]));
        myfile2.close();
    }
    cout<<"\n 预订成功!"<<endl;
    break;

case 5:                  //退订房间
    cout<<"\n 请输入要退房顾客身份证:"<<endl;
    cin>>i;
    if(i<=count&&i>0){
        for(j=i;j<count;j++){cus[j-1]=cus[j];}
        count--;
        cout<<"\n 退房已成功!"<<endl;
    }else{cout<<"\n 输入错误!"<<endl;}
    break;

    /*case 8:
    myfile2("room.txt",ios::in);
    for(int j=0;j<count;j++)
    {
    myfile2.read((char*)&r,sizeof(r));
    cout<<r[j.m_num<<"---"<<r[j].m_floor<<"---"<<r[j].m_price<<"---"<<r[j].m_use<<endl;
    }
    myfile2.close();
    break;
    */
case 6:
    fstream myfile1("customer.txt",ios::in|ios::out);
    for(j=0;j<count;j++){myfile1.write((char *)&cus,sizeof(cus));}
    myfile1.close();
    fstream myfile2("room.txt",ios::in|ios::out);
    for(j=0;j<count;j++){myfile2.write((char*)&r,sizeof(r));}
    myfile2.close();
    exit(0);
        }
    }
}
----------------解决方案--------------------------------------------------------
回复 2# orzorz 的帖子
呵呵,又是你啊,
----------------解决方案--------------------------------------------------------
回复 3# woshiyun 的帖子
恩,同感,非常感谢。
----------------解决方案--------------------------------------------------------
  相关解决方案