클래스 Oval

전공 공부/C++ / / 2020. 12. 27. 20:46
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;
}

반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기