C++ plane boarding problem. using a vector
passengers check in using first name, last name, and class (first, business, economy)
people border in this order
-first class
-if no first class then business
-if no first or business, then economy
use class Boarding (in file Boarding.h)
followinf public functions for the class:
Boarding ();
void checkin(string firstname, string lastname, string class);
void boardNextPassenger();
followinf is output example
checkin(“Tommy”, “Titan”, “First”);
checkin(“Tina“, “Tusker“, “First”);
checkin(“Jim“, “Jumbo“, “Economy“);
boardNextPassenger(); // should print “Tommy Titan (First)”
checkin(“Dottie“, “Jumbo“, “Economy“);
boardNextPassenger(); // should print “Tina Tusker (First)”
boardNextPassenger(); // should print “Jim Jumbo (Economy)”
checkin(“Bob“, “Babar“, “Business“);
boardNextPassenger(); // should print “Bob Babar (Business)”
boardNextPassenger(); // should print “Dottie Jumbo (Economy)”
Please help create the main cpp file which shouldnt be much and then the .h file
thank you
Explanation in code comments :
driver.cpp (main code)
#include<iostream>
#include "Boarding.h"
using namespace std;
int main(){
Boarding b;
b.checkin("Tommy", "Titan", "First");
b.checkin("Tina", "Tusker", "First");
b.checkin("Jim", "Jumbo", "Economy");
b.boardNextPassenger();
b.checkin("Dottie", "Jumbo", "Economy");
b.boardNextPassenger();
b.boardNextPassenger();
b.checkin("Bob", "Babar", "Business");
b.boardNextPassenger();
b.boardNextPassenger();
}
Boarding.h
#ifndef BOARDING_H
#define BOARDING_H
#include<vector>
#include<string>
using namespace std;
class Boarding{
private :
//3 vectors to handle each
class
vector<
pair<string,string> > firstClass;
vector<
pair<string,string> > businessClass;
vector<
pair<string,string> > economyClass;
public:
void checkin(string firstname,
string lastname, string Fclass){
//depending on
the class, push the data item onto the vector
if(Fclass=="First")
firstClass.push_back(make_pair(firstname,lastname));
if(Fclass ==
"Business")
businessClass.push_back(make_pair(firstname,lastname));
if(Fclass ==
"Economy")
economyClass.push_back(make_pair(firstname,lastname));
}
void boardNextPassenger(){
//first check
for first class vector, if data exists then print and remove
//then for
business class and then for economy class
if(firstClass.size()>0){
cout<<firstClass[0].first<<"
"<<firstClass[0].second<<" (First)"<<endl;
firstClass.erase(firstClass.begin());
}
else
if(businessClass.size()>0){
cout<<businessClass[0].first<<"
"<<businessClass[0].second<<"
(Business)"<<endl;
businessClass.erase(businessClass.begin());
}
else
if(economyClass.size()>0){
cout<<economyClass[0].first<<"
"<<economyClass[0].second<<"
(Economy)"<<endl;
economyClass.erase(economyClass.begin());
}
}
};
#endif




C++ plane boarding problem. using a vector passengers check in using first name, last name, and class (first, business,...
Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person { public: Person() { setData("unknown-first", "unknown-last"); } Person(string first, string last) { setData(first, last); } void setData(string first, string last) { firstName = first; lastName = last; } void printData() const { cout << "\nName: " << firstName << " " << lastName << endl; } private: string firstName; string lastName; }; class Musician : public Person { public: Musician() { // TODO: set this...
For C++ Create a student structure that has fields for first name, last name, hometown, state, year in college and major. Keep the number of students to a reasonabe level. Place each structure into an array sorted by last name and within last name, by first name. Read the student information from a file and print the sorted array to the screen and then to an output file. I was using the code below to guide me but it keeps...
I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student { private String firstName; private String lastName; private String id; private boolean tuitionPaid; public Student(String firstName, String lastName, String id, boolean tuitionPaid) { this.firstName=firstName; this.lastName=lastName; this.id=id; this.tuitionPaid=tuitionPaid; } ...
using C++ language!! please help me out with
this homework
In this exercise, you will have to create from scratch and utilize a class called Student1430. Student 1430 has 4 private member attributes: lastName (string) firstName (string) exams (an integer array of fixed size of 4) average (double) Student1430 also has the following member functions: 1. A default constructor, which sets firstName and lastName to empty strings, and all exams and average to 0. 2. A constructor with 3 parameters:...
Write in C++ 1. Use the following Person class (Person.cpp, Person.h). You will be writing Person objects to a random access file. --------------------- Person.cpp--------------------------------- // Class Person stores customer's credit information. #include <string> #include "Person.h" using namespace std; // default Person constructor Person::Person( int idValue, string lastNameValue, string firstNameValue, int AgeValue ) { setID( idValue ); setLastName( lastNameValue ); setFirstName( firstNameValue ); setAge( AgeValue ); } // end Person constructor // get id value int Person::getID() const { return id;...
Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...
C++ implement and use the methods for a class called Seller that represents information about a salesperson. The Seller class Use the following class definition: class Seller { public: Seller(); Seller( const char [], const char[], const char [], double ); void print(); void setFirstName( const char [] ); void setLastName( const char [] ); void setID( const char [] ); void setSalesTotal( double ); double getSalesTotal(); private: char firstName[20]; char lastName[30]; char ID[7]; double salesTotal; }; Data Members The...
DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...
The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...
In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...