A class (called Customer) will represent a potential customer for a meal and discounted harbor cruise package. Various discounts will be offered for children and students.
The main function will create instances of the Customer class, and calculate the costing according to the child/student status of each Customer object.
Write a Customer class which stores the name and two Boolean data fields, one for whether the customer is a student, the other for whether the customer is a child. A child is defined as between 5 and 16 years (inclusive).
The class should have getter methods for these three data fields. Rather than prefix the Boolean getter’s name with get, use is, eg isChild().
The main function will create customer objects when run. Three values should be passed to the Customer’s constructor upon creation – name, age and a Boolean value representing the student’s status.
Use the following values for the customers:
• “Tony Stark”, 17, true
• “Steve Rogers”, 17, false
• “Peter Parker”, 16, true
• “Natasha Romanoff”, 25, true
• “Clint Barton”, 12, false
• “Wanda Maximoff”, 7, false
• “Bruce Banner”, 16, true
• “Carol Danvers”, 20, false
Sample output:
Write another function in the main.cpp called confirmBooking. This function will eventually display prices and confirm the booking. It will need to take a Customer object as a parameter.
The confirmBooking function should
• specify that a standard ticket price in RM56.00 and a standard meal price is RM30.00.
• calculate discounts
o Students and children receive half price tickets, but anyone else gets a 20% discount
o Children receive half-price meals. Everyone else gets a 10% discount.
• display the prices and the total for each customer.
The next task is to ask for confirmation of the booking. The user should confirm by pressing ‘y’.
The booking information will need to be stored. This will require another Boolean data field in the Customer class. Write a setter and getter methods for it.
Back in the main.cpp, finish your confirmBooking function. If the choices is ‘y’, set the customer’s booked field to true and display “Booked”.
Also, in the main.cpp, write another function which takes an instance of Customer as a parameter. All this function should do is print out the name of the customer if (and only if) they are booked.
What I have tried:
How can i store user input into array?
#include <iostream>
using namespace std;
class Customer {
private:
string name;
int age;
bool student;
bool child ;
public:
string getName(string arr[]) {
return name;
}
string geAge(int arr[]) {
return age;
}
string getName(bool arr[]) {
return name;
}
void cus(string n, int a, bool s){
name = n;
age = a;
student = s;
}
customerobj c1;
confirmBooking (c1){
int ticketPrice=56;
int mealPrice=30;
}
};
int main() {
string name[8];
int age[8];
bool student[8];
string id;
int i;
for (i = 0; i < 8; i++) {
cout << "Please enter name:";
cin >> name[i];
cout << "Please enter age:";
cin >> age[i];
cout << "Is student ID present?(y/n)";
cin >> id;
if (id == "y") {
student[i] = true;
}
else if (id == "n") {
student[i] = false;
}
else {
cout << "Error!";
}
}
}