/* ************************************************************************** * Program name : 036_Vertical_Bar_chart (Version 1.00) * * Author : Duck Wong * * Language : C / C++ * * Compiler : Boodshed Dec-C++ compiler Ver 3.95 * * Computer : PII350 * * O/S : Windows 98 * ************************************************************************** * Version 1.00 : 2000/06/10 - first version * ************************************************************************** * Description : (a) Input the test results * * (b) Plot the bar chart * * (c) Try again ? * ************************************************************************** */ #include #include #include int main() { // part 1 : declaration int Num_student, Marks, Index, Max; int Grade_A, Grade_B, Grade_C, Grade_D, Grade_E, Grade_U; char again; do { // part 2 : Read the marks of each student cout << "\n Please enter the test result of the students " << " (9999 means stop): \n\n"; Grade_A = Grade_B = Grade_C = Grade_D = Grade_E = Grade_U =0; for (Index=1; Index<=40; Index++) { cout << "\tstudent no. " << setw(2) << Index << " : "; cin >> Marks; if (Marks==9999) break; // Note (1) else if (Marks < 0 || Marks >100) Index -= 1; // Note (2) else if (Marks < 41) Grade_U +=1 ; else if (Marks < 51) Grade_E +=1 ; else if (Marks < 61) Grade_D +=1 ; else if (Marks < 71) Grade_C +=1 ; else if (Marks < 81) Grade_B +=1 ; else Grade_A +=1 ; }; Index -=1; // Note (3) // part 3 : Find the max number Max = Grade_A; if (Grade_B > Max) Max = Grade_B; if (Grade_C > Max) Max = Grade_C; if (Grade_D > Max) Max = Grade_D; if (Grade_E > Max) Max = Grade_E; if (Grade_U > Max) Max = Grade_U; // part 4 : Draw the bar chart cout << "\n\n\tTotal number of student : " << Index << "\n"; cout << "\n\t---------------------"; for (Index=Max; Index>=1; Index--) { cout << "\n\t " << setw(2) << Index << " : "; if ((Grade_A> again; cout << "\n"; } while (again=='Y' || again=='y'); cout << "\n" << endl; system("PAUSE"); return 0; } /* Notes (1) When the inputted marks is equals to 9999, that means no more record. Example : student no. 6 :9999 (2) When Marks belows zero or greater than 100, then the value of "Index" is decreased by 1 and then start next loop. Example : student no. 6 :956 student no. 6 :95 (3) Number of valid enteries is the current value of Index less One. (4) The statement if ((Grade_A