Saturday, September 19, 2009

C++ program to make a pie chart

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<dos.h>
#define round(a)(int(a+0.5))
void main()
{
double total=0.0,a=0.0;
double x2,y2;
int i,n;
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
cout<<"PIE CHART"<<endl;
cout<<"Enter the no. of regions"<<endl;
cin>>n;
double values[10];
double per[10];
double angle[10]={0,0,0,0,0,0,0,0,0,0};
double b[10];
cout<<"Enter the values of the regions"<<endl;
circle(300,300,100);
line(300,300,400,300);
for(i=0;i<n;i++)
{
cin>>values[i];
total=total+values[i];
}
for(i=0;i<n;i++)
{
per[i]=((values[i]/total)*100);
a=((per[i]/100)*360);
if(i==0)
b[i]=a;
else
b[i]=b[i-1]+a;
angle[i]=(3.14*b[i])/180;
x2=(300+100*cos(angle[i]));
y2=(300-100*sin(angle[i]));
line(300,300,round(x2),round(y2));
setfillstyle(1,i+1);
if(x2>300&&y2< 300)
floodfill(x2+2,y2+2,15);
else
floodfill(x2-2,y2-2,15);
}
getch();
closegraph();
}

5 comments:

Rajesh kumar mehta said...

thanks for share ur knowledge.it works.

Ramya said...

at the time of compilation i'm getting the error as unable to include stdio.h. Plz clarify

paridhi bhagchandani said...

mr. angad please tel me what is pie chart.............?

Tripu Design said...

Very useful and informative blog. Thank you so much for these kinds of informative blogs.
We are also a graphic services in gurgaon and we provide the website design services,
web design services, web designing services, logo design services.
please visit our website to see more info about this.
Freelance Graphic Designing:
Freelance Catalogue Designing in delhi
Freelance Catalogue Designing in gurgaon
Freelance Brochure Designing
Freelance Label Designing
Freelance Banner Designer
Freelance Poster Designer
graphic design services in delhi
graphic design services in gurgaon
Freelance Catalogue Designing in delhi
Freelance Catalogue Designing in gurgaon
Freelance Brochure Designing
Freelance Label Designing
Freelance Banner Designer
Freelance Poster Designer
graphic design services in delhi
graphic design services in gurgaon
Freelance Catalogue Designing in delhi
Freelance Catalogue Designing in gurgaon
Freelance Brochure Designing
Freelance Label Designing
Freelance Banner Designer
Freelance Poster Designer
graphic design services in delhi
graphic design services in gurgaon
Freelance Catalogue Designing in delhi
Freelance Catalogue Designing in gurgaon
Freelance Brochure Designing
Freelance Label Designing
Freelance Banner Designer
Freelance Poster Designer
graphic design services in delhi
graphic design services in gurgaon

TNK Design Desk said...

Nice blog! i'm also working with a Digital marketing company in gurgaon
website designing in gurgaon
best website design services in gurgaon
best web design company in gurgaon
best website design in gurgaon
website design services in gurgaon
website design service in gurgaon
best website designing company in gurgaon
website designing services in gurgaon
web design company in gurgaon
best website designing company in india
top website designing company in india
best web design company in gurgaon
best web designing services in gurgaon
best web design services in gurgaon
website designing in gurgaon
website designing company in gurgaon
website design in gurgaon
graphic designing company in gurgaon
website company in gurgaon
website design company in gurgaon
web design services in gurgaon
best website design company in gurgaon
website company in gurgaon
Website design Company in gurgaon
best website designing services in gurgaon
best web design in gurgaon
website designing company in gurgaon
website development company in gurgaon
web development company in gurgaon
website design company
website designing services