-----
<hahaha.h>------
~cpp
class Mid{
private:
int x,y,z,center;
public:
Mid();
~Mid();
void input();
void comparison();
void disp();
};
-----
<hahaha.cpp>----
~cpp
#include <iostream.h>
#include "hahaha.h"
Mid :: Mid (){
x=0;
y=0;
z=0;
}
Mid :: ~Mid(){
}
void Mid :: input(){
cout<<"비교할 세 수를 입력하세요"<<endl;
cin>>x>>y>>z;
}
void Mid :: comparison (){
if ((x>=y && x<=z) || (x<=y && x>=z)) {
center = x;
}
else if ((y>=x && y<=z) || (y<=x && y>=z)) {
center = y;
}
else {
center = z;
}
}
void Mid :: disp(){
if (x==-999||y==-999||z==-999){
cout<<"프로그램 종료"<<endl;
}
else {
cout<<"A="<<x<<" B="<<y<<" C="<<z<<endl;
cout<<"중위수는 "<<center<<"입니다."<<endl;
}
}
-----
<hahaha2.cpp>-----
~cpp
#include "hahaha.h"
void main(){
Mid center;
center.input();
center.comparison();
center.disp();
}