-
-
Save KronicDeth/55c0c6f61bccfb6dbe4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Regina Imhoff | |
// Ecampus CS 161 | |
// Assignment #6 | |
// makes histogram of students' grades as entered by an instructor | |
#include <iostream> // includes and statements section | |
#include <string> // strings | |
#include <cstdlib> //c standard library | |
#include <stdio.h> | |
#include <string.h> | |
using std::cin; // user input | |
using std::cout; // machine output | |
using std::endl; // for line breaks | |
using std::string; //string | |
using std::getline; // getline | |
const int MINIMUM_GRADE = 0; | |
const int MAXIMUM_GRADE = 5; | |
const int GRADES = MAXIMUM_GRADE - MINIMUM_GRADE + 1; // Number of grades in the range between minimum and maximum, inclusive. | |
const int STOP = -1; | |
const string GRADE_RANGE = "(0-5)"; | |
// Allows teacher to input a single student's grade. | |
int inputStudentGrade(){ | |
int grade; | |
while(true) { | |
cout << "Enter a student's grade " << GRADE_RANGE << endl; | |
cout << "Enter " << STOP << " to stop entering grades" << endl; | |
cin >> grade; | |
if (grade == STOP || | |
(grade >= MINIMUM_GRADE && grade <= MAXIMUM_GRADE)) { | |
break; | |
} | |
cout << "That is not a valid grade " << GRADE_RANGE | |
<< " or stop signal (" << STOP << ")" << endl; | |
} | |
return grade; | |
} | |
// Allows teacher to input grades for all students in a class. | |
void inputClassGrades(int gradeCount[GRADES]){ | |
int grade; | |
while(true) { | |
grade = inputStudentGrade(); | |
if (grade == STOP) { | |
break; | |
} | |
gradeCount[grade]++; | |
} | |
} | |
void displayHistogram(int gradeCount[GRADES]) { | |
for (int i = 0; i < GRADES; i++) { | |
cout << gradeCount[i] << "grade(s) of " << i << endl; | |
} | |
} | |
int main(){ | |
int gradeCount[GRADES] = {0, 0, 0, 0, 0, 0}; | |
inputClassGrades(gradeCount); | |
displayHistogram(gradeCount); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment