Question

In: Computer Science

Implement a version with the outer loop, with a while loop, and the inner loop with...

Implement a version with the outer loop, with a while loop, and the inner loop with a do / while loop.

Modify this program as he ask ↑↑↑ C++

// This program averages test scores. It asks the user for the
2 // number of students and the number of test scores per student.
3 #include <iostream>
4 #include <iomanip>
5 using namespace std;

6
7 int main()
8 {
9 int numStudents, // Number of students
10 numTests; // Number of tests per student
11 double total, // Accumulator for total scores
12 average; // Average test score
13
14 // Set up numeric output formatting.
15 cout << fixed << showpoint << setprecision(1);
16
17 // Get the number of students.
18 cout << "This program averages test scores.\n";
19 cout << "For how many students do you have scores? ";
20 cin >> numStudents;
21
22 // Get the number of test scores per student.
23 cout << "How many test scores does each student have? ";
24 cin >> numTests;
25
26 // Determine each student's average score.
27 for (int student = 1; student <= numStudents; student++)
28 {
29 total = 0; // Initialize the accumulator.
30 for (int test = 1; test <= numTests; test++)
31 {
32 double score;
33 cout << "Enter score " << test << " for ";
34 cout << "student " << student << ": ";
35 cin >> score;
36 total += score;
37 }
38 average = total / numTests;
39 cout << "The average score for student " << student;
40 cout << " is " << average << ".\n\n";
41 }
42 return 0;
43 }

Solutions

Expert Solution

Ans

code:-

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

int numStudents,

numTests; // Number of tests per student

double total, //Accumulator for total scores

average; // Average test score

// Set up numeric output formatting.

cout << fixed << showpoint << setprecision(1);

// Get the number of students.

cout << "This program averages test scores.\n";

cout << "For how many students do you have scores? ";

cin >> numStudents;

// Get the number of test scores per student.

cout << "How many test scores does each student have? ";

cin>>numTests;

// Determine each student's average score.

int student=1;

while (student <= numStudents)

{

total = 0; // Initialize the accumulator.

int test=1;

do

{

double score;

cout << "Enter score " << test << " for ";

cout << "student " << student << ": ";

cin >> score;

total += score;

test++;

}

while(test<=numTests);

average = total / numTests;

cout << "The average score for student " << student;

cout << " is " << average << ".\n\n";

student++;

}

return 0;

}

If any doubt ask in the comments.

Please appreciate the work by giving a thumbs up.


Related Solutions

Modify the previous program to use the Do-While Loop instead of the While Loop. This version...
Modify the previous program to use the Do-While Loop instead of the While Loop. This version of the program will ask the user if they wish to enter another name and accept a Y or N answer. Remove the "exit" requirement from before. Output: Enter the full name of a person that can serve as a reference: [user types: Bob Smith] Bob Smith is reference #1 Would you like to enter another name (Y or N)? [user types: y] Enter...
Document the arrays, using a chart with columns titled: outer loop, inner loop, i, j, and...
Document the arrays, using a chart with columns titled: outer loop, inner loop, i, j, and x. Finally, draw a picture of each array (after the program portion has executed). (5 pts) int[][] arr1 = new int[5][5]; int[][] arr2 = new int[5][5]; x = 1; for(int i = 0; I < 5; i++) { for(int j = 1; j < 6; j++) { arr1[i][j-1] = x; x++; if(x == 6) x += 2; } } for(int i = 4; i...
Create a PL/SQL anonymous block that uses a nested loop (inner loop 1 to 15; outer...
Create a PL/SQL anonymous block that uses a nested loop (inner loop 1 to 15; outer loop 1 to 5) to perform computations using the SQL functions, ABS, EXP, SQRT, ROUND, MIN, MAX, LOG, MOD, REMAINDER and POWER The outer loop will use the functions, ABS, EXP, SQRT, ROUND to display the following messages (must be “ The absolute value of <outer loop index> is <value>” “ The value of e to the <outer loop index> power is <value>” “...
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version)...
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version) The recursive ternarySearch method returns true or false depending if the element was found or not. The ternarySearch method works in a similar manner to a binary search except it uses two mid values that “divide” the array into three portions. So, it needs to consider three recursive scenarios: See sample run: Accounts are: [0] 5658845 [1] 8080152 [2] 1005231 [3] 4520125 [4] 4562555...
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version)...
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version) The recursive ternarySearch method returns true or false depending if the element was found or not. The ternarySearch method works in a similar manner to a binary search except it uses two mid values that “divide” the array into three portions. So, it needs to consider three recursive scenarios: See sample run: Accounts are: [0] 5658845 [1] 8080152 [2] 1005231 [3] 4520125 [4] 4562555...
Give an example of an inner and outer class. (Java)
Give an example of an inner and outer class. (Java)
3. Assume an annulus of inner radius r1 and outer radius r2. The inner surface is...
3. Assume an annulus of inner radius r1 and outer radius r2. The inner surface is at T1, the outer surface at T2, T1 > T2. Assume heat transfer between the surfaces by conduction, with a variable conductivity, k = a + bT, develop an expression for the temperature in the material of the annulus.
Open Average Test Scores while loop, comment out the while loop and add a for loop...
Open Average Test Scores while loop, comment out the while loop and add a for loop that averages 4 test scores. Code C# While loop code using System; class Program { static void Main() { int count = 0, total = 0, number;    while (count < 3) { Console.Write("Enter a number: "); number = Convert.ToInt32(Console.ReadLine()); total += number; count++; }    double average = total / 3.0; Console.Write("Average = " + average.ToString("####0.00")); } }
A hollow, conducting sphere with an outer radius of .250 m and an inner radius of...
A hollow, conducting sphere with an outer radius of .250 m and an inner radius of .200 m has a uniform surface charge density of -6.37 muC/me2.When a charge is now introduced at the center of the cavity inside the sphere, the new charge density on the outside of the sphere is -4.46 muC/me2. What is the charge at the center of the cavity?
A potential difference of V0 is maintained between the inner and outer conductor of a coaxial...
A potential difference of V0 is maintained between the inner and outer conductor of a coaxial cable of length L, inner conductor radius a, and outer conductor radius b. (a) Calculate the current through the medium (∈,σ) using the analogy of ?⃗ and ?⃗⃗⃗. (b) Now, assume that V0 = 500 V, L = 50 m, a = 2 cm and b = 6 cm, and the relative permittivity and the conductivity of the medium are ∈?=3 and σ=5 μS/m,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT