#include<iostream>
using namespace std;
class Cal{
public:
int ad, su, mu, di;
public:
void init();
double add(double, double);
double sub(double, double);
double mul(double, double);
double div(double, double);
void showCount();
};
void Cal::init()
{
ad=0;
su=0;
mu=0;
di=0;
}
int main()
{
char op;
double a, b;
Cal c;
c.init();
while(1)
{
printf("Select operator\n[ + - * / Q ]\n==> ");
cin>>op;
switch(op){
case '+':
cout<<"Input two number : ";
cin>>a>>b;
cout<<a<<"+"<<b<<"="<<c.add(a, b)<<endl;
break;
case '-':
cout<<"Input two number : ";
cin>>a>>b;
cout<<a<<"-"<<b<<"="<<c.sub(a, b)<<endl;
break;
case '*':
cout<<"Input two number : ";
cin>>a>>b;
cout<<a<<"*"<<b<<"="<<c.mul(a, b)<<endl;
break;
case '/':
cout<<"Input two number : ";
cin>>a>>b;
cout<<a<<"/"<<b<<"="<<c.div(a, b)<<endl;
break;
case 'Q':
c.showCount();
exit(1);
break;
default:
cout<<"Please select correct operator!"<<endl;
}
}
return 0;
}
double Cal::add(double a, double b)
{
ad++;
return a+b;
}
double Cal::sub(double a, double b)
{
su++;
return a-b;
}
double Cal::mul(double a, double b)
{
mu++;
return a*b;
}
double Cal::div(double a, double b)
{
di++;
return a/b;
}
void Cal::showCount()
{
cout<<"+ : "<<ad<<endl;
cout<<"- : "<<su<<endl;
cout<<"* : "<<mu<<endl;
cout<<"/ : "<<di<<endl;
}
____________________________________________________________________________________________
멀고도 험난한 C++의 길...
'studio > programmazione' 카테고리의 다른 글
[python] range의 기능 (1) | 2010.10.27 |
---|---|
[python] 인터프리터로 프로그램 파일 실행하기 (1) | 2010.10.27 |
[C/C++] OPP의 개요 - Training (0) | 2010.06.23 |
[C/C++] OOP의 개요 - Core (2) | 2010.06.23 |
[C/C++] [project_upgrade] 내가 살아온 일수 구하기 (0) | 2010.04.14 |