LAB 5.4 Nested Loops Bring in program nested.cpp from the Lab 5 folder (this is Sample Program 5.6 from the Pre-lab Reading Assignment). The code is shown below: // 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; }   Exercise 1: 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 1 on day 2. 6 The average number of hours pre day spent programming by student 1 is 5.   please enter the number of hours worked by student 2 on day 1. 9 please enter number of hour word by student 2 on day 2. 13 the average number of hour per day spent programming by student 2 is 11. Exercise 2: Modify the program from Exercise 1 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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Topic Video
Question

LAB 5.4 Nested Loops
Bring in program nested.cpp from the Lab 5 folder (this is Sample Program 5.6
from the Pre-lab Reading Assignment). The code is shown below:

// This program finds the average time spent programming by a student

// each day over a three day period.

 

// PLACE YOUR NAME HERE

 

#include <iostream>

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;

}

 

Exercise 1: 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 1 on day 2.

6

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

 

please enter the number of hours worked by student 2 on day 1.

9

please enter number of hour word by student 2 on day 2.

13

the average number of hour per day spent programming by student 2 is 11.

Exercise 2: Modify the program from Exercise 1 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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education