Forum PersianCoder

زمان کنونی: ۱/۳/۱۳۹۱, ۰۴:۵۰ صبح درود کاربر مهمان (ورودثبت نام)




ارسال پاسخ 
 
امتیاز موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
سورس ماشین حساب گرافیکی  
نویسنده پیام
soroush_tayyebi آفلاین
کاربر تازه وارد

ارسال ها: 4
تاریخ عضویت: آذر ۱۳۸۹
اعتبار: 0
سپاس ها 1
سپاس شده 4 بار در 3 ارسال
ارسال: #1
سورس ماشین حساب گرافیکی
سلام،اینم سورس یک ماشین حساب ساده و گرافیکی که با بورلند نوشته شده:
کد PHP:
#include <math.h>
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#define   ENTER 13
#define   BKSP  8
const int MAX=20;
const 
int ESC=27;
struct key{
int x;
int y;
char p;
};
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
struct key keys[]={
{
31,11,'('},{36,11,')'},{41,11,'^'},{46,11,16},
{
31,13,'7'},{36,13,'8'},{41,13,'9'},{46,13,'/'},
{
31,15,'4'},{36,15,'5'},{41,15,'6'},{46,15,'*'},
{
31,17,'1'},{36,17,'2'},{41,17,'3'},{46,17,'-'},
{
31,19,'0'},{36,19,'.'},{41,19,'='},{46,19,'+'},
};
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
int pr[]={17,0,16,12,13,14,8,9,10,4,5,6};
int getkey(void )
{
int key,low,high;
key=getch();
return (
key) ?  key getch()+256;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void press(int i)
{
window(keys[i].x,keys[i].y,keys[i].x+3,keys[i].y);
textbackground(WHITE);
textcolor(1);
clrscr();
cprintf(" %c",keys[i].p);
sleep(0.025);
window(keys[i].x,keys[i].y,keys[i].x+3,keys[i].y);
textbackground(BLACK);
textcolor(WHITE);
clrscr();
cprintf(" %c",keys[i].p);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void display(char *s)
{
int len=strlen(s);
window(31,8,49,9);
textbackground(WHITE);
textcolor(BLACK);
clrscr();
if (!
lenlen++;
gotoxy(19-len-1,2);
if (
strlen(s)==0cprintf("0.");
else if (!
strchr(s,'.'))   cprintf("%s.",s);
else 
cprintf("%s ",s);
}
/******************************************************************/
void ftoa(char *s,double x)
{
sprintf(s,"%f",x);
int i=strlen(s)-1;
while(
s[i]=='0's[i--]=0;
if (
s[i]=='.'s[i--]=0;
if (!
xstrcpy(s,"");
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void calculater()
{
int ch,op=0;
double x=0,y=0,k=0;
char str[50]={0};
char str2[50]={0};
display(str);
/******************************************************************/
do {
ch=getkey();
switch (
ch){
case 
'.':
case 
'0':
case 
'1':
case 
'2':
case 
'3':
case 
'4':
case 
'5':
case 
'6':
case 
'7':
case 
'8':
case 
'9':{
char st[]={ch,0};
press(pr[ch-'.']);
if(
strlen(str) < 14 ){
if (
ch!='.')
strcat(str,st);
else
if (!
strchr(str,'.'))
strcat(str,st);
display(str);
}
}
break;
case  
'+':
case  
'-':
(
ch=='+') ? press(19) : press(15);
if (!
k){
x=atof(str);
strcpy(str2,str);
}else
switch(
op){
case 
1:x+=atof(str);
break;
case 
2:x-=atof(str);
break;
case 
3:x*=atof(str);
break;
case 
4:x/=atof(str);
break;
        }
         
ftoa(str,x);
        
display(str);
    
op = (ch=='+') ? 2;
  
k=1;
       
strcpy(str,"");
     break;
      case  
'*':
      case  
'/':
       (
ch=='*') ? press(11) : press(7);
       if (!
k){
      
x=atof(str);
      
strcpy(str2,str);
        }else
   switch(
op){
     case 
1:x+=atof(str);
     break;
     case 
2:x-=atof(str);
     break;
     case 
3:x*=atof(str);
     break;
     case 
4:{double y;
      
y=atof(str);
      if (
yx/=atof(str);
     }
break;
         }
        
ftoa(str,x);
        
display(str);
        
op = (ch=='*') ? 4;
        
k=1;
        
strcpy(str,"");
       break;
/************************************************************/
case '(':{
double x;
press(0);
/*   x=atof(str);
   if(x>0) {
   x=sqrt(x);
   ftoa(str,x);
   display(str);
   }*/
}
break;
/************************************************************/
      
case ')': {
   
double x;
   
press(1);
       
// x=atof(str);
       // x*=-1;
       // ftoa(str,x);
       // display(str);
  
}
   break;
/************************************************************/
      
case '=':
      case 
ENTER:
  
press(18);
  if (!
opx=atof(str);
   else if ( 
)    y=atof(str);
        else 
y=atof(str2);
        switch(
op){
   case 
1x+=y;
         break;
   case 
2x-=y;
        break;
   case 
3x*=y;
         break;
   case 
4x/=y;
         break;
        }
        
ftoa(str,x);
        
display(str);
        
k=0;
       break;
/******************************************************************/
      
case BKSP:{
   
press(3);
   
int i=strlen(str);
   if (
i){
   
str[i-1]=0;
   
display(str);
         }
  }
        break;
/******************************************************************/
     
case '^':
       
press(2);
       
op=0;
       
x=0,y=0,k=0;
       
strcpy(str,"");
       
strcpy(str2,"");
       
display(str);
     continue;
    }
   }while(
ch!=ESC);
  }
/******************************************************************/
void menu4(void);
void meno1(void)
_setcursortype(_NOCURSOR);
  
textbackground(1);
  
clrscr();
  
textbackground(0);
  
window(7,6,19,10);
  
clrscr();
  
textbackground(19);
  
textcolor(15);
  
window(6,5,18,9);
  
clrscr();
  
gotoxy(1,2);cprintf(" Esc   :Exit  ");
  
gotoxy(1,3);cprintf(" Enter :Result ");
  
gotoxy(1,4);cprintf(" Bksp  :Undo   ");
  
window(31,8,52,21);
  
textbackground(0) ;
  
clrscr();
  
window(30,7,50,20);
  
textbackground(19);
  
clrscr();
  
window(31,8,49,9);
  
textbackground(7);
  
textcolor(YELLOW);
  
clrscr();
  
_setcursortype(_NOCURSOR);
  for (
int i=i<MAX ;i++){
  
window(keys[i].x,keys[i].y,keys[i].x+3,keys[i].y);
  
textbackground(0);
  
textcolor(15);
  
clrscr();
  
cprintf(" %c",keys[i].p);
  }
  }
  
void main()
  {
  
int i;
  
meno1();
  
calculater();
  
_setcursortype(_NORMALCURSOR);
  
clrscr();
  } 
(آخرین ویرایش در این ارسال ۱۹/۹/۱۳۸۹ ۰۵:۰۷ عصر توسط soroush_tayyebi.)
۱۹/۹/۱۳۸۹ ۰۵:۰۶ عصر
یافتن تمامی ارسال های این کاربر نقل قول این ارسال در یک پاسخ
 سپاس شده توسط Rasoul
Rasoul آفلاین
ادمین سایت
*******

ارسال ها: 108
تاریخ عضویت: ارد ۱۳۸۹
اعتبار: 3
سپاس ها 13
سپاس شده 80 بار در 11 ارسال
ارسال: #2
سورس ماشین حساب مهندسی و حرفه ای با c++
یک ماشین حساب مهندسی که فاکتوریل، جذر، توان، نسبت های مثلثاتی و ... را محاسبه میکند
این برنامه برای Dev c++ نوشته شده و در کامپایلر های قدیمی turbo و borland باید کمی تغییرش بدهید


کد PHP:
# include <iostream>
# include <cmath>

using namespace std;
void help();
//in tabe be onvane help baraye amalgar ha mibashad barname ast;

int fact (float a);
//in tabe factoryel ra hesab mikonad

void error();
//in tabe peyghame khata ra chap mikonad



int main(){
float result,zakhire ,a[50];
char b;
int flag=0,resultintaint;

for (
int i=1i<50i++){

    if (
i==1) {
        
help();
        
cout <<"Enter Number:";
        
cin>>result;
        
i+=1;}
    do{
    do{
    
system("cls");
    
help();
    
cout<<"Last result= "<<result<<endl;
    
cout<<"Enter Operator: ";
    
cin>>b;
    }while (
b!='f' && b!='l'&& b!='z'&& b!='b'&& b!='c'&& b!='+'&& b!='m'&& b!='n'&& b!='-'&& b!='*'&& b!='/'&& b!='o'&& b!='s'&& b!='r'&&b!='q'&& b!='p'&& b!='\\');
    
flag=3;

    if (
b=='\\'){
                if (
result!=floor(result)){
                
error();
                
flag=2;
                }
//end if
                
    
}//end if
    

    
}while(flag==2); //*/
    
switch (b){
    case 
'r':
        
i=0;
        
system("cls");
        continue;
    case 
'f':
            
resultfact(result);
            continue;
    case 
's':
            
result=sin(3.1416/(180/result));
            
resultint=result*100;
            
result=resultint*1./100;            
            continue;
    case 
'o':
            
result=cos(3.1416/(180/result));
            
resultint=result*100;
            
result=resultint*1./100;            
            continue;
    case 
'm':
            
resultint=result;
            if(
resultint%180!=90){
                
result=3.1416/(180/result);
                
result=tan(result);
                
resultint=result*100;
                
result=resultint*1./100;}//end if
            
else
                
error();
             continue;
    case 
'n':
            
resultint=result;
            if(
resultint%180!=0){
                
result=3.1416/(180/result);
                
result=1/(tan(result));
                
resultint=result*100;
                
result=resultint*1./100;}//end if
            
else
                
error();
             continue;
    case 
'z':
            
zakhire=result;            
            continue;
    case 
'b':
            
result=zakhire;            
            continue;
    case 
'l':
            if(
result>0)
                
result=log10(result);            
            else
                
error();
            continue;
    }
//end switch
        
if (b=='c') break;
//end for*/
        
    
system("cls");
    
help();
    
cout<<"Last result= "<<result<<" "<<b<<endl
    
cout <<"Enter Number:";
    
cin>>a[i];
    
    switch(
b){
    case 
'+':
        
result+=a[i] ;break;
    case 
'-':
        
result -= a[i]; break;
    case 
'*':
        
result *= a[i]; break;
    case 
'/':
        if (
a[i]==0){ 
                
error();
                break;
            }
        else{
            
result/=a[i]; break;}
    case 
'p':
        
resultpow(result,a[i]); break;
    case 
'q':
        
result=pow(result1/a[i]); break;
    case 
'\\':
        
resultint=result;
        
aint=a[i];
            if (
a[i]==floor(a[i])){
                
result resultint%aint; break;
                }
//end if
            
else{
                
error();
                break;
                }
//end else

    
}//end switch
    
}//end for

return 0;
}
//end main


void help(){
cout<<"      In the name of God\n\n";
    
cout<<"//Created By Sepehr Mohammad\\\\"<<<<endl;
    
cout<<"//  Http://cplusprogram.tk  \\\\"<<endl<<endl;
cout<<"HELP:"<<endl;
cout<<"Enter in Operator"<<endl;
cout<<"Close:[c]"<<endl;
cout<<"Reset:[r]"<<endl;
cout<<"Save in Memory:[z]"<<endl;
cout<<"Load from Memory:[b]"<<endl;
cout<<"Plus:[+]    ;example(2+3=5)"<<endl;
cout<<"Subtract:[-]    ;example(5-3=2)"<<endl;
cout<<"Multiply:[*]    ;example(2*3=6)"<<endl;
cout<<"Division:[/]    ;example(5/2=2.5 $ 5/0=Undefined)"<<endl;
cout<<"Reminder:[\\]    ;example(5\\2=1 $ 5.3\\2.1=Undefined)"<<endl;
cout<<"power:[p]    ;example(2 p 3=8)"<<endl;
cout<<"sqrt:[q]    ;example(8 s 3=2)"<<endl;
cout<<"factorial:[f]    ;example(4f=24)"<<endl;
cout<<"Sin:[s]         ;example(30s=0.5)"<<endl;
cout<<"Cos:[o]         ;example(60o=0.5)"<<endl;
cout<<"tan:[m]         ;example(45m=1)"<<endl;
cout<<"Cot:[n]         ;example(45n=1)"<<endl;
cout<<"log:[l]         ;example(10l=1)"<<endl;
cout<<endl;
}
//end help

int fact (float a){
int b=aresult=1;
    for (
int i=2i<=bi++){
    
result*=i;
        }
//end for
return result;
}
//end fact

void error(){
    
system("cls");
    
cerr<<endl<<"!!Undefined!!"<<endl<<endl;
    
system("pause");
}
//end error


//end 
۱۹/۹/۱۳۸۹ ۰۵:۵۹ عصر
یافتن تمامی ارسال های این کاربر نقل قول این ارسال در یک پاسخ
 سپاس شده توسط soroush_tayyebi
soroush_tayyebi آفلاین
کاربر تازه وارد

ارسال ها: 4
تاریخ عضویت: آذر ۱۳۸۹
اعتبار: 0
سپاس ها 1
سپاس شده 4 بار در 3 ارسال
ارسال: #3
RE: سورس ماشین حساب گرافیکی
سلام،ممنون اما گرافیکی نیستشا:دی
۱۹/۹/۱۳۸۹ ۰۹:۱۰ عصر
یافتن تمامی ارسال های این کاربر نقل قول این ارسال در یک پاسخ
ارسال پاسخ 


پرش به انجمن:

Powered by MyBB | Copyright © 2010 MyBB Group
Element Blue by MyBB Mod