MBA1991
پنج شنبه 21 فروردین 1393, 16:20 عصر
با سلام
من این برنامه ماشین حسابو رو توی c++اجرا می کنم ولی چند مورد ارور میده....:افسرده:خواهش می کنم کمکم کنین تا این مشکلو حل کنم
اگه میشه به ایمیلم بفرستین...ممنونmasoud_be70@yahoo.com
اینم برنامه...
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<math.h>
char ch = ' ' ;
int m = 0 ;
class calculator
{
double n1,n2;
char op;
int NewInt;
public:
calculator();
void add();
void sub();
void mul();
void div();
void cal();
void sq();
void ShowOp(char ch);
void ShowChar(char ch);
int isop(char ch);
};
//-------------------------------------------
int calculator::isop(char ch){
if (ch!='+'&& ch!='-'&& ch!='/'&& ch!='*' && ch!=13 && ch!='.')
return 0;
double n,m;
n=n1;m=n2;
if(NewInt==1 || ch==13)
{
if (op=='+') add();
if (op=='-') sub();
if (op=='*') mul();
if (op=='/') div();
if (op=='.') sq();
NewInt=0;
}
gotoxy(20,20);
cout<<n<<op<<m;
op='a';
n2=0;
return 1;
}
//------------------------------------------------------
calculator::calculator(){
n1=0;
n2=0;
op=' ';
NewInt=0;
}
//-------------------------------------------------------
void calculator::ShowChar(char ch)
{
int x=5;
for (int i=0;i<=9;i++)
{
gotoxy (x,10);
textcolor(15);
m=ch;
m=m-48;
if (m == i)
{
textcolor(10);
ch=' ' ;
}
cprintf("%d",i);
x+=2;
}
}
//------------------------------------------------------- op
void calculator::ShowOp(char ch)
{
int x=10;
for (int i=1;i<=6;i++)
{
gotoxy (x,12);
textcolor(15);
if (ch=='+') m=1;
if (ch=='-') m=2;
if (ch=='*') m=3;
if (ch=='/') m=4;
if (ch=='.') m=5;
if (ch==13) m=6;
if (i == m)
{
textcolor(10);
ch=' ' ;
}
if (i==1) cprintf("%c",'+');
if (i==2) cprintf("%c",'-');
if (i==3) cprintf("%c",'*');
if (i==4) cprintf("%c",'/');
if (i==5) cprintf("%c",'S');
if (i==6) cprintf("%c",'=');
x+=2;
}
}
//----------------------------------------------------------
void calculator::cal()
{
char ch=' ';
while(ch!=27){
ShowChar(ch);
ShowOp(ch);
ch = getch();
if (op==' '){
if (ch>='0'&&ch<='9')
n1=n1*10+ch-'0';
clrscr();
cout<<n1;}
else
if (ch>='0'&&ch<='9') {
n2=n2*10+ch-'0';
clrscr();
cout<<n2;
NewInt=1;
}
if (isop(ch)==1) op=ch;
}
}
//--------------------------------------------------------
void calculator::sq(){
n1=sqrt(n1);
clrscr();
cout<<n1;
}
void calculator::add(){
n1+=n2;
clrscr();
cout<<n1;
}
void calculator::sub(){
n1-=n2;
clrscr();
cout<<n1;
}
void calculator::mul(){
n1*=n2;
clrscr();
cout<<n1;
}
void calculator::div(){
n1/=n2;
clrscr();
cout<<n1;
}
void main() //----------------------------------------------main
{
ch= ' ' ;
calculator a;
a.ShowOp(ch);
a.ShowChar(ch);
a.cal();
getch();
}
من این برنامه ماشین حسابو رو توی c++اجرا می کنم ولی چند مورد ارور میده....:افسرده:خواهش می کنم کمکم کنین تا این مشکلو حل کنم
اگه میشه به ایمیلم بفرستین...ممنونmasoud_be70@yahoo.com
اینم برنامه...
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<math.h>
char ch = ' ' ;
int m = 0 ;
class calculator
{
double n1,n2;
char op;
int NewInt;
public:
calculator();
void add();
void sub();
void mul();
void div();
void cal();
void sq();
void ShowOp(char ch);
void ShowChar(char ch);
int isop(char ch);
};
//-------------------------------------------
int calculator::isop(char ch){
if (ch!='+'&& ch!='-'&& ch!='/'&& ch!='*' && ch!=13 && ch!='.')
return 0;
double n,m;
n=n1;m=n2;
if(NewInt==1 || ch==13)
{
if (op=='+') add();
if (op=='-') sub();
if (op=='*') mul();
if (op=='/') div();
if (op=='.') sq();
NewInt=0;
}
gotoxy(20,20);
cout<<n<<op<<m;
op='a';
n2=0;
return 1;
}
//------------------------------------------------------
calculator::calculator(){
n1=0;
n2=0;
op=' ';
NewInt=0;
}
//-------------------------------------------------------
void calculator::ShowChar(char ch)
{
int x=5;
for (int i=0;i<=9;i++)
{
gotoxy (x,10);
textcolor(15);
m=ch;
m=m-48;
if (m == i)
{
textcolor(10);
ch=' ' ;
}
cprintf("%d",i);
x+=2;
}
}
//------------------------------------------------------- op
void calculator::ShowOp(char ch)
{
int x=10;
for (int i=1;i<=6;i++)
{
gotoxy (x,12);
textcolor(15);
if (ch=='+') m=1;
if (ch=='-') m=2;
if (ch=='*') m=3;
if (ch=='/') m=4;
if (ch=='.') m=5;
if (ch==13) m=6;
if (i == m)
{
textcolor(10);
ch=' ' ;
}
if (i==1) cprintf("%c",'+');
if (i==2) cprintf("%c",'-');
if (i==3) cprintf("%c",'*');
if (i==4) cprintf("%c",'/');
if (i==5) cprintf("%c",'S');
if (i==6) cprintf("%c",'=');
x+=2;
}
}
//----------------------------------------------------------
void calculator::cal()
{
char ch=' ';
while(ch!=27){
ShowChar(ch);
ShowOp(ch);
ch = getch();
if (op==' '){
if (ch>='0'&&ch<='9')
n1=n1*10+ch-'0';
clrscr();
cout<<n1;}
else
if (ch>='0'&&ch<='9') {
n2=n2*10+ch-'0';
clrscr();
cout<<n2;
NewInt=1;
}
if (isop(ch)==1) op=ch;
}
}
//--------------------------------------------------------
void calculator::sq(){
n1=sqrt(n1);
clrscr();
cout<<n1;
}
void calculator::add(){
n1+=n2;
clrscr();
cout<<n1;
}
void calculator::sub(){
n1-=n2;
clrscr();
cout<<n1;
}
void calculator::mul(){
n1*=n2;
clrscr();
cout<<n1;
}
void calculator::div(){
n1/=n2;
clrscr();
cout<<n1;
}
void main() //----------------------------------------------main
{
ch= ' ' ;
calculator a;
a.ShowOp(ch);
a.ShowChar(ch);
a.cal();
getch();
}