Add to Favorites    Make Home Page 49344 Online  
 Language Categories  
 Our Services  

Home » C Home » Beginners / Lab Assignments Home » Graphical Calculator Design

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Graphical Calculator Design
Author Manoj Mandal
Author Email mjsmandal [at] rediffmail.com
Description
Category C » Beginners / Lab Assignments
Hits 319231
Code Select and Copy the Code
:#include<graphics.h> #include<conio.h> #include<dos.h> #include<stdio.h> #include<string.h> #include<math.h> class Window; Window * const SCREEN=(Window *)0; enum buttonstatus{unpushed,pushed}; enum boolean{false,true}; class Window { protected: Window * ptr; int left,right,top,bot; int delta,deltacolor,centercolor; public:Window(){} Window(Window *ptro,int l,int t,int r,int b,int dc,int cc); void Display(); }; class Border:public Window { public: Border(Window *ptro,int l,int t,int r,int b,int dc=DARKGRAY,int cc=BLUE) :Window(ptro,l,t,r,b,dc,cc){} }; class Button:public Window { char text[20]; buttonstatus bs; public: Button(Window *ptro,int l,int t,int r,int b,int cc=BLACK,char *tx="") :Window(ptro,l,t,r,b,BLACK,cc) {strcpy(text,tx);bs=unpushed;} void Click(); void Display(); }; class Output:public Window { char text[80]; public: Output(Window *ptro,int l,int t,int r,int b,int dc=BLUE,int cc=WHITE) :Window(ptro,l,t,r,b,dc,cc){} void Text(char *ch); void Number(double d); }; Window::Window(Window* ptro,int l,int t,int r,int b,int dc,int cc) { ptr=ptro;left=l;right=r;top=t;bot=b;deltacolor=dc;centercolor=cc; delta=(-r-l-b-t)/150+3; if(ptr!=SCREEN) { left+=ptr->left; right+=ptr->right; top+=ptr->top; bot+=ptr->bot; } } void Window::Display() { setcolor(WHITE); int p[10]; p[0]=left;p[1]=top;p[2]=right;p[3]=top;p[4]=right;p[5]=bot; p[6]=left;p[7]=bot;p[8]=left;p[9]=top; setfillstyle(SOLID_FILL,deltacolor); fillpoly(5,p); rectangle(left+delta+1,top+delta,right-delta-1,bot-delta); setfillstyle(SOLID_FILL,centercolor); floodfill(left+(right-left)/2,top+delta+1,WHITE); } void Button::Click() { bs=pushed; Button::Display(); sound(500);delay(10);nosound(); delay(250); bs=unpushed; Button::Display(); sound(400);delay(10);nosound(); } void Button::Display() { Window::Display(); moveto(left+(right-left)/2+1,top+(bot-top)/2); settextjustify(CENTER_TEXT,CENTER_TEXT); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,USER_CHAR_SIZE); setusercharsize(5,8,2,3); setcolor(WHITE); outtext(text); moveto(left,top); lineto(left+delta,top+delta); moveto(right,top); lineto(right-delta,top+delta); moveto(left,bot); lineto(left+delta,bot-delta); moveto(right,bot); lineto(right-delta,bot-delta); setfillstyle(SOLID_FILL,LIGHTGRAY); if(bs==unpushed) { floodfill(left+(right-left)/2,top+1,WHITE); floodfill(left+1,top+(bot-top)/2,WHITE); } else { floodfill(left+(right-left)/2,bot-1,WHITE); floodfill(right-1,top+(bot-top)/2,WHITE); } } void Output::Text(char *ch) { Display(); moveto(right-delta,top+(bot-top)/2); settextjustify(RIGHT_TEXT,CENTER_TEXT); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,USER_CHAR_SIZE); setusercharsize(5,8,1,1); setcolor(BLACK); outtext(ch); } void Output::Number(double d) { char buffer[80]; sprintf(buffer,"%16.2lf",d); Output::Text(buffer); } void main() { int gd,gm; gd=EGA; gm=EGAHI; initgraph(&gd,&gm,"\tc\bgi"); Border br1(SCREEN,240,30,480,330); Output o1(&br1,20,20,-20,-240,BLUE,WHITE); Button b0(&br1,30,230,-175,-35,BLACK,"0"); Button b1(&br1,30,180,-175,-85,BLACK,"1"); Button b2(&br1,78,180,-127,-85,BLACK,"2"); Button b3(&br1,127,180,-78,-85,BLACK,"3"); Button b4(&br1,30,130,-175,-135,BLACK,"4"); Button b5(&br1,78,130,-127,-135,BLACK,"5"); Button b6(&br1,127,130,-78,-135,BLACK,"6"); Button b7(&br1,30,80,-175,-185,BLACK,"7"); Button b8(&br1,78,80,-127,-185,BLACK,"8"); Button b9(&br1,127,80,-78,-185,BLACK,"9"); Button bdiv(&br1,175,80,-30,-185,BLUE,"/"); Button bmul(&br1,175,130,-30,-135,BLUE,"*"); Button bsub(&br1,175,180,-30,-85,BLUE,"-"); Button bdot(&br1,78,230,-127,-35,BLACK,"."); Button bclr(&br1,127,230,-78,-35,RED,"clr"); Button badd(&br1,175,230,-30,-35,BLUE,"+="); br1.Display();o1.Display(); b7.Display();b8.Display();b9.Display(); b4.Display();b5.Display();b6.Display(); b1.Display();b2.Display();b3.Display(); b0.Display();bdot.Display();bclr.Display(); bsub.Display();bdiv.Display();badd.Display();bmul.Display(); o1.Number(0.0); const char ESC=27; char ds[80],tb[80],ch,oper; int num=0; boolean isfirst=true,chain=false; double num1,num2,ans; while((ch=getch())!=ESC) { if(ch>='0'&&ch<='9'||ch=='.') { switch(ch) { case '0':b0.Click();break; case '1':b1.Click();break; case '2':b2.Click();break; case '3':b3.Click();break; case '4':b4.Click();break; case '5':b5.Click();break; case '6':b6.Click();break; case '7':b7.Click();break; case '8':b8.Click();break; case '9':b9.Click();break; case '.':bdot.Click();break; } ds[num++]=ch;ds[num]='

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi դ ? ??
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2022 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=423


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review