27.6k views
1 vote
Declare a structure with a type name: Car containing:

- reportingMark a string of 5 or less upper case characters
- carNumber an int
- kind could be box tank flat or other
- loaded a bool
- destination a string with a destination or the word NONE

Note: A destination is required if the car is loaded. If it is not loaded the destination may be either a destination or the word NONE.

Create the following functions:
main * Uses new to obtain space for the data structure * Calls the other two functions * Deletes the space obtained using new
input * Read all the data from the user * After all the data has been read, put all this data into the structure
output * Print the data in a neat format

Put the main function first. Use the function names and field names specified above. Arrange the functions in the order listed above. Test your program with the following data: reportingMark SP, carNumber 34567, kind box, loaded true, destination Salt Lake City

User Ojitha
by
4.8k points

1 Answer

4 votes

Answer:

C++ code is given below

Step-by-step explanation:

#include <iostream>

#include <cctype>

#include <string.h>

#include <cstring>

#include <sstream>

using namespace std;

struct Car {

public:

char reportingMark[5];

int carNumber;

string kind;

bool loaded;

string destination;

};

void input(Car *);

void output(Car *);

int main() {

Car *T = new Car;

input(T);

output(T);

delete T;

return 0;

}

void input(Car *T)

{

string str, s;

cout << " Enter the reporting mark as a 5 or less character uppercase string: ";

cin >> str;

for (int i = 0; i < str.length(); i++)

T->reportingMark[i] = toupper(str[i]);

cout << " Enter the car number: ";

cin >> T->carNumber;

cout << " Enter the kind: ";

cin >> T->kind;

cout << " Enter the loaded status as true or false: ";

cin >> s;

istringstream(s) >> boolalpha >> T->loaded;

if (T->loaded == true) {

cout << " Enter the destination: ";

cin.ignore();

getline(cin, T->destination);

}

else

T->destination = "NONE";

}

void output(Car *T)

{

cout << " Reporting Mark: " << T->reportingMark;

cout << " Car Number: " << T->carNumber;

cout << " Kind: " << T->kind;

cout << " Loaded Status: " << boolalpha << T->loaded;

cout << " Destination: " << T->destination << " ";

}

User Jason Livesay
by
5.7k points