Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ QUESTION. INTRO TO C++ COURSE Write two functions as follows: One function i

ID: 3822453 • Letter: C

Question

C++ QUESTION. INTRO TO C++ COURSE

Write two functions as follows: One function is named all_inches and takes two int parameters, f and i that represent a length in feet and inches. The function returns an int that is the length in all inches, so all_inches(2, 6) returns 30 (2 feet 6 inches = 30 inches). The other function is named feet_inches and takes three parameters, n, f, i. The first parameter is an int that represents a length in all inches, and the other two are output reference parameters that will receive the feet and inches values, so feet_inches(30, ft, in) will set ft to 2 and in to 6.

Write a main program that reads in two lengths from the user as feet and inches and uses the functions to compute the sum of the lengths. Also, use the functions to compute a length that is double the first length entered and another that is triple the second length entered. Print out the sum, double and triple lengths as feet and inches.

Explanation / Answer

#include <iostream>

using namespace std;

int all_inches(int f, int i)
{
return f*12 + i;
}

void feet_inches(int n, int &f, int &i)
{
f = n /12;
i = n%12;
}

int main()
{
int f, i;
cout << "Enter first length feet: ";
cin >> f;

cout << "Enter first length inches: ";
cin >> i;

int f2, i2;
cout << "Enter second length feet: ";
cin >> f2;

cout << "Enter second length inches: ";
cin >> i2;

int length1 = all_inches(f, i);
int length2 = all_inches(f2, i2);

int sumF2, sumI2;
feet_inches(length1+length2, sumF2, sumI2);

cout << "Sum of length " << sumF2 << " feet " << sumI2 << " inches." << endl;

int doubleF1, doubleI1;
feet_inches(2*length1, doubleF1, doubleI1);

cout << "Double of first length " << doubleF1 << " feet " << doubleI1 << " inches." << endl;

int tripleF2, tripleI2;
feet_inches(3*length2, tripleF2, tripleI2);
cout << "Triple of second length " << tripleF2 << " feet " << tripleI2 << " inches." << endl;

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote