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

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):
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...
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.
Plz convert this C++ code into JAVA code thanks #include<iostream> using namespace std; //function for calculating...
Plz convert this C++ code into JAVA code thanks #include<iostream> using namespace std; //function for calculating the average sightings from the Total Sightings array float calcAverage(float totalSightings[],int n) {    int i;    float sum=0.0;    for(i=0;i<n;i++)    sum=sum+totalSightings[i];    return sum/n; } int main() {    // n is no. of bird watchers    //flag , flag2 and flag3 are for validating using while loops    int n,i,flag,flag2,flag3;       //ch also helps in validating    char ch;   ...
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++)
using formula OR Excel function. For questions 1 - 4 use a required nominal annual return:...
using formula OR Excel function. For questions 1 - 4 use a required nominal annual return: 5.00% 1. Consider a 1-year CD. Principal value $5,000.00 What is the future value of the CD in 1 year AND what is the effective annual rate? Future Value EFF a. annual compounding? b. semi-annual compounding? c. quarterly compounding? d. monthly compounding? e. daily compounding? 2. Rework problem #1 assuming a 5-year CD with $5000 principal. Future Value EFF a. annual compounding? b. semi-annual...
How to convert wave function to matrix in H2 and LiH . And how to find...
How to convert wave function to matrix in H2 and LiH . And how to find the determinant(energy)?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT