Dont know why

This is a discussion on Dont know why within the C++ Programming forums, part of the General Programming Boards category; Code: #include<iostream> #include<conio.h> #include<cctype> #include<string> #include<stdlib.h> #include<fstream> #include<iomanip> #include<time.h> #include<string> #include<stdio.h> const char *filename="c:\information.txt"; const char *file="c:\rooms.txt"; using namespace std; ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    13

    Dont know why

    Code:
    #include<iostream>
    #include<conio.h>
    #include<cctype>
    #include<string>
    #include<stdlib.h>
    #include<fstream>
    #include<iomanip>
    #include<time.h>
    #include<string>
    #include<stdio.h>
    
    const char *filename="c:\\information.txt";
    const char *file="c:\\rooms.txt";
    
    using namespace std;
    
    class hotel
    {
        private:
        //string name;
        //string family;
        //string city;
        //string telephone;
        //int time;
        //char type_room;
        //double cost_perday;
        int single;
        int doubler;
        int triple;
        public:
        ifstream infile,in,inp;
        ofstream outfile,out,outp;
    	void menu();
        void submenu();
    	void bill();
    	hotel(){single=100;doubler=200;triple=300;};
        ~hotel(){};
    };
    
    class information : public hotel
    {
        public:
        string name;
        string family;
        string city;
        string telephone;
        int time;
        char type_room;
        double cost_perday;
        //int single;
        //int doubler;
        //int triple;
    	
    
    };
    
    
    int main()
    {	
    
    	hotel custom;
        custom.menu();
    	getch();
        return 0;                                                                           
    }              
    
    void hotel::menu()
    {
        
        char selection;
        
        cout<<"****************************************************************"<<endl;
        cout<<"XXX Hotel."<<endl;
        cout<<"R-> Reservation."<<endl;
    	cout<<"B-> Bill."<<endl;
        cout<<"Q-> Quit."<<endl;
        cout<<"****************************************************************";
        cout<<"Enter your choose: "<<endl;
        cin>>selection;
        cin.get();
        selection=(char)toupper(selection);
        switch(selection)
        {
            case 'R':
                 {
                           submenu();
                           break;
                 }
            case 'B':
                 {
                           bill();
                           break;
                 }
            case 'Q':
                 {
                           exit(1);
                           break;
                 }
            default:
                 {
                           menu();
                 }
        }
    }
    
    
    
    void hotel::submenu()
    {
        information n;
        char choose;
        int number=0;
        int room;
        char continues;
        outfile.open (filename,ios::out|ios::app);
        outfile.close();
        
    		int single=100;
            int doubler=200;
            int triple=300;
            
            cout<<"*******************"<<endl;
            cout<<"Reservation"<<endl;
            cout<<" --------------- "<<endl;
            cout<<"S->Single"<<endl;
            cout<<"D->Double"<<endl;
            cout<<"T->Triple"<<endl;
            cout<<"Q->Quit "<<endl;
            cout<<"*******************"<<endl;
            cout<<"Enter the Type of Room you want: "<<endl;
            cin>>choose;
            cin.get();
            choose=(char)toupper(choose);
            n.type_room=choose;
            int account_s=0;
            int account_d=0;
            int account_t=0;
            int r_number;
            char type;
            string r_name;
            string r_family;
            string r_city;
            string r_telephone;
            int r_time;
            double r_price;
            if (choose=='S'||choose=='D'||choose=='T')
            {
                infile.open(filename,ios::in);
                if (infile==NULL)
                cout<<"Error opening the file"<<endl;
                while(!infile.eof())
                {
                    infile>>r_number>>r_name>>r_family>>r_city>>r_telephone>>type>>r_price>>r_time;
                    if(type=='S')
                    {
                        account_s++;
                    }
                    if (type=='D')
                    {
                        account_d++;
                    }
                    if (type=='T')
                    {
                        account_t++;
                    }
                }
                single=single-account_s;
                doubler=doubler-account_d;
                triple=triple-account_t;
                infile.close();
                if (type=='S')
                {
                    single=single+1;
                }
                if (type=='D')
                {
                    doubler=doubler+1;
                }
                if (type=='T')
                {
                    triple=triple+1;
                }
                if (n.type_room=='S')
                {
                    if (single!=0)
                    {
                        cout<<"Total single bed available is "<<single;
                        cout<<"\nHow many single bed you need?";
                        cin>>number;
                    }
                    else
                    {
                        cout<<"\nSorry,No Room available,Try at YMCA";
                    }
                }
                if (n.type_room=='D')
                {
                    if (doubler!=0)
                    {
                        cout<<"Total double bed available is "<<doubler;
                        cout<<"\nHow many double bed you need?";
                        cin>>number;
                    }
                    else
                    {
                        cout<<"\nSorry,no room available,try at YMCA";
                    }
                }
                if (n.type_room=='T')
                {
                    if (triple!=0)
                    {
                        cout<<"Total triple bed available is "<<triple;
                        cout<<"\nHow many bed you need?";
                        cin>>number;
                    }
                    else
                    {
                        cout<<"Sorry,no any room Available,Try at YMCA";
                    }
                }
                cin.get();
                cout<<"First Name : ";
                cin>>n.name;
                cout<<"Family Name : ";
                cin>>n.family;
                cout<<"City : ";
                cin>>n.city;
                cout<<"Tel : ";
                cin>>n.telephone;
                cout<<"Charge :";
                cin>>n.cost_perday;
                cout<<"Days : ";
                cin>>n.time;
                int flag=0;
                for (int i=1;i<=number;i++)
    			{	
    				cout<<"Room NO.: "<<endl;
                    cin>>room;
                    if (n.type_room=='S')
                    {
                        if(room<100 || room>199)
    					{
    						cout<<"You Should Choose The Number Between 100 And 199"<<endl;
                            cout<<endl;
                            i=i-1;
                            continue;
    					}
                    infile.open(filename,ios::in);
                    while (!infile.eof())
    				{
                            infile>>r_number>>r_name>>r_family>>r_city>>r_telephone>>type>>r_price>>r_time;
                            if (room==r_number)
    						{	   
                                cout<<"You Should Choose Other Room.This is occupied."<<endl;
                                cout<<endl;
                                flag=1;
                                i=i-1;
                                break;
                            }
                            else
    						{
                                flag=0;
                            }
    				}
                    infile.close();
    				if (flag==1)
    				{
    					continue;
    				}
    				
    				}
    
    				if (n.type_room=='D')
    				{
                        if(room<200 || room>399)
    					{
    						cout<<"YOU Should Choose The Number Between 200 And 399"<<endl;
                            cout<<endl;
                            i=i-1;
                            continue;
                        }
                     infile.open(filename,ios::in);
                     while (!infile.eof())
    					{
    						infile>>r_number>>r_name>>r_family>>r_city>>r_telephone>>type>>r_price>>r_time;
                            if (room==r_number)
    						{
    							cout<<"You must choose other room.This is occupied."<<endl;
                                cout<<endl;
                                flag=1;
                                i=i-1;
                                break;
                            }
                            else
    						{
    							flag=0;
                            }
    					}
    				
                        infile.close();
                        if (flag==1)
    					{
    						continue;
                        }
                        if (n.type_room=='T')
    					{
    						if(room<400 || room>499)
    						{
    							cout<<"You should Choose The Number Between 400 And 499"<<endl;
                                cout<<endl;
                                i=i-1;
                                continue;
                            }
                        infile.open(filename,ios::in);
                        while (!infile.eof())
    					{
    						infile>>r_number>>r_name>>r_family>>r_city>>r_telephone>>type>>r_price>>r_time;
                            if (room==r_number)
    						{ 
    							cout<<"You Should choose other room.This is occupied."<<endl;
                                cout<<endl;
                                flag=1;
                                i=i-1;
                                break;
                            }
                            else
                            {
    							flag=0;
                            }
    					}
                        infile.close();
                        if(flag==1)
    					{
    						continue;
                        }
                }          
    			outfile.open (filename,ios::out|ios::app);
    			outfile<<room<<" ";
    			outfile<<n.name<<" ";               
    			outfile<<n.family<<" ";               
    			outfile<<n.city<<" ";               
    			outfile<<n.telephone<<" ";              
    			outfile<<n.type_room<<" ";               
    			outfile<<n.cost_perday<<" ";              
    			outfile<<n.time<<endl;               
    			outfile.close();               
    		}
    		cout<<"The Reservation Is Finished"<<endl;
    		cout<<endl;
    		}
    		if (choose=='Q')
    		{
    			menu();
    		} 
    		
    	cout<<"Another Reservation? (Y/N)"<<endl;
    	cin>>continues;
    	if(continues=='y'||continues=='Y')
    	    menu();
    }
    
    
    	 
    
    void hotel::bill()
    {
    	int temp_room,n=3,r_number,amount;
        char type;
        string temp_name;
        string r_name;
        string r_family;
        string r_city;
        string r_telephone;
        int r_time;
        double r_price;
        double total,discount,sum=0,tax;
        double service_tax;
        int i;
        cout<<endl;
        cout<<"How many rooms you want to pay ? "<<endl;
        cin>>amount;
        for (int k=0;k<amount;k++)
    	{
    		cout<<"Please input the room number: "<<endl;
            cin>> temp_room;
        }
        infile.open(filename,ios::in);
        cout<<"Customer Information"<<endl;
        for (i=0;i<78;i++)
    	{
    		cout<<"_";
    	}
        cout<<endl;
        cout<<"|"<<setw(4)<<"NO."<<"|"<<setw(12)<<"First Name"<<"|"<<setw(12)<<"Family Name"<<"|"<<setw(10)<<"City"<<"|"<<setw(15)<<"Telephone"<<"|"<<setw(5)<<"Type"<<"|"<<setw(6)<<"Price"<<"|"<<setw(6)<<"Days"<<"|";
        cout<<endl;
        cout<<"|";
        for (int l=1;l<78;l++)
    	{
    		cout<<"_";
    	}
        cout<<"|";
        int nobody=0;
        for (int m=0;m<amount;m++)
    	{
    		while (!infile.eof())
    		{
    			infile>>r_number>>r_name>>r_family>>r_city>>r_telephone>>type>>r_price>>r_time;
                if (temp_room==r_number )
    			{
    				cout<<endl;
                    cout<<"|"<<setw(4)<<r_number<<"|"<<setw(13-r_name.length())<<r_name<<"|"<<setw(13-r_family.length())<<r_family<<"|"<<setw(11-r_city.length())<<r_city<<"|"<<setw(16-r_telephone.length())<<r_telephone<<"|"<<setw(5)<<type<<"|"<<setw(6)<<r_price<<"|"<<setw(6)<<r_time<<"|";
                    cout<<endl;                    
                    cout<<"|";
                    for (int i=0;i<77;i++)                    
                    {
    					cout<<"_";
    				}                 
                    cout<<"|";
    				sum=sum+r_price*r_time;
                    nobody=1;
                    break;
                }
                else
    			{
    				nobody=0;
                }
            }
            if (nobody==0)
    		{
                cout<<"\nThe room "<<temp_room<<" is empty.";
            }
        }
        infile.close();
        if (sum>0 && sum<=500)
    	{
    		total=sum*(1+0.15+0.05);
            discount=0;                        
            tax=sum*0.15;                        
            service_tax=sum*0.05;                       
        }
        else
    	{
    		if (sum<=1000)
    		{
    			discount=sum*0.1;
                total=sum*(1+0.15+0.05-0.1);                      
                tax=sum*0.15;                        
                 service_tax=sum*0.05;                       
            }
            else
    		{
            if (sum<=5000)
    		{
    			discount=sum*0.15;
                total=sum*(1+0.15+0.05-0.15);
                tax=sum*0.15;
                service_tax=sum*0.05;
            }
            else
    		{
    			discount=sum*0.2;
                total=sum*(1+0.15+0.05-0.2);
                tax=sum*0.15;
                service_tax=sum*0.05;
    		}
    		}
    	}
        cout<<endl<<endl<<endl;
        cout<<"----------------------"<<endl;
        cout<<"Sub Total : "<<sum<<endl;
        cout<<"Discount : "<<discount<<endl;
        cout<<"Tax : "<<tax<<endl;
        cout<<"Service Tax : "<<service_tax<<endl;
        cout<<"Total : "<<total<<endl;
        cout<<"----------------------"<<endl;
        cout<<"\nPress any key to return main menu.";
        getch();
        int comp=0;
        for (i=0;i<amount;i++)
    	{
    		infile.open(filename,ios::in);
            while (infile)
    		{
    			infile>>r_number>>r_name>>r_family>>r_city>>r_telephone>>type>>r_price>>r_time;
                if (temp_room!=r_number && r_number!=comp )
    			{
    				out.open(file,ios::out|ios::app);
                    out<<r_number<<" ";
                    out<<r_name<<" ";
                    out<<r_family<<" ";
                    out<<r_city<<" ";
                    out<<r_telephone<<" ";
                    out<<type<<" ";
                    out<<r_price<<" ";
                    out<<r_time<<endl;
                    out.close();
                }
                else
    			{
    				continue;
    			}
                comp=r_number;
            }
        infile.close();
        }
        menu();
    }


    something is wrong , but i dont know how to slove it, plz help!!~

  2. #2
    Registered User
    Join Date
    Feb 2005
    Posts
    13

    wats this for

    - bill' : local function definitions are illegal

    - unexpected end of file found

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    32
    You are missing a closing brace at the end of the function "void hotel::submenu()".
    Code:
    		cin>>continues;
    		if(continues=='y'||continues=='Y')
    			menu();
    	}
    }// need a closing brace
    
    void hotel::bill()
    {

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,802
    Your menu function is kinda ugly in its implementation. It recursively calls itself needlessly either directly or through the functions that it calls. The menu function should be a loop that continuously processes user input and either exits or call the appropriate functions submenu/bill. These functions should not call menu but rather they will return to the menu function once they exit whereupon control should return to the loop displaying the menu options and processing user input.

    Code:
    void hotel::submenu()
    {
        information n;
        char choose;
        int number=0;
        int room;
        char continues;
        outfile.open (filename,ios::out|ios::app);
        outfile.close();
    What is the purpose of opening and then immediately closing the file?

    Code:
    class information : public hotel
    {
    Why is this information class being derived from the hotel class?

    The indentation/alignment makes looking through your code difficult. Fix the indentation/alignment and repost. Replace tabs with an appropriate number of spaces. Use the "Preview Post" button to your advantage and use the opportunity to keep at it until you post is nicely formatted.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    Feb 2005
    Posts
    13

    Thx

    ic
    thank you for helping
    i am trying

  6. #6
    Registered User
    Join Date
    Feb 2005
    Posts
    8
    I noticed something on your code:
    Code:
    #include<iostream>
    #include<conio.h>
    #include<cctype>
    #include<string>
    #include<stdlib.h>
    #include<fstream>
    #include<iomanip>
    #include<time.h>
    #include<string>
    #include<stdio.h>
    Why sometimes use .h (C-way) and sometimes without .h (C++-way)?

  7. #7
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Because conio.h has no 'without .h' version. stdlib.h and stdio.h, on the other hand, should be replaced with <cstdlib> and <cstdio>.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #8
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,802
    Quote Originally Posted by Hunter2
    Because conio.h has no 'without .h' version. stdlib.h and stdio.h, on the other hand, should be replaced with <cstdlib> and <cstdio>.
    What about <time.h> replaced with <ctime>?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21