Some notes before I describe my problem.
I am writing a gradebook program.
The setup for the program is this :
A teacher has 5 students who have taken 4 tests each. The teacher uses a basic grading scale to assign letter grades to the students based on their average of these 4 tests.
scale :
90-100 --- A
80-89 --- B
70-79 --- C
60-69 --- D
0-59 --- F
my conditions are as followed :
1. uses an array of string objects to hold student names
2. uses an array of characters that will hold the letter grade(the letter only, ex.A,B,C)
3. uses five arrays of four doubles to hold each student's set of test scores.
4. user should input each name and each test score.
5. calculate the average of each student's test scores and be given a letter grade based on the average.
End conditions.
My problem.
As you will see by the below code, I'm halfway through the program and I'm already stuck.
The part I am stuck on is the findLowest condition.
I understand the concept of looping through each student in the array, but it gets hazy when I also need to loop through their grades and pick out the lowest one. The way I have done this in the past was to use a lot of IF statements, but I was not using arrays then. Right now it is a way longer than expected loop. (the "student number and grade: " part in the findLowest function was me trying to experiment on what information was being sent)
I'm not asking for anyone to write the program for me.
What I'm looking for is a helpful bump in the right direction.
Also, I am very new to writing code so please pick out any areas of improvement that you see with my style or setup.
Any and all help will be greatly appreciated!!
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
|
#include <iostream>
#include <iomanip>
using namespace std;
const int NUM_TESTS = 4, STU_NUM = 5, STU_LENGTH = 20;
void getNames(char [][STU_LENGTH]);
//void calcAverage();
//void display();
void getScores(char [][STU_LENGTH], char [], double [][NUM_TESTS]);
void findLowest(double tests[][NUM_TESTS]);
int main()
{
char names[STU_NUM][STU_LENGTH];
double tests[STU_NUM][NUM_TESTS];
char gradeLetter[STU_NUM];
getNames(names);
getScores(names,gradeLetter,tests);
findLowest(tests);
system("PAUSE");
return 0;
}
// Function that will ask for and store names
void getNames(char names[][STU_LENGTH])
{
for(int i=0;i < STU_NUM;i++)
{
cout << "Please enter student " << i+1 << " name : ";
cin.getline(names[i],STU_LENGTH);
}
}
// Function that will ask for and store scores for each student
void getScores(char names[][STU_LENGTH], char gradeLetter[], double tests[][NUM_TESTS])
{
for(int i = 0; i < STU_NUM; i++)
{
for(int j = 0; j < NUM_TESTS; j++)
{
cout << "Please enter " << names[i] << " grades";
cout << (j+1) << ": ";
cin >> tests[i][j];
}
}
}
// Function that will find each student's lowest grade and drop it.
// Will pass to the calcAverage function.
void findLowest(double tests[][NUM_TESTS])
{
for(int i = 0;i < STU_NUM;i++)
{
cout << "This is student: " << i;
for(int j=0;i < NUM_TESTS;j++)
{
cout << "student number and grade: " << tests[i][j];
}
}
}
|