Write a C++ program to obtain the Mid_term and Final exam scores for 10 students
ID: 3941516 • Letter: W
Question
Write a C++ program to obtain the Mid_term and Final exam scores for 10 students (Student 1 to Student 10) from the user and then compute and print the following:
1 Total score, where Total score = 40% (Mid_term) + 60%(Final).
2 Maximum score in Mid-Term exam and the corresponding student
3 Maximum score in Final exam and the corresponding student
Requirements:
1 .You have to use ARRAYS
2 .You are required to use user-defined functions for the following tasks:
a . Getting the Mid-term and Final exam scores from the user
b . Calculating the Total score
c . Computing the maximum scores in Mid-term and Final exam.
3 .Assume it’s a maximum of 10 students and all of them have scores >=0 but <=100. You are therefore, required to make sure the user’s input falls in the valid range. If not, give him/her one more chance to enter the right score.
4 .If the user does not enter the right score, after two chances, set the score to ZERO and move to the next score.
5 .Make sure you scan the user’s input as described above for one student, before going to the next.
Hint: Use one array each to store Mid-term and Final scores.
Sample RUN:
Please enter the Mid-term and Final scores for student 1
20
98.5
Please enter the Mid-term and Final scores for student 2
-10.9 35
Sorry, the scores have to be in the range of 0 to 100. Please enter the Mid-Term score again:
90
Please enter the Mid-Term and Final scores for Student 3
90
120
Sorry, the scores have to be in the range of 0 to 100. Please enter the Final Exam score again: 99
Please enter the Mid-Term and Final scores for Student 7
101 -20
Sorry, the scores have to be in the range of 0 to 100. Please enter the scores again: 999
-10
//After giving one more chance, if the user’s input is invalid, set the Mid-term and Final exam scores to 0 and move to the next student.
Please enter the Mid-Term and Final scores for Student 10
90
100
Thank you!
Here is the total score for all the students in your class.
Student 1
67.1
Student 2
57
Student 3
95.4
Student 7
0.0
Student 10
96
Maximum score in Mid-term exam is 99 and was scored by Student 4
Maximum score in Final exam is 100 and was scored by Student 10
Student 1
67.1
Student 2
57
Student 3
95.4
Student 7
0.0
Student 10
96
Explanation / Answer
#include <iostream>
using namespace std;
int main() {
int midChance=2,finalChance=2, i, total = 2, midHere, finalHere;
int mid[total];
int final[total];
int totalScores[total];
for (i=0;i<total; i++){
cout << "Please enter the Mid-term and Final scores for student " << i+1 << ":" ;
cin >> midHere;
if(0 < midHere && midHere <= 100 && midChance>0){
mid[i] = midHere;
}else{
midChance = midChance - 1;
cout << "Please enter the mid term score of student " << i+1 << ":";
cin >> midHere;
if(0 < midHere && midHere <= 100 && midChance>0){
mid[i] = midHere;
}else{
midChance = midChance - 1;
cout << "Please enter the mid term score of student " << i+1 << ":";
cin >> midHere;
if(0 < midHere && midHere <= 100 && midChance>=0){
mid[i] = midHere;
}else{
mid[i] = 0;
}
}
}
cin >> finalHere;
if(0 < finalHere && finalHere <= 100 && finalChance>0){
final[i] = finalHere;
}else{
finalChance = finalChance - 1;
cout << "Please enter the mid term score of student " << i+1 << ":";
cin >> finalHere;
if(0 < finalHere && finalHere <= 100 && finalChance>0){
final[i] = finalHere;
}else{
finalChance = finalChance - 1;
cout << "Please enter the mid term score of student " << i+1 << ":";
cin >> finalHere;
if(0 < finalHere && finalHere <= 100 && finalChance>=0){
final[i] = finalHere;
}else{
final[i] = 0;
}
}
}
}
for(int j=0;j<total;j++){
totalScores[j] = 0.4*mid[j]+0.6*final[j];
}
midMax = mid[0];
finalMax = final[0];
int midInd = 0,finalInd = 0;
for(int j = 0; j<total-1; j++){
if(midMax < mid[j]){
midMax = mid[j];
midInd = j;
}
if(finalMax < final[j]){
finalMax = final[j];
finalInd = j;
}
}
cout <<"Total scores fo students in the class are: " << endl;
for(int k=0;k<total;k++){
cout << "Student " << k+1 << " " << total[k]<< endl;
}
cout << << endl;
cout << "Maximum score in Mid-term exam is " << midMax << " and was scored by Student"<< midMax << endl;
cout << "Maximum score in Final exam is " << finalMax << " and was scored by Student"<< finalMax << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.