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
|
#include <iostream>
#include <cmath>
#include <string>
#include <ctype.h>
#include <iomanip>
using namespace std;
const int MAXQ = 30;
void StoreData(int correct, string name, bool pass, int counter, string names[], int scores[], int studpassed[]);
void ReadAnswers(char answers[], int numQuestions);
void ProcessAnswers( const char key[], const char answers[], int &correct, bool &pass, const int NumQuest);
void ProcessOneSect( int& NumStu, const int NumQuest, const char key[], int Num_sect, int count, string names[], int scores[], int studpassed[], int &passed);
void UpdateTotal(int NumStu,int passed,int &totalStu, int &totalPassed);
void DisplayResult(int Num_stu, string names[], int scores[], int studpassed[]);
void header ();
void main ()
{
int Num_quest = 0, Num_sect = 0, kids = 0, passed = 0, counter = 0;
int totalPassed = 0, totalStu=0;
char answers [MAXQ], key [MAXQ];
string names[60];
int scores[60];
int studpassed[60];
cout << "enter number of questions: ";
cin >> Num_quest;
if (Num_quest > 30)
{
cout << "number entered is greater than maximum supported";
}
cout << endl << "enter answer key: ";
ReadAnswers(key, Num_quest);
cout << endl << "enter number of sections: ";
cin >> Num_sect;
for (int i = 1; i <= Num_sect; i++)
{
ProcessOneSect(kids,Num_quest,key, Num_sect, counter, names, scores, studpassed, passed);
UpdateTotal(kids, passed,totalStu, totalPassed,);
counter ++;
DisplayResult(kids, names, scores, studpassed);
cout<<endl<<passed<<"out of "<<kids<<" students of section "<<i<<" passed the exam"<<endl;
passed = 0;
}
cout << "there are " << Num_sect <<" sections, and "<< totalPassed << " out of ";
cout << totalStu << " passed the exam.";
}
void ReadAnswers(char answers[], int numQuestions)
{
for (int i = 0; i < numQuestions; i++)
cin >> answers [i];
}
void ProcessOneSect ( int& NumStu, const int NumQuest, const char key[], int Num_sect, int count, string names[],int scores[], int studpassed[], int &passed)
{
char answers [MAXQ];
string name;
int correct = 0, counter = 0;
bool pass = true;
cout << endl << "enter the number of students in the section: ";
cin >> NumStu;
for ( int i = 0; i < NumStu; i++)
{
ReadAnswers(answers, NumQuest);
cin >> name;
ProcessAnswers(key, answers, correct, pass, NumQuest);
StoreData(correct, name, pass, counter, names, scores, studpassed);
counter ++;
if (pass==true)
passed++;
}
header();
}
void ProcessAnswers( const char key[], const char answers[], int &correct, bool &pass, const int NumQuest)
{
correct = 0;
for (int i = 0; i < NumQuest; i++)
{
if ( toupper(key[i])== toupper(answers[i]))
correct++;
}
if ((correct/float(NumQuest)) <= .60)
pass = false;
}
void UpdateTotal (int NumStu,int passed,int &totalStu, int &totalPassed)
{
totalStu += NumStu;
totalPassed += passed;
}
void DisplayResult(int Num_stu, string names[], int scores[], int studpassed[])
{
for(int i=0; i<Num_stu; i++)
{
cout<<endl;
cout<<names[i]<<" "<<scores[i]<<" ";
if (studpassed[i] == 1)
cout<<"PASSED";
else
cout<<"FAILED";
}
}
void header()
{
cout << "Name" <<" " << "Correct Answers" <<" "<< "Pass/Fail";
cout << endl << endl;
cout << "----------------------------------------------------------------------";
}
void StoreData(int correct, string name, bool pass, int counter, string names[], int scores[], int studpassed[])
{
names[counter] = name;
scores[counter]=correct;
if (pass==true)
studpassed[counter]=1;
else
studpassed[counter]=0;
}
|