In: Computer Science
In C++
All guests in ABC Hotel are either Elite members (meaning they get a free breakfast) or Standard members (meaning they do not get a free breakfast). They collect points for every stay-Elite members earn 100 points for every day stayed in the hotel (so 2 days would be 200 points) and Standard member earns 50 points for every stay (so 3 days would be 140 points). Once 1000 points are reached, guests get a free stay. Guest details are kept in a file:
Sample input file1: Augustus, E-300,200, eggs//customer name, Membership level (E means elite), item ordered, ID number, points, breakfast choice
Sample input file2: Cyrus, S-100,30,x//customer name, Membership level(S means standard), item ordered, ID number, points, breakfast choice
1.The program should read in the number of points to get a free stay (1000) from the command line. It should continuously read in files of guests until the exit is entered (meaning the user can keep typing in file names-note that you can type in the same file name to open a previous guest).
2.Every time a file is opened, the program should ask how many days the guest is staying and award the appropriate number of points based on the membership level. The new point total should be saved in the file. If they are an elite member, they have the chance to change their breakfast choice.
3.When exiting, a file should be output with the number of guests that got a free stay (meaning their total points were 1000 or greater)
Sample output file:
Augustus had a free stay.
Jane had a free stay.
4.You should make a Hotel class and an abstract Person class. You should also make additional classes as necessary.
Solution:
Givendata:
All guests in ABC Hotel are either Elite members (meaning they get a free breakfast) or Standard members (meaning they do not get a free breakfast). They collect points for every stay-Elite members earn 100 points for every day stayed in the hotel (so 2 days would be 200 points) and Standard member earns 50 points for every stay (so 3 days would be 140 points). Once 1000 points are reached, guests get a free stay. Guest details are kept in a file:
Answer:
#pragma once
#include<string>
#include<iostream>
using namespace std;
class Person
{
public:
string name;
char memberShipLevel;
int points;
Person();
Person(string n, char msl);
void setName(string n);
void setMemberShipLevel(char msl);
string getName();
char getMemberShipLevel();
virtual void display() = 0;
};
#include "Person.h"
Person::Person()
{
name = "";
}
Person::Person(string n, char msl)
{
name = n;
memberShipLevel = msl;
}
void Person::setName(string n)
{
name = n;
}
void Person::setMemberShipLevel(char msl)
{
memberShipLevel = msl;
}
string Person::getName()
{
return name;
}
char Person::getMemberShipLevel()
{
return memberShipLevel;
}
#include "Person.h"
#include<fstream>
#include<iostream>
using namespace std;
class Hotel :public Person
{
private:
int totalMembers;
string* files;
string breakFast;
public:
Hotel();
Hotel(string n, char msl, int totalNumber);
void setFilesOfmembers();
void readFiles(string fileName);
void setBreakFast(string Bf);
string getBreakFast();
void addMembers();
void display();
};
#include "Hotel.h"
#include"Person.h"
#include<fstream>
#include<iostream>
using namespace std;
Hotel::Hotel() :Person()
{
totalMembers = 4;
files = new string[totalMembers];
}
Hotel::Hotel(string n, char msl, int totalNumber) : Person(n,
msl)
{
totalMembers = totalNumber;
files = new string[totalMembers];
}
void Hotel::addMembers()
{
fstream file;
cout << "Enter total number of members" <<
endl;
cin >> totalMembers;
cout << "Total number of members are:"
<< totalMembers << endl;
for (int i = 0; i < totalMembers; i++)
{
cout << "Enter the name of
members for membership" << endl;
cin >> files[i];
}
}
void Hotel::setFilesOfmembers()
{
fstream file;
string guest;
cout << "Enter the name of person You want to
edit and view" << endl;
cin >> guest;
for (int i = 0; i < totalMembers; i++)
{
if (files[i] == guest)
{
readFiles(guest);
display();
}
else
{
cout <<
"Member don't exist" << endl;
}
}
file.open(guest, ios::out);
if (!file)
{
cout << "Cannot open the file
please try again" << endl;
}
else
{
cout << "FILE IS OPEND YOU
CAN UPDATE THE INFORMATION" << endl;
file << name;
file << memberShipLevel;
if (memberShipLevel ==
'E')
{
int days;
cout <<
"Enter number of days you want to stay" << endl;
cin >>
days;
points = points
+ (days * 100);
file <<
points;
cout <<
"You can choose the breakfast choice as you are Elite member"
<< endl;
}
else
{
cout <<
"You are member of Standard level" << endl;
int
days;
cout <<
"Enter the number of days you want to stay" << endl;
cin >>
days;
points = points
+ (days * 50);
file <<
points;
}
cout << "Sucessfully
updated" << endl;
file.close();
}
}
void Hotel::readFiles(string fileName)
{
fstream file;
file.open(fileName, ios::in);
if (!file)
{
cout << "You have entered a
wrong persons file (No membership)" << endl;
}
else
{
cout << "FILE OPENED"
<< endl;
while (!file.eof())
{
file >>
name;
file >>
memberShipLevel;
file >>
points;
}
file.close();
}
}
void Hotel::display()
{
cout << "##INFORMATION OF GUEST##" <<
endl;
cout << "NAME:" << name <<
endl;
cout << "MEMBERSHIPLEVEL:" <<
memberShipLevel << endl;
cout << "points:" << points <<
endl;
}
#include"Hotel.h"
#include"Person.h"
#include<iostream>
using namespace std;
int main()
{
int choice;
string guestName;
Hotel obj;
cout << "Enter 1)VIEW GUEST DATA AND EDIT
2)QUIT" << endl;
cin >> choice;
while (choice != 2)
{
cout << "Enter the name of
Guest:" << endl;
cin >> obj.name;
cout << "Enter the
memberShipLevel:" << endl;
cin >>
obj.memberShipLevel;
obj.setFilesOfmembers();
cout << "Enter 1)VIEW GUEST
DATA AND EDIT 2)QUIT" << endl;
cin >> choice;
}
}
PLEASE GIVEME THUMBUP........