3 Replies - 3669 Views - Last Post: 03 October 2006 - 03:41 AM Rate Topic: -----

#1 Quiksilver  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 45
  • Joined: 12-March 05

C++ Simple Graph Making…help

Posted 12 March 2005 - 07:27 PM

Hey,
Im fairly new to C++. But anyway, I made a program that will tell a school teacher how many letter marks were inputed using Case Statements. And now im trying to show a simple graph at the end after it gives the total of each letter.
Here is my code so far (it does everything I want it to except show the graph):

//*************************************************
// Program Filename : AndrewGrade
// Purpose : Adds the number of letter grades inputed.
// Date : March 11
//*************************************************

//Preprocessor Directives
#include <iostream.h>
#include <stdlib.h>

//Name Constant Definitions

int main()
{
//Variable Declarations:
int nTotalA=0, nTotalB=0, nTotalC=0, nTotalD=0, nTotalF=0, nTotalt=0;
float fGradepointav;
char cGrade;

//Function Body
cout<<"\nEnter your grades(after every grade press enter). Then press 'x' once you are finished: "<<endl;
do{
cin>>cGrade;
if(cGrade!='x' && cGrade!='X'){
cout<<"Next: ";
}
switch(cGrade){
case 'A':
case 'a':
nTotalA++;
break;

case 'B':
case 'b':
nTotalB++;
break;

case 'C':
case 'c':
nTotalC++;
break;

case 'D':
case 'd':
nTotalD++;
break;

case 'F':
case 'f':
nTotalF++;
break;
}

}while(cGrade!='x' && cGrade!='X');
cout<<endl;
cout<<"Number of A grades : "<<nTotalA<<endl;
cout<<"Number of B grades : "<<nTotalB<<endl;
cout<<"Number of C grades : "<<nTotalC<<endl;
cout<<"Number of D grades : "<<nTotalD<<endl;
cout<<"Number of F grades : "<<nTotalF<<endl;
nTotalt=nTotalA+nTotalB+nTotalC+nTotalD+nTotalF;
cout<<"Total number of grades : "<<nTotalt<<endl;
fGradepointav=(4*nTotalA+3*nTotalB+2*nTotalC+1*nTo talD)/nTotalt;
cout<<"The class grade point average is : "<<fGradepointav<<endl<<endl;

system("PAUSE");
return 0;
}



Now, heres the bar chart (graph) that I want it to output at the end:

Quote

A | ****
B | ********
C | ***********
D | ****
F | ***


So, does anyone know how I would go about making this bar chart? I have no idea how to, and ive had little luck searching the web for the code.

Thanx for your help

This post has been edited by Dark_Nexus: 03 October 2006 - 09:49 AM


Is This A Good Question/Topic? 0
  • +

Replies To: C++ Simple Graph Making…help

#2 Videege  Icon User is offline

  • rvant.toujours
  • member icon

Reputation: 6
  • View blog
  • Posts: 1,413
  • Joined: 25-March 03

Re: C++ Simple Graph Making…help

Posted 12 March 2005 - 09:37 PM

Use a for loop to output, it would be something like this:

void outputGraph()
{
int i = 0; //counter variable
//#of A grades
cout << "A: ";
for (i; i < nTotalA; i++)
{
cout << '*';
}
cout << "\n";
//#of B grades
cout << "B: ";
//and so on...
}


If you do it like this, make sure you reset i in each for loop.
Was This Post Helpful? 0
  • +
  • -

#3 Quiksilver  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 45
  • Joined: 12-March 05

Re: C++ Simple Graph Making…help

Posted 12 March 2005 - 09:41 PM

great! thanx alot man
Was This Post Helpful? 0
  • +
  • -

#4 keesh1vs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-October 06

Re: C++ Simple Graph Making…help

Posted 03 October 2006 - 03:41 AM

I also need to make a bar chart for my program however it needs to be a vertical bar chart, and I have to scale the chart so that the largest category is 20 lines tall and the others are in correct proportion. I understand how to do the horizontal bar chart, but i have no clue how to even start this. Im thinking it is going to take some kind of divivsion by 20 to see how many *'s will go in each column but any help would be greatly appreciated!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1