C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 16th, 2012, 07:44 PM
box box is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 box User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Memory & arrays - Gradebook Program


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap