명품 c++ 챕터 3장 1번부터 7번 chapter 3
본 자료는 3페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
해당 자료는 3페이지 까지만 미리보기를 제공합니다.
3페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

명품 c++ 챕터 3장 1번부터 7번 chapter 3에 대한 보고서 자료입니다.

본문내용

dl << \"--2에서 10까지의 랜덤 정수 10개--\" << endl;
for (int i = 0; i < 10; i++)
{
int n = r.nextInRange(2, 10);//2에서 4사이의 랜덤 정수
cout << n << \' \';
}
cout << endl;
}
<결과>
5번 문제
<코드>
#include
#include // RAND_MAX
#include
using namespace std;
class SelectableRandom
{
public:
SelectableRandom()
{
srand((unsigned)time(0));//다른 랜덤 정수를 발생시키는 seed 설정
}
int OddNumber(int x, int y) // 홀수
{
int a = x + (rand() % (y - x + 1));
if (a % 2 == 1)
return a;
return a + 1;
}
int EvenNumber(int x, int y) // 짝수
{
int a = x + (rand() % (y - x + 1));
if (a % 2 == 1)
return a - 1;
return a;
}
};
int main()
{
SelectableRandom r;
cout << \"-- 0에서 \" << RAND_MAX << \"까지의 짝수 랜덤 정수 10개--\" << endl;
for (int i = 0; i < 10; i++)
{
int n = r.EvenNumber(0, RAND_MAX);
cout << n << \' \';
}
cout << endl;
cout << \"-- 2에서 9까지의 랜덤 홀수 정수 10개 --\" << endl;
for (int i = 0; i < 10; i++)
{
int n = r.OddNumber(2, 9);
cout << n << \' \';
}
cout << endl;
}
<결과>
6번 문제
<코드>
#include
#include
class Integer {
int integer;
public:
Integer(int integer) { this->integer = integer; }
Integer(std::string integer) { this->integer = stoi(integer); }
void set(int integer) { this->integer = integer; }
int get() { return integer; }
bool isEven() {
if (integer % 2 == 0)
return true;
else
return false;
}
};
int main() {
Integer n(30);
std::cout << n.get() << \' \';
n.set(50);
std::cout << n.get() << \' \';
Integer m(\"300\");
std::cout << m.get() << \' \';
std::cout << m.isEven();
}
<결과>
7번 문제
<코드>
#include
using namespace std;
// Oval 클래스 선언부
class Oval {
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::Oval() {
width = height = 1;
}
Oval::Oval(int w, int h) {
width = w; height = h;
}
Oval::~Oval() {
cout << \"Oval 소멸 : \";
show();
}
void Oval::set(int w, int h) {
width = w; height = h;
}
void Oval::show() {
cout << \"width = \" << width << \", \" << \"height = \" << height << endl;
}
int Oval::getWidth() {
return width;
}
int Oval::getHeight() {
return height;
}
// main() 함수
int main() {
Oval a, b(3, 4);
a.set(10, 20);
a.show();
cout << b.getWidth() << \", \" << b.getHeight() << endl;
}
<결과>
  • 가격6,300
  • 페이지수9페이지
  • 등록일2016.03.13
  • 저작시기2015.8
  • 파일형식한글(hwp)
  • 자료번호#996973
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니