| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1701 人关注过本帖
标题:各位大哥大姐帮我看看这个程序问题在哪好不好??
只看楼主 加入收藏
ntdom
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2008-3-10
收藏
 问题点数:0 回复次数:12 
各位大哥大姐帮我看看这个程序问题在哪好不好??
  还没写 完  已经漏洞百出了 我郁闷啊

#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <string.h>
#include <ctime>
#include <cstdlib>

void choose(char);
void menu();
int montoday(int,int);
int days(int,int,int);
bool choose_a(char *);

const int LENname=6;
const int LENIDc=18;
const int LENnat=6;
const int MAXroom=500;
const int LENphone=11;

class GuestDate{
    char name[LENname];
    char sex[2];
    char IDc[LENIDc];
    char nat[LENnat];
    char phone[LENphone];
    int roomID;
    int delTag;
public:
    GuestDate() {delTag=0;}
    int year;
    int mon;
    int day;
    char *getname()            {return name;}
    char *getsex()            {return sex;}
    char *getIDc()            {return IDc;}
    char *getnat()            {return nat;}
    char *getphone()        {return phone;}
    int getdelTag()        {return delTag;}
    int  getroomID()        {return roomID;}
    void setname(char na[])     {strcpy(name,na);}
    void setsex(char na[])         {strcpy(sex,na);}
    void setIDc(char na[])         {strcpy(IDc,na);}
    void setnat(char na[])         {strcpy(nat,na);}
    void setphone(char na[])     {strcpy(phone,na);}
    void setroomID(int na)        {roomID=na;}
    void del()             {delTag=0;}
    void unDel()             {delTag=1;}
    };

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class GuestWay{
public:
    GuestDate guest[MAXroom];
    void showdate(int);
    void showdate();
    void save();
    void open();
    void newfile();
    void del(int roomID)
    {
        guest[roomID].del();
    }
    int roomIDscan(int roomID){
        if(1==guest[roomID].getdelTag()) return 1;
        return 0;
    }
    void IDcscan(char []);

};

void GuestWay::showdate(int i)
    {    
        cout.flags(ios::left);
        cout<<setw(8)<<guest[i].getname()
                <<setw(4)<<guest[i].getsex()
                <<setw(20)<<guest[i].getIDc()
                <<setw(8)<<guest[i].getnat()
                <<setw(9)<<guest[i].getphone()
              <<setw(6)<<guest[i].getroomID()
              <<endl;
    }

void GuestWay::showdate()
    {
        cout.flags(ios::left);
        cout<<setw(8)<<"姓名"
            <<setw(6)<<"性别"
            <<setw(20)<<"身份证"
            <<setw(8)<<"籍贯"
            <<setw(14)<<"手机号"
            <<setw(6)<<"房间"
            <<endl;
        for(int i=1;i<MAXroom;i++)
            if(guest[i].getdelTag()==1)
                showdate(i);
    }

void GuestWay::save()
    {
        fstream f("GusetDate.date",ios::in|ios::binary);
        for(int i=1;i<MAXroom;i++)
            f.write((char*)&guest[i],sizeof(guest[i]));
        f.close();
    }
void GuestWay::open()
    {
        fstream f("GusetDate.date",ios::in|ios::binary);
        int roomID=0;
        for(;;)
            {
                if(!f)
                    break;
                roomID++;
                f.seekg(roomID*sizeof(guest[roomID]));
                f.read((char*)&guest[roomID],sizeof(guest[roomID]));
            }
        f.close();
    }

void GuestWay::IDcscan(char IDc[])
    {
    for(int i=1;i<=MAXroom;i++)
        {
        if (0==strcmp(guest[i].getIDc(),IDc)) GuestWay::showdate(i);
        else cout<<"没有入住该旅客"<<endl;
        }
    }

