검색결과 리스트
글
열혈강의 3장 연습문제 3-1 3-2
#include<iostream>
using namespace std;
class Calculator
{
private:
float sum;
int add_num;
int min_num;
int div_num;
int mul_num;
public:
void Init()
{
sum=0;
add_num=0;
min_num=0;
div_num=0;
mul_num=0;
}
float Add(float s1,float s2)
{
add_num++;
sum=s1+s2;
return sum;
}
float Min(float s1,float s2)
{
min_num++;
sum=s1-s2;
return sum;
}
float Div(float s1,float s2)
{
div_num++;
sum=s1/s2;
return sum;
}
float mul(float s1,float s2)
{
mul_num++;
sum=s1*s2;
return sum;
}
void ShowOpCount()
{
cout<<"덧셈 :"<<add_num<<" 뺼셈 : "<<min_num<<" 나눗셈 : "<<div_num<<" 곱셈 : "<<mul_num<<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;
}
#include<iostream>
#include<string>
using namespace std;
class Printer{
private:
char str[100];
public:
void SetString(char *string);
void ShowString();
};
void Printer::SetString(char *string)
{
strcpy(str,string);
}
void Printer::ShowString()
{
cout<<str<<endl;
}
int main()
{
Printer pnt;
pnt.SetString("Hello world!");
pnt.ShowString();
pnt.SetString("I love C++");
pnt.ShowString();
return 0;
return 0;
}
'♪C++ > 소스' 카테고리의 다른 글
c++ stack (0) | 2018.09.19 |
---|---|
c++ oop프로젝트 8장 (0) | 2018.09.18 |
성우 1장 OOP 단계별 프로젝트 (0) | 2017.10.09 |