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

70.2K

Verified Solution

Question

Programming

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 executedexactly three times—once for each day of the long weekend. Modifythe code so that the inner loop iterates n times, where n is apositive integer input by the user. In other words, let the userdecide how many days to consider just as they choose how manystudents to consider.

Sample Run:

This program will find the average number of hours a day that a student spent programming over a long weekendHow many students are there?2Enter the number of days in the long weekend2Please enter the number of hours worked by student 1 on day 14Please enter the number of hours worked by student 1 on day 26The average number of hours per day spent programming by student 1 is 5Please enter the number of hours worked by student 2 on day 19Please enter the number of hours worked by student 2 on day 213The average number of hours per day spent programming by student 2 is 11

Q19. Modify the program from Q18 so that it also findsthe average number of hours per day that a given student studiesbiology as well as programming. For each given student include twoprompts, one for each subject. Have the program print out whichsubject the student, on average, spent the most timeon.

Answer & Explanation Solved by verified expert
3.8 Ratings (433 Votes)
Programinclude using namespace    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students