1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#include <iostream>
using namespace std;
void Read (int ID[], int answers[], int *,int *);
void calc( int ID[], int answers[], int *,char grade[], char *, int *);
void print(int ID[],int nofcorrectanswers,int highest, char grade[]);
void Read (int ID[5], int answers[10], int *Answers, int *idnum)
{
int IDi, int Ai, bool stop=false;
while(stop=false && IDi<5)
{
cout<<"Please enter your ID number, to stoo enter a negative value"<<endl;
cin>>*idnum;
if (*idnum<0)
stop=true;
else
{
do
{
cout<<"Enter your answers,note that true=1,false=0"<<endl;
cin>>*Answers;
}
while (*Answers);
while (*Answers==0 && *Answers==1);
}
ID[IDi]=*idnum;
answers[Ai]=*Answers;
}
}
void calc( int ID[5], int answers[10], int *nofcorrectanswers,char grade[5], char *Grade, int *highest)
{
int Ai, IDi,Gri;
int correct[10]={0,1,1,0,1,0,0,1,1,0};
for(IDi=0;IDi<5;IDi++)
{
for(Ai=0;Ai<10;Ai++)
{
if (answers[10]==correct[10])
{
*highest=10;
*nofcorrectanswers=10;
}
else
if(answers[10]==correct[10]-1)
{
*highest=9;
*nofcorrectanswers=9;
}
else
if(answers[10]==correct[10]-2)
{
*highest=8;
*nofcorrectanswers=8;
}
else
if(answers[10]==correct[10]-3)
{
*highest=7;
*nofcorrectanswers=7;
}
else
if(answers[10]==correct[10]-4)
{
*highest=6;
*nofcorrectanswers=6;
}
else
if(answers[10]==correct[10]-5)
{
*highest=5;
*nofcorrectanswers=5;
}
else
if(answers[10]==correct[10]-6)
{
*highest=4;
*nofcorrectanswers=4;
}
else
if(answers[10]==correct[10]-7)
{
*highest=3;
*nofcorrectanswers=3;
}
else {
*highest=0;
*nofcorrectanswers=0;
}
}
}
for(Gri=0;Gri<5;Gri++)
{
if(*nofcorrectanswers == *highest || *nofcorrectanswers == *highest-2)
*grade='A';
else
if(*nofcorrectanswers == *highest-3 || *nofcorrectanswers == *highest-5)
*grade='B';
else
if(*nofcorrectanswers == *highest-6 || *nofcorrectanswers == *highest-8)
*grade='C';
else
if(*nofcorrectanswers < *highest-8)
*grade='F';
}
grade[Gri]=*grade;
}
void print(int ID[5],int nofcorrectanswers,int highest, char grade[5])
{
int Ai, IDi,Gri, nofcorrectanswers;
for(IDi=0;IDi<5;IDi++)
{
cout<<"The ID is:"<<ID[IDi]<<endl;
for(Ai=0;Ai<10;Ai++)
{
cout<<"The number of correct answers is:"<<nofcorrectanswers<<endl;
}
cout<<"The best score is:"<<highest<<endl;
for(Gri=0;Gri<5;Gri++)
{
cout<<"The grade ="<<grade[Gri]<<endl;
}
}
}
void main()
{
int Answers, idnum, highest,nofcorrectanswers;
int ID[5],answers[10];
char grade[5], Grade;
Read (ID, answers, &Answers, &idnum);
calc(ID,answers, &nofcorrectanswers, grade, &Grade, &highest);
print(ID,nofcorrectanswers,highest,grade);
system("pause");
}
|