
November 16th, 2012, 07:44 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 2
Time spent in forums: 19 m 12 sec
Reputation Power: 0
|
|
|
Memory & arrays - Gradebook Program
Hi,
Apologies if this is not the place for threads like this, but I need help with this program I'm designing.
It's a simple gradebook that I am just doing for fun/practice.
The issue is that after inputting grades, then viewing the gradebook, the grades seem all... wrong.
I would show a sample run, but this forum does not allow URLs in new user's posts.
Here is the code:
Code:
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
string fn[9];
string ln[9];
double grades[9][5];
int records = 0;
int width = 0;
int lengths[9];
int longest;
int gradecount = 0;
int findlongestname()
{
for (int i = 0; i < 9; i++)
{
lengths[i] = ln[i].length() + fn[i].length() + 6;
if (lengths[i] > lengths[i - 1])
{
longest = lengths[i];
}
}
if (longest < 14)
{
longest = 14;
}
return longest;
}
void viewgradebook()
{
width = findlongestname();
cout << left << setw(width) << "Student";
for (int i = 0; i < 5; i++)
{
cout << right << setw(5) << i + 1;
}
cout << setw(0) << endl;
for (int i = 0; i < 9; i++)
{
cout << i + 1 << ". ";
if (ln[i] == "")
{
cout << left << setw(width + 1) << "N/A";
}
else
{
cout << left << setw(ln[i].length()) << ln[i] << setw(2) << ", " << setw(width - ln[i].length() - 1) << fn[i];
}
for (int j = 0; j < 5; j++)
{
cout << setw(5) << grades[i][j];
}
cout << endl;
}
cout << endl;
}
void addstudent()
{
cout << "Enter the student's last name: ";
cin >> ln[records];
cout << "Enter the student's first name: ";
cin >> fn[records];
records++;
cout << endl;
}
void delstudent()
{
}
void newgrade()
{
int pointspossible;
int pointsearned[9];
cout << "How many total points were possible for this assignment? ";
cin >> pointspossible;
for (int i = 0; i < 9; i++)
{
if (ln[i] != "")
{
cout << "Enter " << fn[i] << " " << ln[i] << "'s points earned: ";
cin >> pointsearned[i];
}
grades[i][gradecount] = pointsearned[i] / pointspossible;
}
gradecount++;
}
int main()
{
bool running = true;
while (running)
{
int menuchoice;
cout << "What would you like to do? (Enter number of selection)";
cout << "\n1. View Gradebook\n2. Enter New Student\n3. Delete Student\n4. Enter New Grade\n\n";
cout << "Selection: ";
cin >> menuchoice;
cout << endl;
if (menuchoice == 1)
{
viewgradebook();
}
else if (menuchoice == 2)
{
addstudent();
}
else if (menuchoice == 3)
{
delstudent();
}
else if (menuchoice == 4)
{
newgrade();
}
}
}
Any help?
|