Question

In: Computer Science

In the space provided below write a C++ program that asks the user to enter their...

In the space provided below write a C++ program that asks the user to enter their quarterly earnings for the past two years stores the data in a 2-dimensional array. The program then computes both the annual earnings as well as the total earning and prints the results along with the 2-dimensional array on screen as well as onto a file.

Solutions

Expert Solution

CODE

#include<iostream>
#include<fstream>

using namespace std;

int main(){
//opening the file
fstream file;
file.open("output.txt",ios::out);
//earning 2D array
float earnings[2][4];
//annual earning array
float annualEarnings[] = {0,0};
float totalEarning=0;
//asking the user to enter the earnings
for(int i=0;i<2;i++){
//asking the user to enter the earnings quarter by quarter
cout<<"Enter for year "<<(i+1)<<": "<<endl;
for(int j=0;j<4;j++){
cout<<"Enter for quarter: "<<(j+1)<<": ";
cin>>earnings[i][j];
}
}
//printing the output on the screen and file
for(int i=0;i<2;i++){
cout<<"\nEarning for year "<<(i+1)<<": "<<endl;
file<<"\nEarning for year "<<(i+1)<<": "<<endl;
for(int j=0;j<4;j++){
//printing the 2d array in the file and on the screen
cout<<"Quarter "<<(j+1)<<": "<<earnings[i][j]<<endl;
file<<"Quarter "<<(j+1)<<": "<<earnings[i][j]<<endl;
annualEarnings[i] += earnings[i][j];
}
cout<<endl;
file<<endl;
}
//printing the total earnings in the file and on the screen
totalEarning = annualEarnings[0] + annualEarnings[1];
cout<<"\nEarning for year 1: $"<<annualEarnings[0]<<endl;
cout<<"Earning for year 2: $"<<annualEarnings[1]<<endl;
cout<<"Total Earning $"<<totalEarning<<endl;
file<<"\nEarning for year 1: $"<<annualEarnings[0]<<endl;
file<<"Earning for year 2: $"<<annualEarnings[1]<<endl;
file<<"Total Earning $"<<totalEarning<<endl;
//closing the file
file.close();
  
return 0;
}
_____________________________________

CODE IMAGES:

________________________________________

OUTPUT:

output.txt

___________________________________________

Feel free to ask any questions in the comments section

Thank You!


Related Solutions

In the space provided below write a ******C program********* that asks the user to enter their...
In the space provided below write a ******C program********* that asks the user to enter their quarterly earnings for the past two years stores the data in a 2-dimensional array. The program then computes both the annual earnings as well as the total earning and prints the results along with the 2-dimensional array on screen. Using the embed icon shown above, also include screenshots demoing the execution of your program. Please write carefully. Thank you
c program Write a program that asks the user to enter a sequence of 15 integers,...
c program Write a program that asks the user to enter a sequence of 15 integers, each either being 0, 1, or 2, and then prints the number of times the user has entered a "2" immediately following a "1". Arrays are not allowed to appear in your code. Include ONLY THE SCREENSHOT OF YOUR CODE in an image file and submit the file.
Write a C++ program that asks the user to enter the monthly costs for the following...
Write a C++ program that asks the user to enter the monthly costs for the following expenses incurred from operating your automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and a projected total annual cost of these expenses. Label each cost. The labels should be left aligned and have a column width of 30 characters. The cost should be aligned right and displayed with two decimal places...
Write a C program that loops and asks a user to enter a an alphanumeric phone...
Write a C program that loops and asks a user to enter a an alphanumeric phone number and converts it to a numeric one. No +1 at the beginning. You can put all code in one quiz1.c file or put all functions except main in phone.c and phone.h and include it in quiz1.c Submit your *.c and .h files or zipped project */ #pragma warning (disable: 4996) //windows #include <stdio.h> #include <string.h> #include <stdbool.h> #include <ctype.h> enum { MaxLine =...
C++ write a program that asks the user to enter the hours and rate then calculate...
C++ write a program that asks the user to enter the hours and rate then calculate the gross pay for an employee, the program should test if the hours are regular (40), any hour more than 40 should be paid with the overtime rate: 1.5*rate. The program should ask repeatedly the user if he/she wants to continue: y or n, if the user types y, then the program should ask for the hours and rate for another employee then display...
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
C++. Write a program that asks the user to enter a single word and outputs the...
C++. Write a program that asks the user to enter a single word and outputs the series of ICAO words that would be used to spell it out. The corresponding International Civil Aviation Organization alphabet or ICAO words are the words that pilots use when they need to spell something out over a noisy radio channel. See sample screen output for an example: Enter a word: program Phonetic version is: Papa Romeo Oscar Golf Romeo Alpha Mike The specific requirement...
Write a C++ program that asks the user to enter in three numbers and displays the...
Write a C++ program that asks the user to enter in three numbers and displays the numbers in ascending order. If the three numbers are all the same the program should tell the user that all the numbers are equal and exits the program. Be sure to think about all the possible cases of three numbers. Be sure to test all possible paths. Sample Runs: NOTE: not all possible runs are shown below. Sample Run 1 Welcome to the order...
Using the code below as a template, write a program that asks the user to enter...
Using the code below as a template, write a program that asks the user to enter two integers, and finds and prints their greatest common denominator (GCD) in Java! package cp213; import java.util.Scanner; public class Lab01 { /** * @param a * @param b * @return */ public static int gcd(int a, int b) { // your code here } /** * @param args */ public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int a = 0;...
in C++, Write a program that asks the user to enter 6 numbers. Use an array...
in C++, Write a program that asks the user to enter 6 numbers. Use an array to store these numbers. Your program should then count the number of odd numbers, the number of even numbers, the negative, and positive numbers. At the end, your program should display all of these counts. Remember that 0 is neither negative or positive, so if a zero is entered it should not be counted as positive or negative. However, 0 is an even number....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT