In my work to copy and paste the program into something you could use I pasted part of the code twice which is why it was so big the first time I tried to put it into a message. It appears I deleted the wrong bit of code. The beginning of main should be:
1 2 3 4 5 6 7 8 9 10 11 12 13
int main()
{
// All variables should be initialized.
// These lines no longer needed.
//std::string imenagost{}, egnnagost{}, naselenomqsto{};
//int n = 0, i = 0, j = 0, k = 0, dalgotraene{};
//double noshtuvka{};
//hotel vaas[50], vaas2[50]; // <--- Could use your original code here.
char martial{ ' ' }, operation{ ' ' };
std::vector<hotel> single, maried; // <--- Does not need initilized. Nothing to work with yet.
hotel cHotel; // <--- Only need one instance/object to work with.
I just knew I would miss removing some lines of code that would not work.
Any line that says "CLS:" can be either commented out or removed,
Any line that starts "mstd::" an be deleted.
Once I tested and removed those lines it compiled fine for me.
Also had to add the header file "conio.h" for the "_getch();" that I use. This could be replaced with something different and "conio.h" would not be needed.
I can't help wonder whether the OP data model needs a bit of a tweak. The array of guests seems to me to be located in the hotel, rather than the current arrangement. So, along those lines:
#include <iostream>
#include <string>
usingnamespace std;
class Hotel
{
constint hotel_limit = 2; // 2 for testing
string hotel_name;
string* guest = new string[hotel_limit]{};
int* stay = newint[hotel_limit]{0};
int no_guests = 0;
public:
Hotel(string aName){hotel_name = aName;}
void setGuest(string aName, int aStay);
string getGuestName(int aGuestNo);
string getHotelName(){return hotel_name;}
void listGuests();
};
void Hotel::setGuest(string aName, int aStay)
{
if(no_guests < hotel_limit)
{
guest[no_guests] = aName;
stay[no_guests] = aStay;
no_guests++;
}
else
cout << "*** No vacancies ***\n";
}
void Hotel::listGuests()
{
for(int i = 0; i < no_guests; ++i)
cout << i << '\t' << guest[i] << ' ' << stay[i] << '\n';
}
int main()
{
Hotel hilton("Caesar's Palace");
string name;
int stay = 0;
while(true)
{
cout << "Hotel " << hilton.getHotelName() << '\n';
cout << "A:To add a guest \n";
cout << "O: Output all guests \n";
cout << "E: To exit program \n";
char operation;
cin >> operation;
switch ( toupper(operation) )
{
case'A':
cout << " Enter the name of the guest: ";
cin >> name;
cout << "Enter how long will the guest stay: ";
cin >> stay;
hilton.setGuest(name,stay);
break;
case'O':
hilton.listGuests();
break;
case'E':
break;
default:
;
}
}
}
A:To add a guest
O:Output all guests
E:To exit program
a
Enter the name of the guest
Smith
Enter how long will the guest stay
89
A:To add a guest
O:Output all guests
E:To exit program
a
Enter the name of the guest
Brown
Enter how long will the guest stay
56
A:To add a guest
O:Output all guests
E:To exit program
a
Enter the name of the guest
Black
Enter how long will the guest stay
7
No vacancies
A:To add a guest
O:Output all guests
E:To exit program
o
0 Smith 89
1 Brown 56
A:To add a guest
O:Output all guests
E:To exit program
Well the errors are 50
and i'm using codeblocks so i guess my compiler is c++98
and this is one big error that it gave me
1 2 3 4 5 6 7 8 9 10
#ifndef _CXX0X_WARNING_H
#define _CXX0X_WARNING_H 1
#if __cplusplus < 201103L
#error This file requires compiler and library support for the \
ISO C++ 2011 standard. This support is currently experimental, and must be \
enabled with the -std=c++11 or -std=gnu++11 compiler options.
#endif
#endif
and it thank you again for enlightening me!
not just Mr.Andy all of you :)
I am not as familiar with Code::Blocks as I would like to be. If you use the command line to compile the program you will need to try -std=c++11. If you use an IDE to work with your code than you will need to edit something in the options to add -std=c++11.
You can change the range based loops to regular for loops like this:
Notice how you access the member functions differently.
It sounds like your compiler needs to be updated. It will take some time to change the for loops, but it will work. I just changed the first from option "o" and it worked. haha tested it first this time.