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

A company\'s performance is judged based on their earnings for every quarter of

ID: 3889248 • Letter: A

Question

A company's performance is judged based on their earnings for every quarter of the year. Create a C++ n called Earnings.cpp: Ask the user for the starting year (Input validation: do not accept a number less than 2000 or greater than 2017). e Ask the user for the final year (Input validation: do not accept a number less than 2000 or greater than 2017). For each of the years, ask the user to enter the earnings for each quarter (Q1Q2, Q3, and Q4) in US Dollars. Earnings for a quarter may be negative, meaning the company lost money in that quarter Earnings only need to be in integers. At the end, calculate the total carnings during the years, making sure to use proper units (S) and precision. A sample run of the program is shown below. . Enter the starting year: 2014 Enter the ending year: 2016 Enter the earnings for 2014 Q1 $123000 Enter the earnings for 2014 Q2: $65000 Enter the earnings for 2014 Q3: $-9000 Enter the earnings for 2014 Q4 $11000 Enter the earnings for 2015 Q1: $-10000 Enter the earnings for 2015 Q2: $40000 Enter the earnings for 2015 Q3 $120000 Enter the eanings for 2015 Q4 $125000 Enter the earnings for 2016 Q1: $80000 Enter the eanings for 2016 Q2: $90000 Enter the earnings for 2016 Q3: $10000 Enter the earnings for 2016 Q4: $100000 The total earnings during years 2014-2016 was $745000

Explanation / Answer

#include <iostream>
#include <string>

using namespace std;
int main()
{
//Variables for taking the starting year and the ending year
int start,ending;
cout<<"Enter the starting year : ";
//taking the starting year as the input
cin>>start;
cout<<"Enter the ending year : ";
//taking the ending year as the input
cin>>ending;
//calculating the difference between the years
//The total number of years will be the difference as well as the starting year. Hence the 1 was added to the difference.
int diff=ending-start+1;
//Array to store the values for the 4 quarters for each year.
float arr[diff][4];
//variables for iteration
int i,j;
//variable to take the value as the input
string val;
int sum;
sum=0;
//Iterating for the each year between the starting year and the ending year.
for(i=start;i<=ending;i++)
{
//iterating for all the 4 quarters
for(j=0;j<4;j++)
{
cout<<"Enter the earnings for "<<i<<" Q"<<j<<" : ";
//Value is taken input as a string
cin>>val;
//Value is converted to integer using the function stoi() ie string to integer
////Substring is also used to ignore the $ sign given as the input
arr[i-start][j]=stoi(val.substr(1,val.length()));
sum=sum+arr[i-start][j];
}
}
//printing the total earnings.
cout<<"The total earnings during the years "<<start<<"-"<<ending<<" was $"<<sum<<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