The following algorithm is designed to determine whether a student grade is “Pass” or “Fail” for a particular subject. There are total of 4 scores (quiz -10%, assignment-10%, mid-term-20%, and final examination – 60%) being used to determine the grade of a student.
Algorithms
Step
1: Input a Student registration number in alphanumerical. (i.e.2015COM12)
Step
2: Input the student’s quiz score in integer.
Step
3: If the quiz score is greater than 10, display “Invalid Input!” and go to
Step 2
Step
4: Input the student’s assignment score in integer.
Step
5: If the assignment score is greater than 10, display “Invalid Input!” and go
to the Step 4.
Step
6: Input the student’s mid-term exam score in integer.
Step
7: If the mid-term score is greater than 20, display “Invalid Input!” and go to
the Step 6.
Step
8: Input the student’s final exam score in integer.
Step
9: If the final exam is greater than 60, output “Invalid Input!” and go to the
Step 8.
Step
10: Compute the “Grade”, if the total score (quiz + assignment + mid-term +
final) is greater than 55, display the grade as “Pass”. Otherwise “Fail”.
Step
11: Process to student grade, go to step 1.
Step
12: end of program.
Write
a C++ code for the above algorithm.
Answer
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int quiz,ass,mid,final,total,x;
string regnum;
do{
cout<<"Enter the student registration
no:";
cin>>regnum;
do {
cout<<"Enter
student Quiz score marks:";
cin>>quiz;
if (quiz>10)
cout<<"Invalid input"<<endl;
}while(quiz>10);
do {
cout<<"Enter
student Assignment score marks:";
cin>>ass;
if (ass>10)
cout<<"Invalid input"<<endl;
}while(ass>10);
do {
cout<<"Enter
student Mid tearm score:";
cin>>mid;
if (mid>20)
cout<<"Invalid input"<<endl;
}while(mid>20);
do {
cout<<"Enter
student final score:";
cin>>final;
if (final>60)
cout<<"Invalid input"<<endl;
}while(final>60);
total=quiz+ass+mid+final;
if(total>55)
cout<<"Grade is Pass";
else
cout<<"Grade is Fail";
cout<<endl<<"whould you like to enter
another student marks (Yes=1, No=0):";
cin>>x;
}while(x==1);
return 0;
}
0 Comments