728x90
# Oval.h
#ifndef Oval_H
#define Oval_H
class Oval {
private:
int width, height;
public:
Oval();
Oval(int w, int h);
~Oval();
int getWidth();
int getHeight();
void set(int w, int h);
void show();
};
#endif
#pragma once
# Oval.cpp
#include<iostream>
using namespace std;
#include "Oval.h"
Oval::Oval() :width(1), height(1) {}
Oval::Oval(int w, int h) : width(w), height(h) {}
Oval::~Oval() {
cout << "Oval 소멸 : width = " << width << ", height = " << height << endl;
}
int Oval::getHeight() {
return height;
}
int Oval::getWidth() {
return width;
}
void Oval::show() {
cout << "width = " << width << ", height = " << height << endl;
}
void Oval::set(int w, int h) {
width = w;
height = h;
}
# main.cpp
#include<iostream>
using namespace std;
#include "Oval.h"
int main() {
Oval a, b(3, 4);
a.set(10, 20);
a.show();
cout << b.getWidth() << ", " << b.getHeight() << endl;
}
# 실행 결과
#include<iostream>
using namespace std;
class Oval {
private:
int width, height;
public:
Oval();
Oval(int w, int h);
~Oval();
int getWidth();
int getHeight();
void set(int w, int h);
void show();
};
Oval::Oval() :width(1), height(1) {}
Oval::Oval(int w, int h) : width(w), height(h) {}
Oval::~Oval() {
cout << "Oval 소멸 : width = " << width << ", height = " << height << endl;
}
int Oval::getWidth() {
return width;
}
int Oval::getHeight() {
return height;
}
void Oval::set(int w, int h) {
width = w;
height = h;
}
void Oval::show() {
cout << "width = " << width << ", height = " << height << endl;
}
int main() {
cout << "2018305065 전유정" << endl;
Oval a, b(3, 4);
a.set(10, 20);
a.show();
cout << b.getWidth() << ", " << b.getHeight() << endl;
}
반응형
'전공 공부 > C++' 카테고리의 다른 글
배열 동등 비교 (0) | 2020.12.28 |
---|---|
클래스 Power(프렌드 함수, 연산자 중복) (0) | 2020.12.28 |
클래스 Adder, Calculator 파일 분리 (0) | 2020.12.27 |
클래스 Circle 파일 분리(반지름 입력받아 면적 구하기) (0) | 2020.12.27 |
클래스 Rectangle(사각형 면적 구하기) (0) | 2020.12.27 |