1번.
비행기를 나타내는 Plane라는 이름의 클래스를 설계하라. Plane 클래스는 식별번호, 모델 승객수를 멤버 변수로 가지고 있다.
-멤버 변수를 정의하라. 모든 멤버 변수는 전용 멤버로 하라
-모든 멤버 변수에 대한 접근자와 설정자 멤버 함수를 작성한다.
#include <iostream>
using namespace std;
class Plane
{
private:
string Model;
int CusNum;
int Number;
public:
Plane();
~Plane();
void setModel(string x);
void setCusNum(int x);
void setNumber(int x);
void setAll(string a, int b, int c);
void getModel();
void getCusNum();
void getNumber();
void print();
};
Plane::Plane()
:CusNum(0),Number(0),Model("")
{}
Plane::~Plane()
{}
void Plane::setModel(string x)
{
this->Model = x;
}
void Plane::setCusNum(int x)
{
this->CusNum = x;
}
void Plane::setNumber(int x)
{
this->Number = x;
}
void Plane::setAll(string a, int b, int c)
{
this->Model = a;
this->CusNum = b;
this->Number = c;
}
void Plane::getModel()
{
cout << this->Model << endl;
}
void Plane::getCusNum()
{
cout << this->CusNum << endl;
}
void Plane::getNumber()
{
cout << this->Number << endl;
}
void Plane::print()
{
cout<<"모델은 "<<this->Model << endl;
cout<<"고객수는 " << this->CusNum << endl;
cout<<"식별번호는" << this->Number << endl;
}
int main()
{
Plane plane1;
Plane plane2;
Plane plane3;
plane1.setAll("Intel", 977084, 200);
plane2.setAll("AMD", 977085, 150);
plane3.setAll("NDIVIA", 977086, 100);
plane1.print();
plane2.print();
plane3.print();
return 0;
}
===========================================
2번.
#include<iostream>
using namespace std;
class Box
{
private:
int hieght;
int wide;
int volume;
int size;
bool isOn;
public:
Box();
Box(int a, int b, int c);
~Box();
void empty();
int getVolume();
};
Box::Box()
:hieght(0), wide(0), volume(0), size(0),isOn(0)
{}
Box::Box(int a, int b, int c)
{
this->hieght = a;
this->wide = b;
this->volume = c;
this->size = 0;
this->isOn = false;
}
Box::~Box()
{}
void Box::empty()
{
if (this->isOn == false)
{
cout << "The box is empty" << endl;
}
else
{
cout << "The box is not empty" << endl;
}
}
int Box::getVolume()
{
this->size = this->hieght * this->wide * this->volume;
//cout << "박스의 사이즈는"<<this->size << endl;
return this->size;
}
int main()
{
Box box1(100, 100, 100);
Box box2(100, 50, 90);
Box box3(123, 47, 90);
if (box1.getVolume() < box2.getVolume())
{
if (box2.getVolume() < box3.getVolume())
{
cout << "The biggest one is box3" << endl;
}
else
{
cout << "The biggest one is box2" << endl;
}
}
else
{
if (box1.getVolume() < box3.getVolume())
{
cout << "The biggest one is box3" << endl;
}
else
{
cout << "The biggest one is box1" << endl;
}
}
return 0;
}
========================================
3번.
#include<iostream>
using namespace std;
class Movie
{
private:
string title;
string director;
int score;
public:
Movie();
Movie(string x, string b, float c);
~Movie();
void setTitle(string x);
void setDirector(string x);
void setScore(float x);
string getTitle();
string getDirector();
float getScore();
};
Movie::Movie()
:title(""),director(""),score(0)
{}
Movie::Movie(string x, string b, float c)
{
this->title = x;
this->director = b;
this->score = c;
}
Movie::~Movie()
{}
void Movie::setTitle(string x)
{
this->title = x;
}
void Movie::setDirector(string x)
{
this->director = x;
}
void Movie::setScore(float x)
{
this->score = x;
}
string Movie::getTitle()
{
return this->title;
}
string Movie::getDirector()
{
return this->director;
}
float Movie::getScore()
{
return this->score;
}
int main()
{
Movie movie1("도둑들", "봉준허", 4.5);
Movie movie2("범죄도시", "킴", 5.5);
Movie movie3("인랑", "장", 2.5);
if (movie1.getScore() < movie2.getScore())
{
if (movie2.getScore() < movie3.getScore())
{
cout << "Most hightest movie is movie3" << endl;
}
else
{
cout << "Most hightest movie is movie2" << endl;
}
}
else
{
if (movie1.getScore() < movie3.getScore())
{
cout << "Most hightest movie is movie3" << endl;
}
else
{
cout << "Most hightest movie is movie1" << endl;
}
}
}
'프로그래밍 언어 > c++' 카테고리의 다른 글
[C/C++] c++ espresso(에스프레소) chapter 08 상속 연습문제 (0) | 2022.06.11 |
---|---|
[C/C++]c++ ESPRESSO 5장 코딩 문제(연습문제) (0) | 2022.05.02 |
[C/C++] c언어로 원 그리는 프로그램/GetWindowDC(GetForegroundWindow()); (0) | 2022.04.29 |
[c/c++] 수입에 따른 세금 계산기 (0) | 2022.04.13 |
[c/c++] c언어로 행맨 (Hangman) 게임 만들기 (0) | 2022.04.13 |