Question

C++ plane boarding problem. using a vector passengers check in using first name, last name, and class (first, business,...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

CAUsers Rogue Desktop driver.cpp IExecutinal Dev-c++5.11 Eile Edit Search Yew Project Egecute lools AStyle岦ndow Help ProjectCUsers r.cpp Dev-C++5.11 Eile Edit Search Yiew Project Execute Iools AStyle Window Help Project Classes Debug zombirgame.cppCUsers Rogue Desktop Boardingh - Dey-C++5.11 Eile Edit Search Yew Project Esecute lools AStyle yndow Help Project Classes DeCUsers Rogue Desktop Boardingh - Dey-C++5.11 Eile Edit Search Yiew Project Execute Iools AStyle Window Help Project Classes

Add a comment
Know the answer?
Add Answer to:
C++ plane boarding problem. using a vector passengers check in using first name, last name, and class (first, business,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person {...

    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...

  • I have a little problem about my code. when i'm working on "toString method" in "Course"...

    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...

    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:...

  • C++ implement and use the methods for a class called Seller that represents information about a...

    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...

  • Create a class called Student. This class will hold the first name, last name, and test...

    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...

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    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 t...

    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...

    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...

  • Create a class hierarchy to be used in a university setting. The classes are as follows:...

    Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last name...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT