Question: 10-4: Record Data Types The exercises in this lesson use the declarations in file Distance.cpp. Distance is defined as a record type with three fields:

10-4: Record Data Types

The exercises in this lesson use the declarations in file Distance.cpp.

Distance is defined as a record type with three fields: feet, yards, and miles. The following three operations (functions) are defined on variables of Distance:

ConvertFeet: Converts feet into a variable of type Distance. For example, 6002 feet is converted to 2 feet, 240 yards, 1 mile.

ConvertYards: Converts yards into a variable of type Distance. For example, 5230 yards is converted to 0 feet, 1710 yards, 2 miles.

PrintDistance: Prints a variable of type Distance.

Exercise 1: Fill in the missing code in these operations involving struct Distance.

Exercise 2: Fill in the missing code in function main that tests the operations with the data used in the description of the operations. Describe any bugs in your implementation and correct them.

Exercise 3: Write a function that takes a variable of type Distance and a time (in minutes) and calculates miles per hour. Convert the variable of type Distance to miles (a float variable) before performing the calculation. The result should be a float value representing miles per hour rather than a value of Distance. Your function heading should be as shown below:

float MilesPerHour(Distance distance, long time)

Use your function to calculate miles per hour where the distance is (15,000 feet + 12,000 yards + 37 miles) and the time is 45 minutes.

Miles per hour traveled: ___________

code: distance.cpp

//***************************************************** // Program Distance converts either yards or feet to // a record of type Distance. //*****************************************************

#include using namespace std;

struct Distance { long feet; long yards; long miles; };

Distance ConvertYards(long yards); // Post: yards has been converted into a variable of // type Distance.

Distance ConvertFeet(long feet); // Post: feet has been converted into a variable of // type Distance.

void PrintDistance(Distance distance); // Post: A vriable of type Distance is printed as feet, // yards, and miles.

int main() { // FILL IN code to test the operations involving // struct Distance. }

//********* Distance Operations ********************

Distance ConvertYards(long yards) { // FILL IN Code to convert yards to a variable of Distance. }

//******************************************************

Distance ConvertFeet(long feet) { // FILL IN Code to convert feet to a variable of Distance. }

//******************************************************

void PrintDistance(Distance Distance) { // FILL IN Code to print a variable of Distance. }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!