Wednesday 13 August 2014

Write a Source Code For Bar Chart in C++

Structure of the Problem Requirements 

In this problem we will learn how to make a state bar chart in C++ Programs. state bar chart are mostly used calculation in Statics and Probability. 
Example of state bar chart is here
0-10 = 1 Student
.
.
.
91-100 = 2 Student

SOURCE CODE 

#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
const int totalSize = 11;
cout<<"\n\n\n *************** BAR CHAT PROGRAMME **************** \n\n\n";
int bar[ totalSize ] = { 0, 0, 0, 0, 1, 2, 2, 3, 4, 4, 5 };
cout << "Grade distribution:" << endl;
// for each element of array n, output a bar of the chart
for ( int i = 0; i < totalSize; i++ )
{
// output bar labels ("0-9:", ..., "90-99:", "100:" )
if ( i == 0 )
{
cout << " 0-9: ";
}
else 
if ( i == 10 )
{
cout << " 100: ";
}
else
{
cout << i * 10 << "-" << ( i * 10 ) + 9 << ": ";
}
// print bar of asterisks
for ( int star = 0; star < bar[ i ]; star++ )
cout << '*';
cout << endl; // start a new line of output
} // end outer for

return 0; // indicates successful termination
} // end main


OUTPUT OF THE PROGRAM

C++ Programming
Bar Chart Programmed


Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

1 comments: Post Yours! Read Comment Policy!▼
Important Note:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

  1. May ALLAH give u a lot of success on this beautifull project nd work....You have done a great work and its realy very helpful nd impressive....keep it up...:)

    ReplyDelete