Hello. I am new to C++ and am struggling with the Structure format. One of the questions we have been asked is to write a C++ statement storing data for a destination. I understand how to create the struct but not sure how to output it correctly.
How do I get the tourInit portion to start the program in main so it displays this on the output first, then asks you for your destination?
So far everything else seems to work I just need help figuring out how to output that part first.
Thank you for any assistance or direction you can provide
The entire question is below:
A: Declare the variable destination of type tourType.
B: Write C++ statements to store the following data in destination: cityName—Chicago, distance—550 miles, travelTime—9 hours and 30 minutes.
C: Write the definition of a function to output the data stored in a variable of type tourType.
D: Write the definition of a value-returning function that inputs data into a variable of type tourType.
E: Write the definition of a void function with a reference parameter of type tourType to input data in a variable of type tourType.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
# include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include<string>
using namespace std;
// predefined struct timeType
struct timeType
{
int hr;
double min;
int sec;
};
//predefined structure tourType
struct tourType
{
string cityName;
int distance;
timeType travelTime;
};
//A: declare destination of type tourType:
struct tourType destination;
void input(void);
void output(void);
int main()
{
input();
output();
system("pause");
return 0;
}
//B: store tour data for Chicago
void tourInit(struct tourType* tour)
{
tour->cityName = "Chicago";
tour->distance = 550;
tour->travelTime.hr = 9;
tour->travelTime.min = 30;
}
//C: function that outputs data from variable tourType
void output(void)
{
cout << destination.cityName << " "
<< destination.distance << " "
<< destination.travelTime.hr << " "
<< destination.travelTime.min << " "
<< endl;
}
//E: void function to input data into type tourType
void input(void)
{
cout << "\nenter destination city: ";
cin >> destination.cityName;
cout << "\nenter distance in miles: ";
cin >> destination.distance;
cout << "\nenter number of hours: ";
cin >> destination.travelTime.hr;
cout << "\nenter time in minutes: ";
cin >> destination.travelTime.min;
}
|