#include<iostream>
using std::cout;
using std::endl;
class Calculator{
private:
int _Add;
int _Div;
int _Min;
public:
int Add(int a, int b);
int Div(int a, int b);
int Min(int a, int b);
void Init();
void ShowOpCount();
};
int Calculator::Add(int a, int b){
_Add++;
return a+b;
}
int Calculator::Div(int a, int b){
_Div++;
return a/b;
}
int Calculator::Min(int a, int b){
_Min++;
return a-b;
}
void Calculator::Init()
{
_Add=0; _Div=0; _Min=0;
}
void Calculator::ShowOpCount()
{
cout<<"덧셈: "<<_Add<<" "<<"뺄셈: "<<_Min<<" "<<"곱셈: 나눗셈:"<<_Div<<endl;
}
int main(void)
{
Calculator cal;
cal.Init();
cout<<"3+5="<<cal.Add(3,5)<<endl;
cout<<"3/5="<<cal.Div(3,5)<<endl;
cout<<"12-4="<<cal.Min(12,4)<<endl;
cout<<"12/4="<<cal.Div(12,4)<<endl;
cal.ShowOpCount();
return 0;
}
using std::cout;
using std::endl;
class Calculator{
private:
int _Add;
int _Div;
int _Min;
public:
int Add(int a, int b);
int Div(int a, int b);
int Min(int a, int b);
void Init();
void ShowOpCount();
};
int Calculator::Add(int a, int b){
_Add++;
return a+b;
}
int Calculator::Div(int a, int b){
_Div++;
return a/b;
}
int Calculator::Min(int a, int b){
_Min++;
return a-b;
}
void Calculator::Init()
{
_Add=0; _Div=0; _Min=0;
}
void Calculator::ShowOpCount()
{
cout<<"덧셈: "<<_Add<<" "<<"뺄셈: "<<_Min<<" "<<"곱셈: 나눗셈:"<<_Div<<endl;
}
int main(void)
{
Calculator cal;
cal.Init();
cout<<"3+5="<<cal.Add(3,5)<<endl;
cout<<"3/5="<<cal.Div(3,5)<<endl;
cout<<"12-4="<<cal.Min(12,4)<<endl;
cout<<"12/4="<<cal.Div(12,4)<<endl;
cal.ShowOpCount();
return 0;
}
'프로그래밍 > [열혈강의] C++' 카테고리의 다른 글
[열혈강의 C++] 연습문제 3-1 문제2 (p.114) (0) | 2008.03.14 |
---|---|
연습문제 1-1 문제4 (1) | 2008.03.05 |
연습문제 1-1 문제3 (0) | 2008.03.05 |