본문내용
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;
}
<결과>
for (int i = 0; i < 10; i++)
{
int n = r.nextInRange(2, 10);//2에서 4사이의 랜덤 정수
cout << n << \' \';
}
cout << endl;
}
<결과>
5번 문제
<코드>
#include
#include
#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;
}
<결과>
키워드
추천자료
국토순례대행진 / 푸른 강물, 울창한 숲, 편리한 교통편의 팔당댐 유원지
C++ 고급C언어에 관한 이해
Operating System Concept(공룡책) 운영체제 연습문제 정답 1장 ~ 13장
[신화의 세계 공통] 아래 책들 중 한 권을 택해 읽고 아래 지시사항에 따라 과제를 작성하시...
[성인간호학] Chapter 11. 위장관계 간호 파트 정리 {위장관의 건강과 질병, 위장관장, 위장...
2015년 1학기 생명과환경 기말시험 핵심체크
2015년 1학기 숲과삶 기말시험 핵심체크
2015년 1학기 일본명작기행 기말시험 핵심체크
2015년 1학기 C프로그래밍 기말시험 핵심체크
2015년 1학기 Visual C++프로그래밍 기말시험 핵심체크
[원서번역] Generalist Social Work Practice (저자 - Elizabeth M. Timberlake...) 7장 Asse...
[사회복지개론] Chapter 8. 사회복지의 관점 (보수주의, 신자유주의, 제3의 길, 시민권 사회...
[사회복지개론] Chapter 07. 사회복지의 가치 (자유, 평등, 사회정의, 효율)
천체 물리학 서론 정리 (part7) - 활동은하, 퀘이사, 멀리 떨어진 활동은하의 흡수선, 우주론...
소개글