Create pseudocode and C++ code for a program that creates a report containing a
ID: 3769179 • Letter: C
Question
Create pseudocode and C++ code for a program that creates a report containing a breakdown of payroll by department. Input includes each employee's department number, hourly salary, and number of hours worked. The output is a list of the seven departments in the company and the total gross payroll (rate times hours) for each department The department names are shown below. If an invalid department number is entered, your program should display an error message and re-prompt for another department number. You will need to implement this program using a sentinel loop and parallel arrays.
Department Number Department Name
1 Personnel
2 Marketing
3 Manufactoring
4 Computer Service
5 Sales
6 Accounting
7 Shipping
Explanation / Answer
PseudoCode:
int SENTINEL
string[7] departments
input n
while(n != SENTINEL)
if(n present in departments)
input Hourly Salary
input No. Hours Worked
add Hourly Salary, No. Hours Worked in department[n]
else
throws Error
for(i = 1 to 7)
output department[i]
rate = 0
for(j = 0 to department[i].size)
rate += (department[j].salary) * (department[j].hours)
output rate
end
C++ Code;
<code>
#include<bits/stdc++.h>
using namespace std;
#define SENTINEL 1000
struct node{
int denum;
int hsalary;
int hworked;
};
int main()
{
map<int,string>md;
md[1] = "Personnel";
md[2] = "Marketing";
md[3] = "Manufactoring";
md[4] = "Computer Service";
md[5] = "Sales";
md[6] = "Accounting";
md[7] = "Shipping";
map<int,vector<node> > mp;
map<int,vector<node> >::iterator it;
vector<node>::iterator iit;
int n;
int i = 0;
cout<<"Enter department number:";
cin >> n;
while(n != SENTINEL){
if (md.count(n)){
node a;
a.denum = n;
cout<<"Enter hourly salary:";
cin >> a.hsalary;
cout<<"Enter number of hours worked:";
cin >> a.hworked;
mp[n].push_back(a);
}else{
cout<<"Invalid department number entered ";
}
cout<<"Enter department number:";
cin >> n;
}
for(int i = 1;i < 8;i++){
cout<< md[i];
int rate = 0;
for(iit = (mp[i]).begin(); iit != (mp[i]).end();iit++){
rate += (iit->hsalary * iit->hworked);
}
cout<<" "<<rate<<endl;
}
return 0;
}
</code>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.