Google Answers Logo
View Question
 
Q: C++ Program ( No Answer,   4 Comments )
Question  
Subject: C++ Program
Category: Computers > Programming
Asked by: shock1-ga
List Price: $10.00
Posted: 04 Mar 2005 16:28 PST
Expires: 06 Mar 2005 14:52 PST
Question ID: 484883
It's about writing a program to tally the number of A's, B's, C's, D's
and F's based upon a list of scores entered by a user. After all the
scores are entered, the program summarizes the results and displays a
graph of the number of each grade.

Operation:

The program starts and prompts you to either enter a test score or end
the program by entering a -1. Like the following:

Number of A's: 0
Number of B's: 0
Number of C's: 0
Number of D's: 0
Number of F's: 0
Enter a score (%) or -1 to end: 90

As you enter each score, the application decides whether the score is
an A, B, C, D or F and adds one to the letter-grade tally. Like the
following:

Number of A's: 1
Number of B's: 0
Number of C's: 0
Number of D's: 0
Number of F's: 0
Enter a score (%) or -1 to end: 95

Each time you enter a score, the program updates the tally. Like the following:

Number of A's: 2
Number of B's: 0
Number of C's: 0
Number of D's: 0
Number of F's: 0
Enter a score (%) or -1 to end: -1

When you are done entering scores, the program displays a horizontal
bar graph of the tally for A's, B's, C's, D's and F's. Like the
following:

A's: **
B's:
C's:
D's:
F's:

Specifications:

1. Make a program to tally the number of A's, B's, C's, D's and F's
based upon a list of scores entered by a user.
2. Tally the number of A's, B's, C's, D's and F's using the following scale: 

Numerical Grade                             Letter Grade 

greater than or equal to 90                      A 

less than 90 but greater than or equal to 80     B 

less than 80 but greater than or equal to 70     C 

less than 70 but greater than or equal to 60     D 

less than 60                                     F 

3. After all the scores are entered, the program must display a
horizontal bar graph of the number tallied for each grade like that
shown in the Operation section.
4. The tally graph must display a single '*' for each unit tallied. 
5. When a user enters a -1, the program must display the final graph and exit. 
6. The output of your program must display prompts and a tally graph
like that shown in the Operation section above.
7. You may assume that a user will enter numbers only.
Answer  
There is no answer at this time.

Comments  
Subject: Re: C++ Program
From: reemul-ga on 05 Mar 2005 17:43 PST
 
First of all, I'd like some more details: what OS will be the one the
program runs on? What development environment did you have in mind?
Secondly, a C++ program making what you require is quite easy to
write, even a 'professional' one... but of course one cannot post it
here, and surely I wont do it, unless I get the 10 bucks (I am not a
google 'Researcher'). For any questions (I have been writing C++
programs as a job for more than 7 years), just drop me an email:

reemul@softhome.net
Subject: Here's the solution ...
From: dound-ga on 06 Mar 2005 04:26 PST
 
#include <iostream>
using namespace std;

enum gradeIndex   { GRADE_A, GRADE_B, GRADE_C, GRADE_D, GRADE_F };
enum gradingScale { GRADESCL_A=90, GRADESCL_B=80, GRADESCL_C=70, GRADESCL_D=60 };

//returns the corresponding letter grade index for given percentage
static int getGradeIndex( double percentage );

//returns the correseponding letter grade defined by gradeIndex
static char getGradeLetter( int index );

//prints the char n times
static void printChar(char c, int n, ostream &OUT);

int main()
{
    double testScore;                          //store inputted test scores
    int numLG[5]={0,0,0,0,0};                  //stores # of each
letter grade entered
    bool firstLoop=true;

    //loop until the user is done entering scores (enters -1)
    do
    {
        //find the letter grade entered and increment its counter
        if( !firstLoop)
        {
            int index = getGradeIndex( testScore );
            numLG[index] += 1;
        }
        else
            firstLoop = false;

        //output the tally
        for(int i=0; i<5; i++)
            cout << "Number of " << getGradeLetter(i) << "'s: " <<
numLG[i] << endl;

        //prompt the user for another test score
        cout << "Enter a score (%) or -1 to end: ";
        cin >> testScore; 
    } while( testScore != -1 );

    //print bar graph
    for(int i=0; i<5; i++)
    {
        cout << getGradeLetter(i) << "'s: ";
        printChar( '*', numLG[i], cout );
        cout << endl;
    }

    return 0;
}

static int getGradeIndex( double percentage ) {
    if( percentage >= GRADESCL_A )
        return GRADE_A;
    else if( percentage >= GRADESCL_B)
        return GRADE_B;
    else if( percentage >= GRADESCL_C)
        return GRADE_C;
    else if( percentage >= GRADESCL_D)
        return GRADE_D;
    else
        return GRADE_F;
}

static char getGradeLetter( int index )
{
    switch( index ) {
        case GRADE_A: return 'A';
        case GRADE_B: return 'B';
        case GRADE_C: return 'C';
        case GRADE_D: return 'D';
        default:      return 'F';
    }
}

static void printChar(char c, int n, ostream &OUT)
{
    while( n > 0 )
    {
        OUT << c;
        n -= 1;
    }
}
Subject: ... the solution, cont.
From: dound-ga on 06 Mar 2005 04:30 PST
 
In case you want the convenience of just being able to download the
cpp file (google inserted endlines to make the code fit its max width)
I have posted it at http://www.dound.com/temp/gradeGrapher.cpp -- you
may also view the screenshot of it working on the particular input you
provided above at http://www.dound.com/temp/screen1.jpg ... it meets
the specifications you provided.  Thanks for the question and please
let me know if you have any trouble.
Subject: Re: C++ Program
From: shock1-ga on 06 Mar 2005 10:28 PST
 
Thanks for the program, it works. Will you do me a big favor? Can you
rewrite it in C++ language like:

cout <<
cin >>

thanks

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy