درخواست راهنمایی برای پروژه ++c
[LEFT]با سلام عرض ادب .استاد ما یه برنامه ماشین حصاب با عملگر های (+.-./.*.%) خواسته که به عنوان پروژه تحویل .من برنامه رو نوشتم ولی گفت که باید یه محیط گرافیکی هم براش درست کنیم میخواستم بدونم چطور میتونم.این دو تا کد زیر رو ترکیب کنم طوری که ورودی و خروجی از قسمت نمایشگر شکل ماشین حصاب نمایش داده بشه.ممنون میشم اگه کمکم کنین[/LEFT]
void calculator()
{
cout<<"\t\t\t\t\t\t\t\t ________________________________________________________ "<<endl;
cout<<"\t\t\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t\t\t|________________________________________________________|"<<endl;
cout<<"\t\t\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| 7 8 9 [+] |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| [-] |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| 4 5 6 |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| [/] |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| 1 2 3 |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t\t\t|[*] |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| +/- 0 . |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| [%] |"<<endl;
cout<<"\t\t\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t\t\t|________________________________________________________|"<<endl;
}
و این
}
#include <iostream>
#include <cmath>
#include <cfloat>
using namespace std;
void calculator(double a, char op, double b) {
switch(op) {
case('+'):
if((a+b)<=DBL_MAX || (a+b)>=DBL_MIN) {
cout<<a<<" "<<op<<" "<<b<<" = "<<a+b;
break;
} else {
cout<<"Overflow occured! Try again.";
break;
}
case('-'):
if((a-b)<=DBL_MAX || (a-b)>=DBL_MIN) {
cout<<a<<" "<<op<<" "<<b<<" = "<<a-b;
break;
} else {
cout<<"Overflow occured! Try again.";
break;
}
case('*'):
if((a*b)<=DBL_MAX || (a*b)>=DBL_MIN) {
cout<<a<<" "<<op<<" "<<b<<" = "<<a*b;
break;
} else {
cout<<"Overflow occured! Try again.";
break;
}
case('/'):
if(b!=0)
cout<<a<<" "<<op<<" "<<b<<" = "<<a/b<<"";
else
cout<<"Error! Division by 0 is not idefined.";
break;
case('^'):
if(pow(a, b)<=DBL_MAX) {
if(a==0 && b==0) {
cout<<a<<" ^ "<<b<<"\nAnswer in C++ is 1, but it is not mathematicaly defined.";
break;
}
else {
cout<<a<<" "<<op<<" "<<b<<" = "<<pow(a, b);
break;
}
} else {
cout<<"Overflow occured! Try again.";
break;
}
case('%'):
cout<<a<<" "<<op<<" "<<b<<" = "<<(int)a%(int)b;
break;
default:
cout<<"You entered wrong operation, try again.";
break;
}
}
int main() {
double a, b;
char op;
menu();
cin>>a>>op>>b;
calculator(a, op, b);
return 0;