C++ programming. To solve the problem in the picture that I attached, please refer to this programming below. ------------------------------------------------------- #include #include using namespace std; #define SIZE 50 class Taxi { private: string taxi_id; string driver_name; string make; string model; string color; string license; int num_passenger; public: // default constructor Taxi():taxi_id(""), driver_name(""), make(""), model(""), color(""), license(""), num_passenger(0) {} // set taxi id void setTaxiID(string taxi_id) { this->taxi_id = taxi_id; } // set driver name void setDriverName(string driver_name) { this->driver_name = driver_name; } // set car maker void setMake(string make) { this->make = make; } // set car model void setModel(string model) { this->model = model; } // set car color void setColor(string color) { this->color = color; } // set license number void setLicenseNumber(string license) { this->license = license; } // set number of passengers in the entire shift void setNumPassengers(int num_passenger) { this->num_passenger = num_passenger; } // return taxi id string getTaxiID() {return taxi_id;} // return driver name string getDriverName() {return driver_name;} // return car maker string getMake() {return make;} // return car model string getModel() {return model;} // return car color string getColor() {return color;} // return license number string getLicense() {return license;} // return number of passengers in the entire shift int getPassengers() {return num_passenger;} }; // function to populate the input array with maximum of 50 Taxi records int readRecords(Taxi taxi[]); int main() { Taxi taxi[50]; // create an array of 50 Taxi objects // read Taxi records into array int numTaxi = readRecords(taxi); // open output file ofstream out; out.open("CTC.dat"); // check if file opening is successful or not if(out.fail()) { cout<<"Unable to open output file: CTC.dat... Terminating"<
C++ programming. To solve the problem in the picture that I attached, please refer to this programming below.
-------------------------------------------------------
#include <iostream>
#include <fstream>
using namespace std;
#define SIZE 50
class Taxi
{
private:
string taxi_id;
string driver_name;
string make;
string model;
string color;
string license;
int num_passenger;
public:
// default constructor
Taxi():taxi_id(""), driver_name(""), make(""), model(""), color(""), license(""), num_passenger(0)
{}
// set taxi id
void setTaxiID(string taxi_id)
{
this->taxi_id = taxi_id;
}
// set driver name
void setDriverName(string driver_name)
{
this->driver_name = driver_name;
}
// set car maker
void setMake(string make)
{
this->make = make;
}
// set car model
void setModel(string model)
{
this->model = model;
}
// set car color
void setColor(string color)
{
this->color = color;
}
// set license number
void setLicenseNumber(string license)
{
this->license = license;
}
// set number of passengers in the entire shift
void setNumPassengers(int num_passenger)
{
this->num_passenger = num_passenger;
}
// return taxi id
string getTaxiID() {return taxi_id;}
// return driver name
string getDriverName() {return driver_name;}
// return car maker
string getMake() {return make;}
// return car model
string getModel() {return model;}
// return car color
string getColor() {return color;}
// return license number
string getLicense() {return license;}
// return number of passengers in the entire shift
int getPassengers() {return num_passenger;}
};
// function to populate the input array with maximum of 50 Taxi records
int readRecords(Taxi taxi[]);
int main()
{
Taxi taxi[50]; // create an array of 50 Taxi objects
// read Taxi records into array
int numTaxi = readRecords(taxi);
// open output file
ofstream out;
out.open("CTC.dat");
// check if file opening is successful or not
if(out.fail())
{
cout<<"Unable to open output file: CTC.dat... Terminating"<<endl;
}
else
{
// loop to output records to file where each taxi spans 7 lines where each line contains 1 field
for(int i=0;i<numTaxi;i++)
{
out<<taxi[i].getTaxiID()<<endl<<taxi[i].getDriverName()<<endl<<taxi[i].getMake()<<endl
<<taxi[i].getModel()<<endl<<taxi[i].getColor()<<endl<<taxi[i].getLicense()<<endl
<<taxi[i].getPassengers();
if(i < numTaxi-1) // not the last record
out<<endl;
}
out.close(); // close the file
}
return 0;
}
// function to read Taxi records from user and return number of records read
int readRecords(Taxi taxi[])
{
cout<<"Enter records for upto 50 taxi(enter blank string for taxi id to exit):"<<endl;
bool done= false; // initialize done to false
int count = 0; // initialize count to 0
string taxi_id;
string driver_name;
string make;
string model;
string color;
string license;
// loop that continues until user wants to exit
while(!done)
{
// input the taxi id
cout<<"Enter details for Taxi-"<<count+1<<":"<<endl;
cout<<"Taxi ID: ";
getline(cin, taxi_id);
// check if user wants to exit
if(taxi_id.length() == 0)
done = true; // then set done to true
else
{
// input the driver name, car maker, model, color, and license number
cout<<"Driver name: ";
getline(cin, driver_name);
cout<<"Car maker: ";
getline(cin, make);
cout<<"Car model: ";
getline(cin, model);
cout<<"Car color: ";
getline(cin, color);
cout<<"License number: ";
getline(cin, license);
taxi[count].setLicenseNumber(license);
taxi[count].setMake(make);
taxi[count].setModel(model);
count++; // increment count
// check if maximum limit has reached, then set done to true
if(count == SIZE)
done = true;
}
}
return count;
}


Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images









