/ Published in: C++
Expand |
Embed | Plain Text
#include <cstdlib> #include <iostream> #include "firstQuiz.h" using namespace std; static int studentNo = 1; static int zeroInput = 0; firstQuiz::firstQuiz(int i) { errorC = i; } void firstQuiz::errorHandling() { //static int errorC; //we can use this instead of interface solution //if there is an error, show the error message if (errorC == 1) cout << "error: try again: "; //no problem else cout << "enter the negative number tolerance quantity: "; cin >> zeroInput; if (zeroInput < 0) { errorC = 1; //error logger errorHandling(); //recursion } } //if we don't want to write cout's again and again, we creat a function void firstQuiz::pointInput() { cout << "please enter the grade for student " << studentNo++ << " : "; cin >> point; } //"everything is something happen" (sinyor terim) void firstQuiz::compute() { int zeroCount = 0; char closer; counterA = 0; avarageA = 0; maximumA = 0; minimumA = 100; counterB = 0; avarageB = 0; maximumB = 0; minimumB = 100; //classic do-while structure do{ pointInput(); //when entered grade is negative and error handler is activated while(point<0 && zeroCount != zeroInput) { zeroCount++; cout << "negative! want to quit? (y / n) : "; cin >> closer; if (closer == 'y' || closer == 'Y') { break; } if( closer == 'n' || closer == 'N') { pointInput(); } } //for above 50 if(point>50) { counterA++; avarageA+=point; if(point > maximumA) maximumA=point; if(point < minimumA) minimumA=point; } //for belove 50 if(point<=50) { //if it is negative, easily ignore that! if(point<0) break; counterB++; avarageB+=point; if(point > maximumB) maximumB=point; if(point < minimumB) minimumB=point; } }while(point>=0); } //compute avarages seperately void firstQuiz::computeAvarage() { avarageA = avarageA / counterA; //for above 50 avarageB = avarageB / counterB; //for belove 50 } //result outputs void firstQuiz::printResult() { //+50 cout << endl << "maximum (+ 50) is " << maximumA << endl; cout << "minimum (+ 50) is " << minimumA << endl; cout << "avarage (+ 50) is " << avarageA << endl << endl; //-50 cout << "maximum (- 50) is " << maximumB << endl; cout << "minimum (- 50) is " << minimumB << endl; cout << "avarage (- 50) is " << avarageB << endl << endl; }
Comments
Subscribe to comments
You need to login to post a comment.

It was my CS201 (at Bilkent University, Computer Science) Quiz question.