void GuestWay::newfile()
    {
        int roomID;
        char name[LENname];
        char sex[2];
        char IDc[LENIDc];
        char nat[LENnat];
        char phone[LENphone];
        for(;;){
            cout<<"输入房间"<<endl;
            cin>>roomID;
            if(0==GuestWay::roomIDscan(roomID) && roomID<MAXroom)
                guest[roomID].setroomID(roomID);
            else {
                cout<<"该房间已有人"<<endl;
                break;
            }
            cout<<"输入姓名"<<endl;
            cin>>name; guest[roomID].setname(name);
            cout<<"输入性别"<<endl;
            cin>>sex;
            guest[roomID].setsex(sex);
            cout<<"输入身份证"<<endl;
            cin>>IDc;
            guest[roomID].setIDc(IDc);
            cout<<"输入籍贯"<<endl;
            cin>>nat;
            guest[roomID].setnat(nat);
            cout<<"输入手机号"<<endl;
            cin>>phone;
            guest[roomID].setphone(phone);
            guest[roomID].year=0;
            guest[roomID].mon=0;
            guest[roomID].day=0;
            guest[roomID].unDel();
            break;
        }
        for(int i=1;i<roomID;i++){
            if(1==guest[i].getdelTag() && guest[roomID].getroomID() < guest[i].getroomID()){
                GuestDate temp;
                temp=guest[i];
                guest[i]=guest[roomID];
                guest[roomID]=temp;
            }
        }
    }

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void menu()
{
    cout<<"按1入住"<<"  "
        <<"按2退房"<<"  "
        <<"按3显示住房信息"<<"  "
        <<"按4房间查询"<<"  "
        <<"按5身份证查询"<<"  "
        <<"按q退出"<<"  "<<endl;
}

void choose(char key){
    GuestWay guest;
    guest.open();
    switch(key){
        case 49 :
            //guest.open();
            guest.newfile();
            //guest.save();
            break;
        case 50 :
            //guest.open();
            cout<<"输入房间"<<endl;
            int roomID;
            cin>>roomID;
            if(0==guest.roomIDscan(roomID)) {
                cout<<"该房间没有人"<<endl;
                break;
            }
            else
            {
                guest.del(roomID);
                //guest.save();
            }
            break;
        case 51 :
            //guest.open();
            guest.showdate();
            break;
        case 52 :
            //guest.open();
            cout<<"输入房间"<<endl;
            cin>>roomID;
            if(0==guest.roomIDscan(roomID)) {
                cout<<"该房间没有人"<<endl;
                break;
            }
            else    guest.showdate(roomID);
            break;
        case 53 :
            char IDc[18];
            cin>>IDc;
            guest.IDcscan(IDc);
            break;
        case 113: exit(0);
        default : cout<<"输入错误,重新输入"<<endl;
    }
    guest.save();
}

int montoday(int year,int mon){
    int day;
    switch(mon){
        case 1 :
        case 3 :
        case 5 :
        case 7 :
        case 8 :
        case 10:
        case 12:
            day=31;break;
        case 4 :
        case 6 :
        case 9 :
        case 11:
            day=30;break;
        case 2 :
            if( year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
                day=29;
            else
                day=28;
    }
    return day;
}

int days(int year,int mon,int day){
    return montoday(year,mon)+day;
}

bool choose_a(char *p){
int k=0;
while(*p) {p++;k++;}
if (k==1) return true;
else return false;
}

void main()
{
    menu();
    while(1)
    {
        char key[10];
        cin>>key;
        if (choose_a(key))        
            {
            choose(key[0]);
            menu();
            }
        else {cout<<"输入错误"<<endl;menu();}
    }
}
搜索更多相关主题的帖子: int include 大姐 const 
2008-08-19 10:01
ntdom
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2008-3-10
收藏
得分:0 
小做修改后。。。。
#include <fstream.h>
#include <iomanip.h>
#include <string.h>
#include <ctime>
#include <cstdlib>

void choose(char);
void menu();
int montoday(int,int);
int days(int,int,int);
bool choose_a(char *);

const int LENname=6;
const int LENIDc=18;
const int LENnat=6;
const int MAXroom=500;
const int LENphone=11;

class GuestDate{
    char name[LENname];
    char sex[2];
    char IDc[LENIDc];
    char nat[LENnat];
    char phone[LENphone];
    int roomID;
    int delTag;
public:
    GuestDate() {delTag=0;}
    int year;
    int mon;
    int day;
    char *getname()            {return name;}
    char *getsex()            {return sex;}
    char *getIDc()            {return IDc;}
    char *getnat()            {return nat;}
    char *getphone()        {return phone;}
    int getdelTag()        {return delTag;}
    int  getroomID()        {return roomID;}
    void setname(char na[])     {strcpy(name,na);}
    void setsex(char na[])         {strcpy(sex,na);}
    void setIDc(char na[])         {strcpy(IDc,na);}
    void setnat(char na[])         {strcpy(nat,na);}
    void setphone(char na[])     {strcpy(phone,na);}
    void setroomID(int na)        {roomID=na;}
    void del()             {delTag=0;}
    void unDel()             {delTag=1;}
    };

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class GuestWay{
public:
    GuestDate guest[MAXroom];
    void showdate(int);
    void showdate();
    void save();
    void open();
    void newfile();
    void del(int roomID)
    {
        guest[roomID].del();
        GuestWay::save();
    }
    int roomIDscan(int roomID){
        if(1==guest[roomID].getdelTag()) return 1;
        return 0;
    }
    void IDcscan(char []);

} guest ;

void GuestWay::showdate(int i)
    {    
        cout.flags(ios::left);
        cout<<setw(8)<<guest[i].getname()
                <<setw(4)<<guest[i].getsex()
                <<setw(20)<<guest[i].getIDc()
                <<setw(8)<<guest[i].getnat()
                <<setw(9)<<guest[i].getphone()
              <<setw(6)<<guest[i].getroomID()
              <<endl;
    }

void GuestWay::showdate()
    {
        cout.flags(ios::left);
        cout<<setw(8)<<"姓名"
            <<setw(6)<<"性别"
            <<setw(20)<<"身份证"
            <<setw(8)<<"籍贯"
            <<setw(14)<<"手机号"
            <<setw(6)<<"房间"
            <<endl;
        for(int i=1;i<MAXroom;i++)
            if(guest[i].getdelTag()==1)
                showdate(i);
    }

void GuestWay::save()
    {
        fstream f("GusetDate.bin",ios::in|ios::binary);
        for(int roomID=1;roomID<=MAXroom;roomID++)
            f.write((char*)&guest[roomID],sizeof(guest[roomID]));
        f.close();
    }
void GuestWay::open()
    {
    fstream f("GusetDate.bin",ios::out|ios::binary);
        int roomID=0;
        for(;;)
            {
                if(roomID>MAXroom)
                    break;
                roomID++;
                f.seekg((roomID-1)*sizeof(guest[roomID]));
                f.read((char*)&guest[roomID],sizeof(guest[roomID]));
            }
        f.close();
    }

void GuestWay::IDcscan(char IDc[])
    {
    for(int i=1;i<=MAXroom;i++)
        {
        if (0==strcmp(guest[i].getIDc(),IDc)) {
            cout.flags(ios::left);
            cout<<setw(8)<<"姓名"
                <<setw(6)<<"性别"
                <<setw(20)<<"身份证"
                <<setw(8)<<"籍贯"
                <<setw(14)<<"手机号"
                <<setw(6)<<"房间"
                <<endl;
            GuestWay::showdate(i);
            break;
        }
        else if(i==MAXroom) cout<<"没有入住该旅客"<<endl;
        }
    }

void GuestWay::newfile()
    {
        int roomID;
        char name[LENname];
        char sex[2];
        char IDc[LENIDc];
        char nat[LENnat];
        char phone[LENphone];
        for(;;){
            cout<<"输入房间"<<endl;
            cin>>roomID;
            if(0==GuestWay::roomIDscan(roomID) && roomID<MAXroom)
                guest[roomID].setroomID(roomID);
            else {
                cout<<"该房间已有人"<<endl;
                break;
            }
            cout<<"输入姓名"<<endl;
            cin>>name; guest[roomID].setname(name);
            cout<<"输入性别"<<endl;
            cin>>sex;
            guest[roomID].setsex(sex);
            cout<<"输入身份证"<<endl;
            cin>>IDc;
            guest[roomID].setIDc(IDc);
            cout<<"输入籍贯"<<endl;
            cin>>nat;
            guest[roomID].setnat(nat);
            cout<<"输入手机号"<<endl;
            cin>>phone;
            guest[roomID].setphone(phone);
            guest[roomID].year=0;
            guest[roomID].mon=0;
            guest[roomID].day=0;
            guest[roomID].unDel();
            break;
        }
        for(int i=1;i<roomID;i++){
            if(1==guest[i].getdelTag() && guest[roomID].getroomID() < guest[i].getroomID()){
                GuestDate temp;
                temp=guest[i];
                guest[i]=guest[roomID];
                guest[roomID]=temp;
            }
        GuestWay::save();
        }
    }

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void menu()
{
    cout<<"按1入住"<<"  "
        <<"按2退房"<<"  "
        <<"按3显示住房信息"<<"  "
        <<"按4房间查询"<<"  "
        <<"按5身份证查询"<<"  "
        <<"按q退出"<<"  "<<endl;
}

void choose(char key){
    guest.open();
    switch(key){
        case 49 :
            guest.newfile();
            break;
        case 50 :
            cout<<"输入房间"<<endl;
            int roomID;
            cin>>roomID;
            if(0==guest.roomIDscan(roomID)) {
                cout<<"该房间没有人"<<endl;
                break;
            }
            else guest.del(roomID);
            break;
        case 51 :
            guest.showdate();
            break;
        case 52 :
            cout<<"输入房间"<<endl;
            cin>>roomID;
            if(0==guest.roomIDscan(roomID)) {
                cout<<"该房间没有人"<<endl;
                break;
            }
            else    {
                cout.flags(ios::left);
                cout<<setw(8)<<"姓名"
                     <<setw(6)<<"性别"
                    <<setw(20)<<"身份证"
                      <<setw(8)<<"籍贯"
                    <<setw(14)<<"手机号"
                    <<setw(6)<<"房间"
                    <<endl;
                guest.showdate(roomID);
                break;
                }
        case 53 :
            char IDc[18];
            cout<<"输入身份证"<<endl;
            cin>>IDc;
            guest.IDcscan(IDc);
            break;
        case 113:
            exit(0);
        default : cout<<"输入错误,重新输入"<<endl;
    }
}

int montoday(int year,int mon){
    int day;
    switch(mon){
        case 1 :
        case 3 :
        case 5 :
        case 7 :
        case 8 :
        case 10:
        case 12:
            day=31;break;
        case 4 :
        case 6 :
        case 9 :
        case 11:
            day=30;break;
        case 2 :
            if( year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
                day=29;
            else
                day=28;
    }
    return day;
}

int days(int year,int mon,int day){
    return montoday(year,mon)+day;
}

bool choose_a(char *p){
int k=0;
while(*p) {p++;k++;}
if (k==1) return true;
else return false;
}

void main()
{
    menu();
    while(1)
    {
        char key[10];
        cin>>key;
        if (choose_a(key))        
            {
            choose(key[0]);
            menu();
            }
        else {cout<<"输入错误"<<endl;menu();}
    }
}

网络幽灵.....
2008-08-19 14:03
elegant87
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2008-1-15
收藏
得分:0 
程序挺好的啊!没什么问题!可以运行的!但结果不是很正确的!把你问题说清楚吧!
2008-08-19 21:10
thynson
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-9-16
收藏
得分:0 
很坦诚的说,当我看到
char *getname(){return name;}
这一句以及以下的几句时,我就认为你在类的运用上还欠火候。
好一些的方法是
void show_name(){ cout<<name;}
在下面一个地方这样用
show_name();
show_sex();
show_XXX();
...

    总之不要在类的成员函数中返回一个类的指针或引用。这个getname完全是多余的,既然你这样用,何必吧name作为一个公开的数据成员呢。我想你的这份代码不需要修改,而是需要重新设计。更严实的封装会让你的代码更明了,从而降低了出错的可能

[[it] 本帖最后由 thynson 于 2008-8-19 22:20 编辑 [/it]]
2008-08-19 22:03
ntdom
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2008-3-10
收藏
得分:0 
name是私有成员啊
不过我的c++学习的确实不是很久

导致有很多都 不明白
这个代码我又改了下

现在的问题很奇怪

第一次运行的时候什么问题都没有
但第二次及以后就什么操作都没有用了

#include <fstream.h>
#include <iomanip.h>
#include <string.h>
#include <ctime>
#include <cstdlib>

void choose(char);
void menu();
void money(int);
int montoday(int,int);
int days(int,int,int);
int inday(int,int,int);
bool choose_a(char *);

const int LENname=8;
const int LENIDc=20;
const int LENsex=4;
const int LENnat=8;
const int MAXroom=500;
const int LENphone=14;

class GuestDate{
    char name[LENname];
    char sex[LENsex];
    char IDc[LENIDc];
    char nat[LENnat];
    char phone[LENphone];
    int roomID;
    int delTag;
public:
    GuestDate() {delTag=0;}
    int year;
    int mon;
    int day;
    char *getname()            {return name;}
    char *getsex()            {return sex;}
    char *getIDc()            {return IDc;}
    char *getnat()            {return nat;}
    char *getphone()        {return phone;}
    int getdelTag()        {return delTag;}
    int  getroomID()        {return roomID;}
    void setname(char na[])     {strcpy(name,na);}
    void setsex(char na[])         {strcpy(sex,na);}
    void setIDc(char na[])         {strcpy(IDc,na);}
    void setnat(char na[])         {strcpy(nat,na);}
    void setphone(char na[])     {strcpy(phone,na);}
    void setroomID(int na)        {roomID=na;}
    void del()             {delTag=0;}
    void unDel()             {delTag=1;}
    };

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class GuestWay{
public:
    GuestDate guest[MAXroom];
    void showdate(int);
    void showdate();
    void save();
    void open();
    void newfile();
    void del(int roomID)
    {
        guest[roomID].del();
    }
    int roomIDscan(int roomID){
        if(1==guest[roomID].getdelTag()) return 1;
        return 0;
    }
    void IDcscan(char []);

} guest ;

void GuestWay::showdate(int i)
    {    
        cout.flags(ios::left);
        cout<<setw(8)<<guest[i].getname()
                <<setw(6)<<guest[i].getsex()
                <<setw(20)<<guest[i].getIDc()
                <<setw(8)<<guest[i].getnat()
                <<setw(14)<<guest[i].getphone()
                  <<setw(6)<<guest[i].getroomID()
                  <<guest[i].year<<"."
                <<guest[i].mon<<"."
                <<setw(5)<<guest[i].day
                <<setw(3)<<inday(guest[i].year,guest[i].mon,guest[i].day)
                <<endl;
    }

void GuestWay::showdate()
    {
        cout.flags(ios::left);
            cout<<setw(8)<<"姓名"
                <<setw(6)<<"性别"
                <<setw(20)<<"身份证"
                <<setw(8)<<"籍贯"
                <<setw(14)<<"手机号"
                <<setw(6)<<"房号"
                <<setw(12)<<"入住时间"
                <<setw(3)<<"天数"
                <<endl;
        for(int i=1;i<MAXroom;i++)
            if(guest[i].getdelTag()==1)
                showdate(i);
    }

void GuestWay::save()
    {
        fstream f("GusetDate.bin",ios::out|ios::binary);
        for(int roomID=1;roomID<=MAXroom;roomID++)
            f.write((char*)&guest[roomID],sizeof(guest[roomID]));
        f.close();
    }
void GuestWay::open()
    {
    fstream f("GusetDate.bin",ios::in|ios::binary);
        int roomID=0;
        for(;;)
            {
                if(roomID>MAXroom)
                    break;
                roomID++;
                f.seekg((roomID-1)*sizeof(guest[roomID]));
                f.read((char*)&guest[roomID],sizeof(guest[roomID]));
            }
        f.close();
    }

void GuestWay::IDcscan(char IDc[])
    {
    for(int i=1;i<=MAXroom;i++)
        {
        if (0==strcmp(guest[i].getIDc(),IDc)) {
            cout.flags(ios::left);
            cout<<setw(8)<<"姓名"
                <<setw(6)<<"性别"
                <<setw(20)<<"身份证"
                <<setw(8)<<"籍贯"
                <<setw(14)<<"手机号"
                <<setw(6)<<"房号"
                <<setw(12)<<"入住时间"
                <<setw(3)<<"天数"
                <<endl;
            GuestWay::showdate(i);
            break;
        }
        else if(i==MAXroom) cout<<"没有入住该旅客"<<endl;
        }
    }

void GuestWay::newfile()
    {
        int roomID;
        char name[LENname];
        char sex[LENsex];
        char IDc[LENIDc];
        char nat[LENnat];
        char phone[LENphone];
        for(;;){time_t t=time(0);
            cout<<"输入房间"<<endl;
            cin>>roomID;
            if(0==GuestWay::roomIDscan(roomID) && roomID<MAXroom)
                guest[roomID].setroomID(roomID);
            else {
                cout<<"该房间已有人"<<endl;
                break;
            }
            cout<<"输入姓名"<<endl;
            cin>>name; guest[roomID].setname(name);
            cout<<"输入性别"<<endl;
            cin>>sex;
            guest[roomID].setsex(sex);
            cout<<"输入身份证"<<endl;
            cin>>IDc;
            guest[roomID].setIDc(IDc);
            cout<<"输入籍贯"<<endl;
            cin>>nat;
            guest[roomID].setnat(nat);
            cout<<"输入手机号"<<endl;
            cin>>phone;
            guest[roomID].setphone(phone);
            guest[roomID].year=localtime(&t)->tm_year+1900;
            guest[roomID].mon=localtime(&t)->tm_mon+1;
            guest[roomID].day=localtime(&t)->tm_mday;
            guest[roomID].unDel();
            break;
        }
        for(int i=1;i<roomID;i++){
            if(1==guest[i].getdelTag() && guest[roomID].getroomID() < guest[i].getroomID()){
                GuestDate temp;
                temp=guest[i];
                guest[i]=guest[roomID];
                guest[roomID]=temp;
            }
        }
    }

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void menu()
{
    cout<<">>>>>按1入住"<<"  "
        <<"按2退房"<<"  "
        <<"按3显示住房信息"<<"  "
        <<"按4房间查询"<<"  "
        <<"按5身份证查询"<<"  "
        <<"按q退出<<<<<"<<"  "<<endl;
}

void choose(char key){
    guest.open();
    switch(key){
        case 49 :
            cout<<endl;
            guest.newfile();
            break;
        case 50 :
            cout<<endl;
            cout<<"输入房间"<<endl;
            int roomID;
            cin>>roomID;
            if(0==guest.roomIDscan(roomID)) {
                cout<<"该房间没有人"<<endl;
                break;
            }
            else {
                money(inday(guest.guest[roomID].year,guest.guest[roomID].mon,guest.guest[roomID].day));
                cout<<"确定支付? 1.确定 2.返回"<<endl;
                char c[10];
                cin>>c;
                if (choose_a(c))
                    switch(c[0])
                    {
                        case 49 : cout<<"选择支付"<<endl; guest.del(roomID); break;
                        case 50 : cout<<"选择返回"<<endl; break;
                        default : cout<<"输入错误,重新输入"<<endl; break;
                    }
                else cout<<"输入错误,重新输入"<<endl;
            }
            break;
        case 51 :
            cout<<endl;
            guest.showdate();
            break;
        case 52 :
            cout<<endl;
            cout<<"输入房间"<<endl;
            cin>>roomID;
            if(0==guest.roomIDscan(roomID)) {
                cout<<"该房间没有人"<<endl;
                break;
            }
            else    {
                cout.flags(ios::left);
            cout<<setw(8)<<"姓名"
                <<setw(6)<<"性别"
                <<setw(20)<<"身份证"
                <<setw(8)<<"籍贯"
                <<setw(14)<<"手机号"
                <<setw(6)<<"房号"
                <<setw(12)<<"入住时间"
                <<setw(3)<<"天数"
                <<endl;
                guest.showdate(roomID);
                break;
                }
        case 53 :
            cout<<endl;
            char IDc[18];
            cout<<"输入身份证"<<endl;
            cin>>IDc;
            guest.IDcscan(IDc);
            break;
        case 113:
            guest.save();
            exit(0);
        default : cout<<"输入错误,重新输入"<<endl;
    }
}

int montoday(int year,int mon){
    int day;
    switch(mon){
        case 1 :
        case 3 :
        case 5 :
        case 7 :
        case 8 :
        case 10:
        case 12:
            day=31;break;
        case 4 :
        case 6 :
        case 9 :
        case 11:
            day=30;break;
        case 2 :
            if( year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
                day=29;
            else
                day=28;
    }
    return day;
}

int days(int year,int mon,int day){
    return montoday(year,mon)+day;
}

bool choose_a(char *p){
int k=0;
while(*p) {p++;k++;}
if (k==1) return true;
else return false;
}

int inday(int year,int mon,int day)
{
int tempmon,tempday;
time_t t=time(0);
tempmon=localtime(&t)->tm_mon+1;
tempday=localtime(&t)->tm_mday;
mon=tempmon-mon;
day=tempday-day;
return days(year,mon,day)>1?days(year,mon,day):1 ; //不足一天算一天
}

void money(int p)
{        
    cout<<"应付:"<<p*120<<endl;  //120一天
}

void main()
{
    menu();
    while(1)
    {
        char key[10];
        cin>>key;
        if (choose_a(key))        
            {
            choose(key[0]);
            cout<<endl;
            menu();
            }
        else {cout<<"输入错误"<<endl<<endl;menu();}
    }
}

网络幽灵.....
2008-08-20 10:17
thynson
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-9-16
收藏
得分:0 
简单的说,从类的成员函数中返回类的私有成员的指针,在语法上没错,但在用法上错了,在特殊的场合也只能返回给友元函数。总之,尽可能避免用C的方式去写C++,在类与类之间尽可能避免私有成员的指针传递。
代码我先拿去修改下...
2008-08-20 11:20
thynson
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-9-16
收藏
得分:0 
我很奇怪,为什么你连#include<iostream>都没写,怎么编译得过?
还有,为什么你会#include<iomanip.h>这个东西我都没用过?似乎有了iostream就不需要这个文件了吧。难道你的cout是声明在这个文件里??

[[it] 本帖最后由 thynson 于 2008-8-20 11:31 编辑 [/it]]
2008-08-20 11:28
liangjian0
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2008-4-30
收藏
得分:0 
还是不会    555



















" border="0" />
[url=http://www.]极品家丁[/url]
2008-08-20 11:44
thynson
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-9-16
收藏
得分:0 
年月日的计算错了....用一个月减去另一个月得到的月数差居然还要判断大月小月?
比如11月减10月得1,1月大就算31天了?是这样吧...我最后算出的价格怎么那么贵?

[[it] 本帖最后由 thynson 于 2008-8-20 12:38 编辑 [/it]]
2008-08-20 12:13
ntdom
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2008-3-10
收藏
得分:0 
  是个问题 我没有注意到

还有你上面说的 #include<iostream>是包含在 #include<fstream.h>
里的

这个代码我上午说的问题我已经修改了

是这样的

把choose()中的guest.open()移到main()中 这样就不会因为打开文件而覆盖原有数据了

楼上说的问题我会再改下

至于类的应用 接触时间不长  我 真不知道该怎么写 希望大家多指点指点

[[it] 本帖最后由 ntdom 于 2008-8-20 13:25 编辑 [/it]]

网络幽灵.....
2008-08-20 13:17
快速回复:各位大哥大姐帮我看看这个程序问题在哪好不好??
数据加载中...
 
   



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

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