Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ PROGRAM Problem 3.1 Copy the solution from problem 2.2 Make the following additions and changes: 1. Arrange the functions in the order: * main

C++ PROGRAM
Problem 3.1
Copy the solution from problem 2.2
Make the following additions and changes:
1. Arrange the functions in the order:
* main
* output
* setUp (was setUpCar)
* input
2. Change the output function so it is a member function of the class Car.
3. Change the name of the setUpCar function to setUp and make it a
member function of the class Car, with five parameters specified as
constant reference parameters.
4. Make all the data in the Car class private and make the member
functions public.
5. Do NOT make the input function a member function.
6. Change the parameters of the input function to five reference
parameters corresponding to the five fields in the class.
7. In main define five variables. Pass these variables to the input
function so the input function can set their values.
8. In main define a Car object. This time the Car object will be in the
stack for main, rather than in the heap. Name this object car1.
9. In main call the setUp function and pass the five variables, rather
than calling it from the input function.
10. In main call the output function.
11. Test the program with the same data as was used in assignment 2.
MY LAB 2.2 CODE :
#include
#include
#include
using namespace std;
class Car
{
public:
string reportingMark;
int carNumber;
string kind;
bool loaded;
string destination;
public:
Car()
{
reportingMark = "None";
carNumber = 0;
kind = "None";
loaded = false;
destination = "None";
}
Car(string rMark, int cNumber, string knd, bool load, string dest)
{
reportingMark = rMark;
carNumber = cNumber;
kind = knd;
loaded = load;
destination = dest;
}
~Car()
{};
void setReportingMark(string rMark)
{ reportingMark = rMark;}
void setCarNumber(int cNumber)
{ carNumber = cNumber;}
void setKind(string knd)
{ kind = knd;}
void setLoaded(bool load)
{ loaded = load;}
void setDestination(string dest)
{ destination = dest;}
string getReportingMark() const
{ return reportingMark;}
int getCarNumber() const
{ return carNumber;}
string getKind() const
{ return kind;}
bool getLoaded() const
{ return loaded;}
string getDestination() const
{ return destination;}
Car* setUpCar(string rMark, int cNumber, string knd, bool load, string dest)
{
Car *c1 = new Car(rMark, cNumber, knd, load, dest);
return c1;
}
};
void input(string &rMark, int &cNumber, string &knd, bool &load, string &dest);
void output(Car *cPtr);
int main()
{
string rMark;
int cNumber;
string knd;
bool load;
string dest;
input(rMark, cNumber, knd, load, dest);
Car *cPtr;
cPtr = cPtr->setUpCar(rMark, cNumber, knd, load, dest);
output(cPtr);
delete cPtr;
return 0;
}
void input(string &rMark, int &cNumber, string &knd, bool &load, string &dest)
{
int len;
cout << "Enter reportingMark: ";
getline(cin, rMark);
len = rMark.length();
while (len > 5)
{
cout << "Invalid! Enter reportingMark with 5 or less upper case characters: ";
cin >> rMark;
len = rMark.length();
}
for (int i = 0; i < int (rMark.length()); i++)
rMark[i] = toupper(rMark[i]);
cout << "Enter carNumber: ";
cin >> cNumber;
cout << "Enter kind: ";
cin >> knd;
cout << "Enter loaded: ";
cin >> std::boolalpha >> load;
cin.ignore();
if (load)
{
cout << "Enter destination: ";
getline(cin, dest);
}
else
dest = "NONE";
}
void output(Car *cPtr)
{
cout << " *Display the Car data * ";
cout << setw(15) << left << "ReportingMark: " << cPtr->reportingMark;
cout << setw(16) << left << " CarNumber: " << cPtr->carNumber;
cout << setw(16) << left << " Kind: " << cPtr->kind;
cout << setw(16) << left <<" Loaded: ";
cout << std::boolalpha << cPtr->loaded;
cout << setw(16) << left << " Destination: " << cPtr->destination;
cout << endl;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is body cathexis?

Answered: 1 week ago