Write a Source Code For Bar Chart in C++

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.

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

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.

1 comments:

  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