Question

In: Computer Science

3. Write a C++ program that takes in the name of a store, and the following...

3. Write a C++ program that takes in the name of a store, and the following details for 4 employees working at the store; their first name, last name, number of hours they worked that week and how much they are paid per hour. Your program should output the name of the store, along with each employee's full name and how much they earned that week in the manner below. Monetary values should be format to 2 decimal places. Also consider that a store could have as many words contained in it's name (Best Buy, Harris Tetter, The Home Depot)

Ballack's Electronic Store

Jon Snowden $452.50

Midoriya Izuku    $363.99

Thomas Muller $1322.00

Senku Ishigami $895.50

Use the different output formatting methods

Solutions

Expert Solution

Please find below code and don't forget to give a Like.

Please refer below code with explanation in comments and output.

Code:

#include <iostream>
#include<iomanip>
#include<math.h>

using namespace std;
float rounding(float value){
float var=(int)(value*100+.5);
return (float)var/100;
}

int main()
{   
//storing firstname and lastname in string array
string firstname[4]={"Jon","Midoriya","Thomas","Senku"};
string lastnamr[4]={"Snowden","Izuku","Muller","Ishigami"};
//stoing price per hour and hours worked in a week in float array
float price_perhour[4]={20,30,15.5,25.5};
float hours_worked[4]={50,60,45,35};
float total_price[4];
string store[1]={"Ballack's Electronic Store"};
//using for loop to run and calculate the total price of that employee
for(int i=0;i<=3;i++){
total_price[i]=price_perhour[i]*hours_worked[i];
}
cout<<store[0]<<endl;
for(int j=0;j<=3;j++){
//here calling rounding function to round of the decimal values to 2 places
cout<<firstname[j]<<" "<<lastnamr[j]<<" "<<rounding(total_price[j])<<endl;
}


return 0;
}

Output:


Related Solutions

Write a program in c# that declare a variable and store user name jjohn in. Then,...
Write a program in c# that declare a variable and store user name jjohn in. Then, write a statement that will make your program display at the screen the content of that variable, followed by " I would like to know your height in centimeter. Please enter it:". Then, write a statement that will store the value entered by the user, allowing decimal numbers ie some precision, a fraction part. Finally, write statements (more than one can be needed) so...
Write a C++ program that takes input from the keyboard of the 3 dimensions of a...
Write a C++ program that takes input from the keyboard of the 3 dimensions of a room (W,L,H in feet) and calculates the area (square footage) needed to paint the walls only. Use function overloading in your program to pass variables of type int and double. You should have two functions: one that accepts int datatypes and one that accepts double datatypes. Also assume a default value of 8 if the height parameter is omitted when calling the functions.
Write a program that does the following in C++ 1 ) Write the following store data...
Write a program that does the following in C++ 1 ) Write the following store data to a file (should be in main) DC Tourism Expenses 100.20 Revenue 200.50 Maryland Tourism Expenses 150.33 Revenue 210.33 Virginia Tourism Expenses 140.00 Revenue 230.00 2 ) Print the following heading: (should be in heading function) Store name | Profit [Note: use setw to make sure all your columns line up properly] 3 ) Read the store data for one store (should be in...
Write c code program for the following Write a function, circle, which takes the radius of...
Write c code program for the following Write a function, circle, which takes the radius of a circle from the main function and assign the area of the circle to the variable, area, and the perimeter of the circle to the variable, perimeter. Hint: The function should have three variables as input. Since the contents of the variables are to be modified by a function, it is necessary to use pointers. Please type out the full usable program. Thank you.
Write a C++ program to display toy name
Write a C++ program to display toy name
Write a program in C that takes the length and the integers to be stored in...
Write a program in C that takes the length and the integers to be stored in an array and shifts array by N positions. Example: Input the number of elements to store in the array (max 10) : 5 Input 5 integers to be stored : Index - 0 : 12 Index - 1 : 29 Index - 2 : 68 Index - 3 : 32 Index - 4 : 97 Input number of shifts : 2 Expected Output :...
Q#3 Write a C++ program to read 10 temperatures in Celsius and to store the temperatures...
Q#3 Write a C++ program to read 10 temperatures in Celsius and to store the temperatures in an array of integers, then it should convert the temperatures to Fahrenheit and store the new values rounded to the nearest integer in another array . The program should display both temperatures in a table form.    F = 9/5 x C + 32 where F is temp in Fahrenheit and C temperature in Celsius
In C++ Write a program to store exam scores into a file. The program will ask...
In C++ Write a program to store exam scores into a file. The program will ask the user how many exam scores to enter. Then it will ask the user for each exam score and store them in a file called scores.dat The file output should have the following format: Exam 1: 97 Exam 2: 85
Write a program named filemaker.py in python that will be used to store the first name...
Write a program named filemaker.py in python that will be used to store the first name and age of some friends in a text file named friends.txt. The program must use a while loop that prompts the user to enter the first name and age of each friend. Each of these entries should be written to its own line in the text file (2 lines of data per friend). The while loop should repeat until the user presses Enter (Return...
Tail of a File, C++ Program. write a program that asks the user for the name...
Tail of a File, C++ Program. write a program that asks the user for the name of a text file. The program should display the last 10 lines, or all lines if less than 10. The program should do this using seekg Here is what I have so far. #include<iostream> #include<fstream> #include<string> using namespace std; class File { private:    fstream file;    string name; public:    int countlines();    void printlines(); }; int File::countlines() {    int total =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT