Question

In: Computer Science

Q18. // This program finds the average time spent programming by a student // each day...

Q18.

// This program finds the average time spent programming by a student
// each day over a three day period.

// PLACE YOUR NAME HERE

#include 
using namespace std;

int main()
{
        int numStudents;
        float numHours, total, average;
        int student, day = 0;   // these are the counters for the loops

        cout << "This program will find the average number of hours a day"
                 << " that a student spent programming over a long weekend\n\n";
        cout << "How many students are there ?" << endl << endl;
        cin >> numStudents;

        for (student = 1; student <= numStudents; student++)
        {
                total = 0;

                for (day = 1; day <= 3; day++)
                {
                        cout << "Please enter the number of hours worked by student "
                                 << student << " on day " << day << "." << endl;
                        cin >> numHours;

                        total = total + numHours;
                }

                average = total / 3;

                cout << endl;
                cout << "The average number of hours per day spent programming by "
                         << "student " << student << " is " << average
                         << endl << endl << endl;
        }

        return 0;
}

Note that the inner loop of this program is always executed exactly three times—once for each day of the long weekend. Modify the code so that the inner loop iterates n times, where n is a positive integer input by the user. In other words, let the user decide how many days to consider just as they choose how many students to consider.

Sample Run:

This program will find the average number of hours a day that a student spent programming over a long weekend

How many students are there?
2
Enter the number of days in the long weekend
2

Please enter the number of hours worked by student 1 on day 1
4

Please enter the number of hours worked by student 1 on day 2
6

The average number of hours per day spent programming by student 1 is 5


Please enter the number of hours worked by student 2 on day 1
9

Please enter the number of hours worked by student 2 on day 2
13

The average number of hours per day spent programming by student 2 is 11

Q19. Modify the program from Q18 so that it also finds the average number of hours per day that a given student studies biology as well as programming. For each given student include two prompts, one for each subject. Have the program print out which subject the student, on average, spent the most time on.

Solutions

Expert Solution

Program:

#include <iostream>
using namespace std;

int main()
{
int numStudents;
float numHours, totalp,totalb, averagep,averageb;
int student, day = 0; // these are the counters for the loops

cout << "This program will find the average number of hours a day"
<< " that a student spent on biology and programming over a long weekend and prints the subject on which more time was spent\n\n";
cout << "How many students are there ?" << endl << endl;
cin >> numStudents;

for (student = 1; student <= numStudents; student++)
{
totalp = 0;
totalb=0;
for (day = 1; day <= 3; day++)
{
cout << "Please enter the number of hours worked by student "
<< student << " in programming on day " << day << "." << endl;
cin >> numHours;

totalp = totalp + numHours;
cout << "Please enter the number of hours worked by student "
<< student << " in biology on day " << day << "." << endl;//read input for biology as well
cin >> numHours;

totalb = totalb + numHours;
}

averagep = totalp / 3;
averageb = totalb / 3;//calculate average for biology
cout << endl;
cout << "The average number of hours per day spent studying programming by "
<< "student " << student << " is " << averagep
<< endl << endl << endl;
cout << "The average number of hours per day spent studying biology by "
<< "student " << student << " is " << averageb
<< endl << endl << endl;
if(averagep>averageb)//check for greater value and print message on console
cout<<"The student spent most time on average on programming subject"<<endl;
else
cout<<"The student spent most time on average on biology subject"<<endl;
}

return 0;
}

Expected Output:

This program will find the average number of hours a day that a student spent on biology and programming over a long weekend and prints the subject on which more time was spent

How many students are there ?

1
Please enter the number of hours worked by student 1 in programming on day 1.
3
Please enter the number of hours worked by student 1 in biology on day 1.
4
Please enter the number of hours worked by student 1 in programming on day 2.
3
Please enter the number of hours worked by student 1 in biology on day 2.
4
Please enter the number of hours worked by student 1 in programming on day 3.
3
Please enter the number of hours worked by student 1 in biology on day 3.
4

The average number of hours per day spent studying programming by student 1 is 3


The average number of hours per day spent studying biology by student 1 is 4


The student spent most time on average on biology subject

Screenshots:

The screenshots are attached below for reference.

Please follow them for output.

Please upvote my answer. Thank you.


Related Solutions

Is the average amount of time spent sleeping each day different between male and female students?...
Is the average amount of time spent sleeping each day different between male and female students? Which hypothesis test is the most appropriate to use in this problem? Why? (Note: if you are doing a 2-sample t-test, make sure you state which one you are doing and why.) If the test you chose has a t-statistic, report it here with degrees of freedom. If it does not, state that the test you chose does not have a test-statistic. Give and...
Q1. In order to estimate the average time spent on the computer terminals per student at...
Q1. In order to estimate the average time spent on the computer terminals per student at a local university, data were collected from a sample of 81 business students over a one-week period. Assume the population standard deviation is 1.2 hours. If the sample mean is 9 hours, then the 95% confidence interval is approximately a. 7.04 to 10.96 hours b. 7.36 to 10.64 hours c. 8.74 to 9.26 hours d. 7.80 to 10.20 hours Q2. In a random sample...
You've surveyed the student body about time spent on coursework each week. The mean (??) is...
You've surveyed the student body about time spent on coursework each week. The mean (??) is 8.3 hours with a standard deviation (??) of .85 hours. What is the probability of a student reporting working 10 hours or more each week on course work? What is the probability of a student reporting 5 hours or less on coursework? What proportion of students report doing coursework between 7 and 9 hours per week? How many hours would a student do coursework...
Using R: write a program that finds the standard deviation between each column. Find the average...
Using R: write a program that finds the standard deviation between each column. Find the average standard deviation for Set A and B, and then use that average to guess the next (fifth) column. Set A: 2, 5, 7, 8 Set B: 2, 3, 6, 9
This program focuses on programming with Java Collections classes. You will implement a module that finds...
This program focuses on programming with Java Collections classes. You will implement a module that finds a simplified Levenshtein distance between two words represented by strings. Your program will need support files LevenDistanceFinder.Java, dictionary.txt, while you will be implementing your code in the LevenDistanceFinder.java file. INSTRUCTIONS The Levenshtein distance, named for it's creator Vladimir Levenshtein, is a measure of the distance between two words. The edit distance between two strings is the minimum number of operations that are needed to...
A television repair shop repair man finds that the time spent on his job has an...
A television repair shop repair man finds that the time spent on his job has an exponential distribution with mean of 30 minutes. If he repairs sets in the order in which they come in and if the arrival of sets is distributed as poisson with an the average rate of 10 per eight hour day, how long must a typical customer wait before a set he drops off is ready to be picked up?
Part 1: Write a program that finds the sum and average of a series of numbers...
Part 1: Write a program that finds the sum and average of a series of numbers entered by the user. The program will first ask the user how many numbers there are. It then prompts the user for each of the numbers in turn and prints out the sum, average, the list of number from the user. Note: the average should always be a float, even if the user inputs are all ints. Part 2: Same as part 1 except...
A survey of 37 men found that an average amount spent on St. Patrick's day of...
A survey of 37 men found that an average amount spent on St. Patrick's day of $91 with a standard deviation of $39. A similar survey of 54 women found they spent an average of $46 with a standard deviation of $17. When testing the hypothesis (at the 5% level of significance) that the variance that men spend more than the variance of what women spend on St. Patrick's day, what is the test statistic? (please round your answer to...
AS According to a research​ institution, men spent an average of ​$136.78 on​ Valentine's Day gifts...
AS According to a research​ institution, men spent an average of ​$136.78 on​ Valentine's Day gifts in 2009. Assume the standard deviation for this population is ​$45 and that it is normally distributed. A random sample of 15 men who celebrate​ Valentine's Day was selected. Complete A-E a. Calculate the standard error of the mean. b. What is the probability that the sample mean will be less than ​$130? c. What is the probability that the sample mean will be...
According to a research​ institution, men spent an average of $132.69 on​ Valentine's Day gifts in...
According to a research​ institution, men spent an average of $132.69 on​ Valentine's Day gifts in 2009. Assume the standard deviation for this population is $45 and that it is normally distributed. A random sample of 10 men who celebrate​ Valentine's Day was selected. Complete parts a through e. a. Calculate the standard error of the mean. sigma Subscript x σx= ​(Round to two decimal places as​ needed.) b. What is the probability that the sample mean will be less...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT