Question

In: Computer Science

Complete the function ConvertToDecadesAndYears to convert totalYears to decades and years. Return decades and years using...

Complete the function ConvertToDecadesAndYears to convert totalYears to decades and years. Return decades and years using the ElapsedDecadesYears struct. Ex: 26 years is 2 decades and 6 years.

#include <iostream>
using namespace std;

struct ElapsedDecadesYears {
   int decadesVal;
   int yearsVal;
};

ElapsedDecadesYears ConvertToDecadesAndYears(int totalYears) {
   ElapsedDecadesYears tempVal;

   /* Your code goes here */

}

int main() {
   ElapsedDecadesYears elapsedYears;
   int totalYears;

   cin >> totalYears;

   elapsedYears = ConvertToDecadesAndYears(totalYears);

   cout << elapsedYears.decadesVal << " decades and " << elapsedYears.yearsVal << " years" << endl;

   return 0;
}

Solutions

Expert Solution

  • Number of decades that can be fit into a year is the quotient of that year when divided by 10.
  • Number of remaining years that after the decades in a year is the remainder of that year when divided by 10.

Code screenshot:

Output:

Code to copy:

#include <iostream>
using namespace std;

struct ElapsedDecadesYears {
int decadesVal;
int yearsVal;
};

ElapsedDecadesYears ConvertToDecadesAndYears(int totalYears) {
ElapsedDecadesYears tempVal;
// we can initialize the value of decadesVal with quotient of totalYears / 10
tempVal.decadesVal = totalYears/10;
// we can initialize the value of yearsVal with remainder of totalYears % 10
tempVal.yearsVal = totalYears%10;
// now we can return the structure object tempVal
return tempVal;
}

int main() {
ElapsedDecadesYears elapsedYears;
int totalYears;
cin >> totalYears;
elapsedYears = ConvertToDecadesAndYears(totalYears);
cout << elapsedYears.decadesVal << " decades and " << elapsedYears.yearsVal << " years" << endl;
return 0;
}


Related Solutions

PYTHON: Complete these functions in the module: f2c, a function to convert Fahrenheit temperatures to Celcius....
PYTHON: Complete these functions in the module: f2c, a function to convert Fahrenheit temperatures to Celcius. c2f, a function to convert Celcius termperatures to Fahrenheit. Write f2c() and c2f() as functions that return a true value or False. In other words, these functions do not print — they return. A "true value", in this case, would be a number that corresponds to a temperature. If the user enters an invalid temperature, the function should return False. Create _main(), a function...
Complete the code so that it can convert the date to day of week using python,...
Complete the code so that it can convert the date to day of week using python, the code should pass the doctest def convert_datetime_to_dayofweek(datetime_string): """ This function takes date in the format MON DAY YEAR HH:MM(PM/AM) and returns the day of the week Assume input string is UTC    >>> convert_datetime_to_dayofweek('Jun 1 2005 1:33PM') 'Wednesday' >>> convert_datetime_to_dayofweek('Oct 25 2012 2:17AM') 'Thursday' """ # code goes here
Complete this return statement so that it could be used in the function body offind_percentageto fulfill...
Complete this return statement so that it could be used in the function body offind_percentageto fulfill the requirements for the last step's program. Fill in the Blanks — Fill in the blanks return ________ /___________
Complete the following program skeleton. When finished, the program will ask the user for a length (in inches), convert that value to centimeters, and display the result. You are to write the function convert.
Complete the following program skeleton. When finished, the program will ask the user for a length (in inches), convert that value to centimeters, and display the result. You are to write the function convert. (Note: 1 inch = 2.54 cm. Do not modify function main.) #include #include using namespace std;// Write your function prototype here.int main(){ double measurement; cout ≪ "Enter a length in inches, and I will convert\n"; cout ≪ "it to centimeters: "; cin ≫ measurement; convert(&measurement); cout...
complete in python The function sumEven should return the sum of only the even numbers contained...
complete in python The function sumEven should return the sum of only the even numbers contained in the list, lst. Example list_of_nums = [1, 5, 4, 8, 5, 3, 2] x = sum_evens(list_of_nums) print(x) #prints 14 Start your code with def evens(lst):
Complete the isScrambled() function to return True if stringA can be reordered to make stringB. Otherwise,...
Complete the isScrambled() function to return True if stringA can be reordered to make stringB. Otherwise, return False. Ignore spaces and capitalization. You must use a list for this assignment. isScrambled( 'Easy', 'Yase' ) returns True isScrambled( 'Easy', 'EasyEasy' ) returns False isScrambled( 'eye', 'eyes' ) returns False isScrambled( 'abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba' ) returns True isScrambled( 'Game Test', 'tamegest' ) returns True.
Write a function using MATLAB that will accept a structure as an argument and return two...
Write a function using MATLAB that will accept a structure as an argument and return two cell arrays containing the names of the fields of that structure and the data types of each field. Be sure to check that the input argument is a structure, and generate an error message if it is not.
Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than...
Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 3, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by " seconds". End with a newline. Example output for ounces = 7: 42 seconds #include <stdio.h> void PrintPopcornTime(int bagOunces) { } int main(void) { int userOunces; scanf("%d", &userOunces); PrintPopcornTime(userOunces); return 0; } 2. Write a function PrintShampooInstructions(), with int parameter numCycles, and void return...
The work function for nickel is 5.15 eV. (a) Convert the value of the work function...
The work function for nickel is 5.15 eV. (a) Convert the value of the work function from electron volts to joules. J (b) Find the cutoff frequency for nickel. Hz (c) What maximum wavelength of light incident on nickel releases photoelectrons from the nickel's surface? nm (d) If light of energy 7.12 eV is incident on nickel, what is the maximum kinetic energy of the ejected photoelectrons? Give the answer in electron volts. eV (e) For photons of energy 7.12...
Using pseudocode or C++ code, write a function to compute and return the product of two...
Using pseudocode or C++ code, write a function to compute and return the product of two sums. The first is the sum of the elements of the first half of an array A. The second is the sum of the elements of the second half of A. The function receives A and N ≥ 2, the size of A, as parameters. (in c++)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT