Question

In: Computer Science

Question: We have 10 students that each of them passed 3 tests. Write a c++ program...

Question: We have 10 students that each of them passed 3 tests. Write a c++ program that asks each student to enter 3 grades for each test and then find the average by using nested loop. Validate each grade. (before getting the grade test it whether it is greater than 0 and less than 100).

Solutions

Expert Solution

#include <iostream>

using namespace std;

int main()
{
//variable declaration
int test[3], grade;
float avg[10];
  
//get user input
for(int i=0; i<10; i++)
{
cout<<"Enter the grade of student "<<(i+1)<<": "<<endl;
  
for(int k=0; k<3; k++)
{
cout<<"Test "<<(k+1)<<": ";
cin>>grade;
if(grade>=0 && grade<=100)
{
test[k] = grade;
}
}
  
avg[i] = (test[0]+test[1]+test[2]) / 3.0;
}
//display the average grade
cout<<endl<<"The average grades are given below: "<<endl;
for(int i=0; i<10; i++)
{
cout<<"Average grade of student "<<(i+1)<<" = "<<avg[i]<<endl;
}   

return 0;
}

OUTPUT:

Enter the grade of student 1:
Test 1: 40
Test 2: 50
Test 3: 60
Enter the grade of student 2:
Test 1: 50
Test 2: 60
Test 3: 70
Enter the grade of student 3:
Test 1: 80
Test 2: 60
Test 3: 50
Enter the grade of student 4:
Test 1: 40
Test 2: 30
Test 3: 20
Enter the grade of student 5:
Test 1: 30
Test 2: 40
Test 3: 65
Enter the grade of student 6:
Test 1: 67
Test 2: 87
Test 3: 90
Enter the grade of student 7:
Test 1: 30
Test 2: 29
Test 3: 49
Enter the grade of student 8:
Test 1: 54
Test 2: 65
Test 3: 67
Enter the grade of student 9:
Test 1: 89
Test 2: 90
Test 3: 98
Enter the grade of student 10:
Test 1: 54
Test 2: 23
Test 3: 50

The average grades are given below:
Average grade of student 1 = 50
Average grade of student 2 = 60
Average grade of student 3 = 63.3333
Average grade of student 4 = 30
Average grade of student 5 = 45
Average grade of student 6 = 81.3333
Average grade of student 7 = 36
Average grade of student 8 = 62
Average grade of student 9 = 92.3333
Average grade of student 10 = 42.3333



Related Solutions

Write push and pop functions on C/C++. Have a program having 10 random integers(hardcoded)and put them...
Write push and pop functions on C/C++. Have a program having 10 random integers(hardcoded)and put them on your stack. Also, print them. Read a character from the keyboard. If the character is an “o” then pop from the stack but don’t print. If the character is a “p”, then pop from the stack and print that number. If the character is an “e” or the stack is empty, end the program.
write a program in C Write a function that is passed an array of characters containing...
write a program in C Write a function that is passed an array of characters containing letter grades of A, B, C, D, and F, and returns the total number of occurrences of each letter grade. Your function should accept both lower and upper case grades, for example, both 'b' and 'B' should be bucketed into your running total for B grades. Any grade that is invalid should be bucketed as a grade of 'I' for Incomplete. You must use...
Question 1: Write a C program that reads a date from the keyboard and tests whether...
Question 1: Write a C program that reads a date from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format: mm/dd/yyyy Note that there is no space in the above format. A date in this format must be entered in one line. A valid month...
C# language Question: You need to write a program for students who receive bursaries in the...
C# language Question: You need to write a program for students who receive bursaries in the department, managing the free hours they have to do. For each recipient you store the recipient’s name and the number of hours outstanding. All recipients start with 90 hours. Implement class Recipients which has the private attributes Name and Hours. In addition to the constructor, the class has the following methods: public String getName() // Returns the name of the recipient public int getHours()...
Write a C++ program that prints out all of the command line arguments passed to the...
Write a C++ program that prints out all of the command line arguments passed to the program. Each command line argument should be separated from the others with a comma and a space. If a command line argument ends in a comma, then another comma should NOT be added
Question: Write a complete C++ program that runs multiple tests and calculations using switch statement. Based...
Question: Write a complete C++ program that runs multiple tests and calculations using switch statement. Based on your input and the selection from the keyboard, the program does the followings. If the selection is 1, the program should test the input if it’s positive, negative or zero. For example, the output should be “The selection is 1 to test the input value if it’s positive, negative or equal to zero. The input value 7 is positive” If the selection is...
Write a program in C (NOT C++ or C#) The program inputs 5 elements into each...
Write a program in C (NOT C++ or C#) The program inputs 5 elements into each of 2 integer arrays. Multiply corresponding array elements, that is, arrayOne[0] * arrayTwo[0], etc. Save the product into a third array called prodArray[ ]. Display the product array.
C++ Program: Write a program that prompts the user for two numbers and stores them in...
C++ Program: Write a program that prompts the user for two numbers and stores them in signed integers. The program should then add those two numbers together and store the result in a signed integer and display the result. Your program should then multiply them by each other and store the result in another integer and display the result. Then do the same but with dividing the first number by the second. Display an error message to the screen if...
Question : Write a C++ program to find all prime numbers between 10 to 100 by...
Question : Write a C++ program to find all prime numbers between 10 to 100 by using while loop. Hint: a prime number is a number that is divisible by 1 and itself. For example 3, 5, 7, 11, 13 are prime numbers because they are only divisible by 1 and themselves.
(IN C) Program Question 2: Write a program that solves for c in the Pythagorean Theorem:...
(IN C) Program Question 2: Write a program that solves for c in the Pythagorean Theorem: a2 + b2 = c2 The user will enter values for a and b, and you will calculate c. All of this code will go in just one source file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT