Write the problem anaysis (IPO) in a table based on the c++ coding below.
1. Write the problem anaysis (IPO) in a table based on the c++ coding below.
(the image shows the question for the c++ coding)
#include <iostream>
#define STUDENTS 5
#define SCORES 4
using namespace std;
void getname(char[]);
void getscores(char[],double[]);
char calcgrade(double[],double &);
void print(char[],double[],char,double);
int main()
{
char name[STUDENTS][20],letter[STUDENTS],grade;
double s1[SCORES],s2[SCORES],s3[SCORES],s4[SCORES],s0[SCORES],avg;
getname(name[0]);
getscores(name[0],s0);
grade=calcgrade(s0,avg);
print(name[0],s0,grade,avg);
cin.ignore();
getname(name[1]);
getscores(name[1],s1);
grade=calcgrade(s1,avg);
print(name[1],s1,grade,avg);
cin.ignore();
getname(name[2]);
getscores(name[2],s2);
grade=calcgrade(s2,avg);
print(name[2],s2,grade,avg);
cin.ignore();
getname(name[3]);
getscores(name[3],s3);
grade=calcgrade(s3,avg);
print(name[3],s3,grade,avg);
cin.ignore();
getname(name[4]);
getscores(name[4],s4);
grade=calcgrade(s4,avg);
print(name[4],s4,grade,avg);
system("pause");
return 0;
}
void getname(char n[])
{
cout<<"Enter students name: ";
cin.getline(n,20);
}
void getscores(char n[],double g[])
{
cout<<"Enter tests scores for "<<n<<endl;
for(int i=0;i<SCORES;i++)
{
cout<<"Enters test score "<<i+1<<" : ";
cin>>g[i];
while(g[i]<0||g[i]>100)
{
cout<<"Invalid grade\n";
cout<<"Enter test score "<<i+1<<": ";
cin>>g[i];
}
}
}
char calcgrade(double g[],double & a)
{
int i;
double sum=0;
char grade;
for(i=0;i<SCORES;i++)
sum+=g[i];
a=sum/SCORES;
switch((int)a/10) // using integer arithmetic by dividing
{
case10: // score by 10 anything between 90 to 99 becomes 9
case9: // anything between 80 to 89 becomes 8 etc.
grade='A';
break;
case 8:
grade='B';
break;
case 7:
grade='C';
break;
case 6:
grade='D';
break;
default:
grade='F';
}
return grade;
}
void print(char n[],double g[],char l,double a)
{
cout<<"Student's name : "<<n<<endl;
cout<<"Test scores : ";
for(int i=0;i<SCORES;i++)
cout<<g[i]<<"\t";
cout<<"\nAverage score : "<<a<<endl;
cout<<"Student's grade : "<<l<<endl<<endl;
}


Step by step
Solved in 2 steps with 1 images









