3.21 Lab 4 Assignment 18 is continuation of assignment 1A where you are required
ID: 3756128 • Letter: 3
Question
3.21 Lab 4 Assignment 18 is continuation of assignment 1A where you are required to use if statements to improve the program Verify the entered data for soores are all between 0 and 100 if any of them is not valid (out of range or character is entered) print an error message and stop the program Once the average is calculated then assign a letter grade to the student based on the following table Average Grade 0-100A 80-89 70-79 : 60-69 D 0-59 F Develop a C++program based on the requirements stated on the assignments 1A and 18 Use the sample output posted below for submission on zyBooksExplanation / Answer
#include<iostream.h>
#include<ctype.h>
#include<stdlib.h>
// About the modification, just add 3 functions
//add a new function to check whether it is a digit
void checkdigit(int m) // m is the mark
{ if(isdigit(m))
{ return;
}
else
{ cout<<"/nTest score is not valid : please enter valid digit ";
exit(); //exit program
}
}
//add a new function to check whether it is in the range
void range(int m)
{ if((m>0)&&(m<100))
{ return;
}
else
{ cout<<"/nTest score is not valid : please enter valid number between 0 and 100 ";
exit(); // exit program
}
}
void grade(float tot) // calculating Grade from average.tot=avg
{ if((tot<=100)&&(tot>=90))
cout<<"A";
else if((tot<=89)&&(tot>=80))
cout<<"B";
else if((tot<=79)&&(tot>=70))
cout<<"C";
else if((tot<=69)&&(tot>=60))
cout<<"D";
else if((tot<=59)&&(tot>0))
cout<<"B";
}
void main()
{ char name[40];
int mark1,mark2,mark3,quiz,prog;
float total,avg;
cout<<"Enter the student name :";
cin>>name;
cout<<"/nEnter the first mark : ";
cin>>mark1;
checkdigit(mark1); //checking number or not
range(mark1); //checking range
cout<<"/nEnter the second mark : ";
cin>>mark2;
checkdigit(mark2);
range(mark2);
cout<<"/nEnter the third mark : ";
cin>>mark3;
checkdigit(mark3);
range(mark3);
cout<<"/nEnter the quiz score : ";
cin>>quiz;
checkdigit(quiz,);
range(quiz);
cout<<"/nEnter the programming total : ";
cin>>prog;
checkdigit(prog);
range(prog);
total = mark1 + mark2+ mark3 + prog + quiz; //calculating total
cout<<"/nTotal ="<<total;
avg = total/6; // calculating average
cout<<"/nAverage ="<<avg;
cout<<"/nGrade = ";
grade(avg);
cout<<" ";
}
// it doesnot contain the whole program for the exact output, as i cannot see the the full question.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.