C++ ESPRESSO(에스프레소) PART 02 - CHAPTER 09 PROGRAMMING(프로그래밍) 9개
본 자료는 9페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
해당 자료는 9페이지 까지만 미리보기를 제공합니다.
9페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

C++ ESPRESSO(에스프레소) PART 02 - CHAPTER 09 PROGRAMMING(프로그래밍) 9개에 대한 보고서 자료입니다.

목차

1. 은행의 계좌를 나타내는 BankAcct라는 부모 클래스를 작성한다.

2. 전자 제품을 나타내는 HomeAppliance 클래스를 작성한다.

3. 본문에 등장하는 Shape라는 클래스에 추가로 move(), getArea() 함수를 모두 가상 함수로 정의하라.

4. 3번 문제에서 새로운 도형 객체를 생성하여서 반환해주는 가상 함수 createShape()을 부모 클래스 Shape안에 정의 하고 자식 클래스에서 이 가상 함수를 구현하여 보자.

5. 도형에 관한 클래스를 약간 변경하여 보자.

6. 3차원 도형들을 칠하는데 필요한 페인트의 양을 계산하는 프로그램을 작성하여 보자.

7. 마트에서 판매되는 물건을 Product로 나타내자.

8. 책을 대여해주는 업체를 위한 Book이라는 클래스를 작성한다.

9. 간단한 게임 프로그램을 다형성을 이용하여서 작성하여 보자.

본문내용

am>
#include
using namespace std;
class Product
{
protected:
string name;
double price;
public:
Product(string n, double p)
{
name = n;
price = p;
}
void setPrice(double p)
{
price = p;
}
virtual double getPrice()
{
return price;
}
void print()
{
cout<<"상품명 : "< cout<<"가 격 : "< }
};
class DiscountProduct : public Product
{
private:
double discount;
public:
DiscountProduct(string n, double p, double d) : Product(n,p)
{
discount = d;
}
double getPrice()
{
return price-(price*(discount/100));
}
void print()
{
Product::print();
cout<<"할인율 : "< }
};
int main(void)
{
Product *p1 = new Product("toothbrush",3000);
Product *p2 = new DiscountProduct("toothbrush",3000,15);
cout<getPrice()< cout<getPrice()< return 0;
}
8. 책을 대여해주는 업체를 위한 Book이라는 클래스를 작성한다.
#include
#include
using namespace std;
class Book
{
protected:
int number;
string title;
string author;
public:
Book(int n, string t, string a)
{
number = n;
title = t;
author = a;
}
int getNumber()
{
return number;
}
void setNumber(int n)
{
number = n;
}
string getTitle()
{
return title;
}
void setTitle(string t)
{
title = t;
}
string getAuthor()
{
return author;
}
void setAuthor(string a)
{
author = a;
}
bool equals(Book b)
{
if( number == b.getNumber() )
return true;
else
return false;
}
virtual int getLateFees(int days) = 0;
void print()
{
cout<<"관리번호 : "< cout<<"제 목 : "< cout<<"저 자 : "< }
};
class Novel : public Book
{
public:
Novel(int n, string t, string a) : Book(n,t,a) {}
int getLateFees(int days)
{
return days * 300;
}
};
class Poet : public Book
{
public:
Poet(int n, string t, string a) : Book(n,t,a) {}
int getLateFees(int days)
{
return days * 200;
}
};
class ScienceFiction : public Book
{
public:
ScienceFiction(int n, string t, string a) : Book(n,t,a) {}
int getLateFees(int days)
{
return days * 600;
}
};
int main(void)
{
Book *b1 = new Novel(1111,"소설책","소설저자");
Book *b2 = new Poet(1111,"시집","시인");
Book *b3 = new ScienceFiction(1111,"공상과학책","공상저자");
b1->print();
cout<getLateFees(3)<<"원"< b2->print();
cout<getLateFees(4)<<"원"< b3->print();
cout<getLateFees(5)<<"원"< return 0;
}
9. 간단한 게임 프로그램을 다형성을 이용하여서 작성하여 보자.
#include
#include
using namespace std;
class GameCharacter
{
public:
virtual void draw(){}
};
class Hobit : public GameCharacter
{
public:
Hobit() : GameCharacter(){}
void draw()
{
cout<<"호빗을 그립니다."< }
};
class Titan : public GameCharacter
{
public:
Titan() : GameCharacter(){}
void draw()
{
cout<<"타이탄을 그립니다."< }
};
class Magician : public GameCharacter
{
public:
Magician() : GameCharacter(){}
void draw()
{
cout<<"주술사를 그립니다."< }
};
int main(void)
{
GameCharacter *ac[3];
ac[0] = new Hobit();
ac[1] = new Titan();
ac[2] = new Magician();
for(int i = 0; i < 3 ; i++){
cout<<"======================"< ac[i]->draw();
cout<<"======================"< }
return 0;
}
  • 가격3,000
  • 페이지수26페이지
  • 등록일2014.11.04
  • 저작시기2012.4
  • 파일형식한글(hwp)
  • 자료번호#945470
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니