In: Computer Science
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
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: