hii i am a beginner in c++ and i have got an assignment to do. below is my code and i am unable to execute it so can anyone help me out !! please !!! I am confused on how to replace the room no. in change_room() function and case 3

#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
class hotel

{
    public:

    {

        int folio_no;
        int card_no;
        int room_no;
        int room_new;
        int room_error;
        int days;
        int adult;
        int children;
        int room_type;

        char first_name;
        char last_name;
        char address[50];
        char probs[100];
        char country;
        char company;
        char date_in;
        char date_out;
        char vehicle;
        char vehic_mod;
        char plate_no;
        char vehic_type;
        char vehic_manuf;
        char memb;

        float tot_charge;
        float discount;
        float tot;
        float balance;
        float amount_paid;
        float id_type;
        float id_no;

        void guest_info();
        void ident_info();
        void vehic_info();
        void rates_info();
        void rates_disp();
        void change_room();
        void calcu_rate();
        void display_info();
        void greetings();
        void room();
    }

};

void hotel :: greetings()

{
    clrscr ();
    for (int i=0;i<10;i++)
    {
        delay(500);
        gotoxy(i,10);
        cout<<"WELCOME TO HOTEL TAJ.PLEASE WAIT";
    }
}
void hotel :: guest_info()

{
    clrscr();
    ofstream guestout;
    guestout.open("Guest info.txt",ios::out);
    {

        gotoxy
        gotoxy(1,1);
        cout<<"PLEASEENTER YOUR DETAILS: ";
        gotoxy(1,4);
        cout<<"Enter folio number: ";
        cin>>folio_no;
        gotoxy(1,6);
        cout<<"Enter your registration card number: ";
        cin>>card_no;
        gotoxy(1,8);
        cout<<"Enter your first name: ";
        gets(first_name);
        gotoxy(1,10);
        cout<<"Enter your last name: ";
        gets(last_name);
        gotoxy(1,12);
        cout<<"Enter your permanent address: ";
        gets(address);
        gotoxy(1,14);
        cout<<"Country: ";
        gets(country);
        gotoxy(1,16);
        cout<<"Company: ";
        gets(company);
        guestout<<folio_no<<"\n"<<card_no<<"\n"<<first_name<<" "<<last_name<<"\n"<<address<<"\n"<<country<<"\n"<<company<<"\n";
    }
    guestout.close();
}

void hotel :: ident_info()

{
    clrscr();
    ofstream idout;
    idout.open("Guest ID.txt",ios::out);
    {
        gotoxy(1,1);
        cout<<"PLEASE ENTER YOUR IDENTIFICATION INFO. : ";
        gotoxy(1,3);
        cout<<"Enter ID type: ";
        gets(id_type);
        gotoxy(1,5);
        cout<<"Enter ID number: ";
        gets(id_no);
        idout<<id_type<<"\n"<<id_no<<"\n";
    }
    idout.close();
}

void hotel :: vehic_info()

{
    clrscr();
    ofstream vehicout;
    vehicout.open("Vehicle info.txt",ios::out);
    {

        gotoxy(1,1);
        cout<<"PLEASE ENTER YOUR VEHICLE INFO. : ";
        gotoxy(1,3);
        cout<<"Vehicle type: ";
        gets(vehic_type);
        gotoxy(1,5);
        cout<<"Manufacturer: ";
        gets(vehic_manuf);
        gotoxy(1,7);
        cout<<"Model: ";
        gets(vehic_mod);
        gotoxy(1,9);
        cout<<"Plate number: ";
        gets(plate_no);
        vehicout<<vehic_type<<"\n"<<vehic_manuf<<"\n"<<vehic_mod<<"\n"<<plate_no<"\n";
    }
    vehicout.close();
}

void hotel :: room()

{
    ofstream roomout;
    roomout.open("Guest room.txt",ios::out);
    {
        gotoxy(1,13);
        cout<<"Enter room number: ";
        cin>>room_no;
    }
    roomout.close();
}

void hotel :: rates_info()

{
    clrscr();
    ofstream billout;
    billout.open("Guest bill.txt",ios::out);
    {

        gotoxy(1,1);
        cout<<"ENTER BILLING DETAILS: ";
        gotoxy(1,3);
        cout<<"Enter date of check in: ";
        gets(date_in);
        gotoxy(1,5);
        cout<<"Enter check out date: ";
        gets(date_out);
        gotoxy(1,7);
        cout<<"Enter number of days: ";
        cin>>days;
        gotoxy(1,9);
        cout<<"Enter number of adults: ";
        cin>>adult;
        gotoxy(1,11);
        cout<<"Enter number of children: ";
        cin>>children;
        gotoxy(1,13);
        cout<<"Enter type of room (luxury=1, ordinary=2): ";
        cin>>room_type;
        room();
        billout<<date_in<<"\n"<<date_out<<"\n"<<room_no<<"\n"<<room_type<<"\n"<<days<<"\n"<<adult<<"\n"<<children<<"\n";
    }
    billout.close();
}

void hotel :: change_room()

{
    clrscr();
    int d=0;
    gotoxy(32,8);
    cout<<"PLEASE WAIT ";
    for(i=33;i<40;i++)
    {
        delay(600);
        gotoxy(i,8);
        cout<<".";
        d=i;
    }
    while(d!<39)
    clrscr();
    gotoxy(1,1);
    cout<<"Enter your current room number: ";
    cin>>room_error;
    gotoxy(1,3);
    cout<<"Enter new room number: ";
    cin>>room_new;
    gotoxy(1,5);
    cout<<"Problem's faced: ";
    gets(probs);
}
void hotel :: rates_display()

{
    clrscr();
    gotoxy(1,1);
    cout<<"CHARGES (per day includin all services): ";
    gotocy(2,3);
    cout<<"Ordinary suite: ";
    gotoxy(2,5);
    cout<<"1 - Adult = 100 Rs";
    gotocy(2,7);
    cout<<"2 - Children = 40";
    gotoxy(55,3);
    cout<<"Luxury suite: ";
    gotoxy(55,5);
    cout<<"3 - Adult = 300 Rs";
    gotocy(55,7);
    cout<<"4 - Children = 150";

}

void hotel :: calcu_rate()

{

    int f=0;
    ofstream trancout;
    trancout.open("Guest transaction.txt",ios::open);
    {
        if(room_type==1)
        {
            a=adult*300;
            b=children*150;
            d=a+b;
        }
        else if (room_type==2)
        {
            a=adult*100;
            b=children*40;
            d=a+b;
        }
        gotoxy(1,5);
        cout<<"Are you a member of taj club (y/n): ";
        cin>>memb;
        if((memb=='y')||(memb=='Y'))
        {
            tot=(0.16)*d;
        }
        else
        {
            tot=d;
        }
        gotoxy(1,8);
        cout<<"Enter amount paid: ";
        cin>>amount_paid;
        balance=amount_paid - tot;
        trancout<<room_type<<"\n"<<memb<<"\n"<<amount_paid<<"\n"<<tot<<"\n"<<balance<<"\n";
    }
    trancout.close();
    cout<<"Billing your transcation please wait";
    for(i=38;i<44;i++)
    {
        delay(400);
        cout<<".";
    }

}

void hotel :: display_info()

{
    clrscr();
    gotoxy(30,2);
    cout<<"TAJ HOTELS";
    gotoxy(30,3);
    cout<<"THANK YOU FOR VISITING";
    gotoxy(3,5);
    cout<<first_name<<" "<<last_name;
    gotoxy(3,6);
    cout<<room_no;
    gotoxy(3,7);
    cout<<room_type;
    gotoxy(3,8);
    cout<<amount_paid;
    gotoxy(3,9);
    cout<<tot;
    gotoxy(3,10);
    cout<<balance;
}
int main()
{

    hotel obj
    int choice;
    clrscr();
    cout<<"Welcome to hotel taj.What you would like to do: ";
    gotoxy(2,3);
    cout<<"1 - Check in";
    gotoxy(2,4);
    cout<<"2 - Change room";
    gotoxy(2,5);
    cout<<"3 - Check out";
    gotoxy(2,6);
    cout<<"Enter your choice: ";
    cin>>choice;
    switch(choice)
    {
        case 1:
        {
            obj.greetings();
            obj.guest_info();               
            obj.ident_info();               
            obj.vehic_info();               
            obj.rates_info();
            obj.calcu_rate();
            obj.display_info();
        }
        case 2:
        {

            change_room();
        }
        case 3:

        {


}

Bold Text Here

Ancient Dragon commented: declared int main() instead of void main() +14

Recommended Answers

All 2 Replies

The first thing you need to do is split up the Hotel class into three different classes

  1. GuestInfo
  2. RoomInfo
  3. Hotel

class Hotel should contain an array or vector of RoomInfo classes

class RoomInfo should contain an array or vector of GuestInfo classes, as well as the room number and other objects related to the room. When you need to change the room number all you have to do is locate the instance of RoomInfo from the array/vector in Hotel that has the same room number as the current room number, then simply change the room number in that RoomInfo instance. Of course when you enter the new room number you need to verify that the new room number isn't already taken.

You have used int main() which is really nice for a beginner. Also, try avoiding old C++ formats. For example using # include <iostream.h>. Instead use # include <iostream>. And for others, like # include <stdio.h> use # include <cstdio>. Same with stdlib header. Avoid using clrscr() as its compiler specific, same with conio.h header, avoid using it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.