Hi there, I have been given this question to complete but I can't seem
to get my code working properly. I'm very new to C# so sorry if i come
across as stupid!

Here is the question...


Create a class that represents the grade distribution for a given course. In this class you should write methods to perform the following tasks:

Read the number of each of the letter grades A, B, C D and F

Set the number of letter grades A, B, C, D and F

Return the total number of grades

Return the percentage of each letter grade as a whole number between 0 and 100 inclusive

Draw a bar graph of the grade distribution
The graph should have five bars, one per grade. Each bar can be a horizontal row of asterisks, such that the number of asterisks in a row is proportionate to the percentage of grades in each category. For example, let on asterisk represent 2%, so 50 asterisks correspond to 100%. Mark the horizontal axis at 10% increments from 0 to 100% and label each line with a letter grade.
For example, if the grades are entered as 1A, 4B's, 6C's, 2D's and 1 F, then the output would look like:
0 10 20 30 40 50 60 70 80 90 100
IIIIIIIIIII
**************************************************
**** A
************** B
******************** C
****** D
E
**** F
In addition, you will have to use simple testing techniques in order to evaluate the program you have written. Your testing strategy for your code could include examples of the following:

Black box testing
Initialisation and termination of the program Interface
Performance errors

White box testing
Test loops
Test logical decisions
Test variable assignments
This should be written up in the form of a report (no more than two pages) which outlines the tests you have performed and their results.

It is my third day today I'm trying to get the program worked and there are still errors... :(
Hope you can help me

Many Thanks

Angela

I'm very new to C#

Do you think asking for homework help in a c++ forum will further your efforts in learning c pound?

  1. Accept input from user.
  2. Store input from user in a container of your choice (probably an int array)
  3. Using a loop, step through the array
  4. At each element of the array, use another loop to display the correct number of asterisks

You seem like an intelligent individual.. give this a try. We'd love to see your code.

Edited 7 Years Ago by Clinton Portis: n/a

#include <cstdlib>
#include <iostream>
#include <iomanip>
int a,Acent,b,Bcent,c,Ccent,d,Dcent,e,Ecent,f,Fcent,total,percent;


using namespace std;

int main(int argc, char *argv[])
{
cout<<"******************************************************"<<endl;
cout<<"This program will present the number of grades"<<endl;             //INTRODUCTION
cout<<"you input for grades A-F and turn this information"<<endl;         //TO
cout<<"in to a bar graph for ease."<<endl;                                //PROGRAM
cout<<"******************************************************"<<endl;
cout<<" "<<endl;

     cout<<"Please enter how many grade A's"<<endl; 
cin>>a;
     cout<<"Please enter how many grade B's"<<endl; 
cin>>b; 
     cout<<"Please enter how many grade C's"<<endl; 
cin>>c;
     cout<<"Please enter how many grade D's"<<endl;
cin>>d;
     cout<<"Please enter how many grade E's"<<endl;
cin>>e;
     cout<<"Please enter how many grade F's"<<endl;
cin>>f;
     total=a+b+c+d+e+f; 

percent=100/14; // 7;  
     cout<<" "<<endl;
     cout<<"      TOTAL GRADES ENTERED - "<<total<<endl; 

     Acent = percent*a/2;//3;  Bcent=percent*b/2; Ccent=percent*c/2; Dcent=percent*d/2;  Ecent=percent*e/2;  Fcent=percent*f/2;         

     cout<<endl;
     cout<<"      0   10   20   30   40   50   60   70   80   90   100"<<endl;
     cout<<"      |   |    |    |    |    |    |    |    |    |    |"<<endl;
     cout<<"      **************************************************"<<endl;

     int array[6] = {Acent,Bcent,Ccent,Dcent,Ecent,Fcent};                   //stores grades as percentage
     char array2[6] = {'A','B','C','D','E','F'};                            //stores letters a-f   
     // loop for each grade
     for(int loopcounter=0; loopcounter<6; loopcounter++)
     {                         

              cout<<"     ";
              // loop to output each asterisk                 
              for(int asteriskcounter=0; asteriskcounter<array[loopcounter]; asteriskcounter++)
              {

                cout << "*";
              }
              // print the grade after the asterisks
              cout << "   GRADE " << array[loopcounter] << endl;


     cout<<endl;
     }



    system("PAUSE");
    return EXIT_SUCCESS;
}

what is wrong? :(

Edited 3 Years Ago by Nick Evan: Fixed formatting

Are you kidding me?

cout<<"Please enter how many grade E's"<<endl;
cin>>e;

Use basic math to calculate a percentage for each letter grade:

Acent = a / total * 100;
Bcent = b / total * 100;
Ccent = c / total * 100;
Dcent = d / total * 100;
Fcent = f / total * 100;

This will give you the overall average grade:

average = (Acent+Bcent+Ccent+Dcent+Fcent) / total;

Edited 7 Years Ago by Clinton Portis: n/a

thank you :) but the program still does not show the graph correct...

You are probably displaying too many asterisks.

Each asterisk is supposed to represent 2% as per assignment requirement.

As of now, each asterisk represents 1%.

Therefore, you will have to reduce your asterisk output by 1/2:

for(int asteriskcounter=0; asteriskcounter<array[loopcounter]/2; asteriskcounter++)

Edited 7 Years Ago by Clinton Portis: **********

I did all you submited, but when I compile the graph still does not show the correct percentage - it shows all 6 as grade 0 :(

I am doing my best to imagine your current code...

I was wondering if you could help me out by posting what you have thus far.. if you don't mind.

this is what I have done so far:

#include <cstdlib>
#include <iostream>
#include <iomanip>
int a,Acent,b,Bcent,c,Ccent,d,Dcent,f,Fcent,total,percent,average;


using namespace std;

int main(int argc, char *argv[])
{
cout<<"******************************************************"<<endl;
cout<<"This program will present the number of grades"<<endl;             //INTRODUCTION
cout<<"you input for grades A-F and turn this information"<<endl;         //TO
cout<<"into a bar graph for ease."<<endl;                                //PROGRAM
cout<<"******************************************************"<<endl;
cout<<" "<<endl;

     cout<<"Please enter how many grade A's"<<endl; 
cin>>a;
     cout<<"Please enter how many grade B's"<<endl; 
cin>>b; 
     cout<<"Please enter how many grade C's"<<endl; 
cin>>c;
     cout<<"Please enter how many grade D's"<<endl;
cin>>d;
          cout<<"Please enter how many grade F's"<<endl;
cin>>f;
     total=a+b+c+d+f; 

percent=total/6; 
     cout<<" "<<endl;
     cout<<"      TOTAL GRADES ENTERED - "<<total<<endl; 

    Acent = a / total * 100; Bcent = b / total * 100; Ccent = c / total * 100; Dcent = d / total * 100;  Fcent = f / total * 100;
    average = (Acent+Bcent+Ccent+Dcent+Fcent) / total;

     cout<<endl;
     cout<<"      0   10   20   30   40   50   60   70   80   90   100"<<endl;
     cout<<"      |   |    |    |    |    |    |    |    |    |    |"<<endl;
     cout<<"      **************************************************"<<endl;

     int array[6] = {Acent,Bcent,Ccent,Dcent,Fcent};                   //stores grades as percentage
     char array2[6] = {'A','B','C','D','F'};                            //stores letters a-f   
     // loop for each grade
     for(int loopcounter=0; loopcounter<6; loopcounter++)
     {                         

              cout<<"     ";
              // loop to output each asterisk                 
              for(int asteriskcounter=0; asteriskcounter<array[loopcounter]/2; asteriskcounter++)
              {

                cout << "*";
              }
              // print the grade after the asterisks
              cout << " GRADE " << array[loopcounter] << endl;


     cout<<endl;
     }



    system("PAUSE");
    return EXIT_SUCCESS;
}

Edited 3 Years Ago by Nick Evan: Fixed formatting

I was all for integer division, and I believe it would have worked in that it would just truncate any decimal value to a whole integer.

But I guess this was not the case this time.

Change all your int's to doubles (or floats.. remember to set your precision) and I think you'll be happy with the results.

That is an excellent question, and I will break it down for you:

  1. Start at the top of your code
  2. Begin reading through your code
  3. Anytime you see 'int', replace with 'double'
  4. Continue the previous step until you have reached end of code

Compile, run and enjoy.

Edited 7 Years Ago by Clinton Portis: Take your name off your phone.

Thank you :) it look that the displayed percents are correct. just one thing is missing - it displays as GRADE not GRADE A, GRADE B etc. How can I change it? and please let me know why I had to change the int to double to get the program working ok?

what should I do to have the display look like this?:
0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
| | | | | | | | | | |
Grade A: |*******| 14.2857142857143%
Grade B: |**************| 28.5714285714286%
Grade C: |*******| 14.2857142857143%

I just made this up because I am currently cooking macaroni and cheese, and I think my noodles are being overcooked as we speak.

However, give this a try. If the output is not what you desire, feel free to tweak it as necessary before asking how to improve it:

for(int loopcounter=0; loopcounter<6; loopcounter++)
{
    switch(loopcounter)
    {
         case 0:  cout << "\nGrade A: |"; break;
         case 1:  cout << "\nGrade B: |"; break;
         case 3:  cout << "\nGrade C: |"; break;
         case 4:  cout << "\nGrade D: |"; break;
         case 5:  cout << "\nGrade F: |"; break;
    }    
    
    //loop to output each asterisk
    for(int asteriskcounter=0; asteriskcounter<array[loopcounter]/2; asteriskcounter++)
    {
        cout << '*';
    }  
    
    cout << "| " << array[loopcounter] << '%';
}

Edited 7 Years Ago by Clinton Portis: n/a

My bad.. i told you I was in a rush to save my noodles. Would have liked to have seen more effort on your part with simple debugging:

for(int loopcounter=0; loopcounter<5; loopcounter++)
{
    switch(loopcounter)
    {
         case 0:  cout << "Grade A: |"; break;
         case 1:  cout << "Grade B: |"; break;
         case 2:  cout << "Grade C: |"; break;
         case 3:  cout << "Grade D: |"; break;
         case 4:  cout << "Grade F: |"; break;
    }

    //loop to output each asterisk
    for(int asteriskcounter=0; asteriskcounter<array[loopcounter]/2; asteriskcounter++)
    {
        cout << '*';
    }

    cout << "| " << array[loopcounter] << '%'<< endl;
}

thank you, I will try it. one last thing - how should look black and white box testing?

White box testing (a.k.a. clear box testing, glass box testing or structural testing) uses an internal perspective of the system to design test cases based on internal structure. It requires programming skills to identify all paths through the software. The tester chooses test case inputs to exercise paths through the code and determines the appropriate outputs.
Definition from Wikipedia

Here you test the limits of your code design and data structures.

Black box testing takes an external perspective of the test object to derive test cases. These tests can be functional or non-functional, though usually functional. The test designer selects valid and invalid input and determines the correct output. There is no knowledge of the test object’s internal structure.
Definition from Wikipedia

Here you test the limits of user stupidity.

Edited 6 Years Ago by Clinton Portis: why does it always have to be a color issue

I am doing the same thing only in java and I would like help of how to change the coding to java code. I have tried doing the coding however I still have 12 error and not sure how to correct them. Please help

This question has already been answered. Start a new discussion instead.