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...
Write a c program that will return 1 if the argument passed is a digit and...
Write a c program that will return 1 if the argument passed is a digit and zero otherwise. Use the following function int isNumber(char *c) to do that. Do not use && or || logical operator. Write a full c program that has the header required and will accept the user entry.
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...
Write a method that will have a C++ string passed to it. The string will be...
Write a method that will have a C++ string passed to it. The string will be an email address and the method will return a bool to indicate that the email address is valid. Email Validation Rules: ( These rules are not official.) 1) No whitespace allowed 2) 1 and only 1 @ symbol 3) 1 and only 1 period allowed after the @ symbol. Periods can exist before the @ sign. 4) 3 and only 3 characters after the...
Write a method that will have a C++ string passed to it. The string will be...
Write a method that will have a C++ string passed to it. The string will be an email address and the method will return a bool to indicate that the email address is valid. Email Validation Rules: ( These rules are not official.) 1) No whitespace allowed 2) 1 and only 1 @ symbol 3) 1 and only 1 period allowed after the @ symbol. Periods can exist before the @ sign. 4) 3 and only 3 characters after the...
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()...
Q#2 Write a C++ program that reads 10 integer values and stores them in an array....
Q#2 Write a C++ program that reads 10 integer values and stores them in an array. The program should find and display the average of the array elements and how many elements are below the average.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT