/* ************************************************************************** * Program name : 019_Horizontal_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; 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 : \n"; Grade_A = Grade_B = Grade_C = Grade_D = Grade_E = Grade_U =0; for (Index=1; Index<=40; Index++) { cout << " Student no. " << setw(2) << Index << " the marks is (9999 means stop) :"; 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 : cout << "\n\n Total number of student : " << Index << "\n"; cout << "\n Grade Students"; cout << "\n --------------------------------------------"; cout << "\n A | "; for (Index=1; Index<= Grade_A; Index++) cout << "* "; cout << "\n B | "; for (Index=1; Index<= Grade_B; Index++) cout << "* "; cout << "\n C | "; for (Index=1; Index<= Grade_C; Index++) cout << "* "; cout << "\n D | "; for (Index=1; Index<= Grade_D; Index++) cout << "* "; cout << "\n E | "; for (Index=1; Index<= Grade_E; Index++) cout << "* "; cout << "\n U | "; for (Index=1; Index<= Grade_U; Index++) cout << "U "; cout << "\n --------------------------------------------"; cout << "\n\n"; // part 4 : try another number ? cout << "\aTry another number (Y/N) : "; cin >> 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 the marks is (9999 means stop) :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. 5 the marks is (9999 means stop) :456 Student no. 5 the marks is (9999 means stop) :45 (3) Number of valid enteries is the current value of Index less One. */