plz do a,b and c CSC 126 Spring 2016 Final B 2 points) suppose the weekly bours
ID: 3581145 • Letter: P
Question
plz do a,b and c
Explanation / Answer
answer for a:
#include <iostream>
using namespace std;
int main()
{
int hours[4][7] = {0};
return 0;
}
--------------------
answer for b:
It looks like the question is wrongly printed as sum is initialized to 0 inside for loop with 'i'. The output with the given program is below:
Employee 1 processed...
Employee 2 processed...
Employee 3 processed...
Employee 4 processed...
Weekend Totals: 7
Program written is below:
#include <iostream>
using namespace std;
int main()
{
int hours[4][7] = {
{2,4,3,4,5,8,8},
{7,3,5,3,3,4,4},
{3,3,4,3,4,3,2},
{9,3,4,7,3,4,1}
};
int i,j,sum=0;
for(i=0;i<4;i++){
sum=0;
for(j=4;j<6;j++)
sum=sum+hours[i][j];
cout << "Employee " << i+1 << " processed..."<<endl;
}
cout << "Weekend Totals: " << sum << endl ;
return 0;
}
The purpose of the program looks to find the total of the weekend for all the employees. I tweaked the program to look like below(just commented sum=0):
#include <iostream>
using namespace std;
int main()
{
int hours[4][7] = {
{2,4,3,4,5,8,8},
{7,3,5,3,3,4,4},
{3,3,4,3,4,3,2},
{9,3,4,7,3,4,1}
};
int i,j,sum=0;
for(i=0;i<4;i++){
//sum=0;
for(j=4;j<6;j++)
sum=sum+hours[i][j];
cout << "Employee " << i+1 << " processed..."<<endl;
}
cout << "Weekend Totals: " << sum << endl ;
return 0;
}
and for this program output is:
Employee 1 processed...
Employee 2 processed...
Employee 3 processed...
Employee 4 processed...
Weekend Totals: 34
--------------------------------------
#include <iostream>
using namespace std;
int main()
{
int hours[4][7] = {
{2,4,3,4,5,8,8},
{7,3,5,3,3,4,4},
{3,3,4,3,4,3,2},
{9,3,4,7,3,4,1}
};
int i,j,highest=0;
for(i=0;i<4;i++){
for(j=0;j<7;j++){
if(hours[i][j]>highest)
highest=hours[i][j];
}
}
cout << "Highest number " << highest << endl ;
return 0;
}
output:
Highest number 9
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.