[C++]명품 C++ 프로그래밍 실습문제 10장 12번
[C++]명품 C++ programming 실습문제 10장 12번
명품 C++ 프로그래밍실습문제/연습문제 /C++
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
#include <cstdlib>
using namespace std;
class Word {
string english;
string korean;
public:
Word(string eng,string kor) {
this->english = eng;
this->korean = kor;
}
string getEng() { return english; }
string getKor() { return korean; }
};
int main() {
string example[4] = { "" };
bool sw = false;
srand((unsigned)time(0));
cout << "***** 영어 어휘 테스트를 시작합니다. *****" << endl;
vector<Word> v;
v.push_back(Word("human", "인간"));
v.push_back(Word("baby", "아기"));
v.push_back(Word("society", "사회"));
v.push_back(Word("photo", "사진"));
v.push_back(Word("painting", "그림"));
v.push_back(Word("love", "사랑"));
v.push_back(Word("emotion", "감정"));
v.push_back(Word("dall", "인형"));
v.push_back(Word("animal", "동물"));
v.push_back(Word("bear", "곰"));
v.push_back(Word("trade", "거래"));
int n;
while (true) {
int num;
cout << "어휘 삽입: 1, 어휘 테스트 : 2, 프로그램 종료:그외키 >>";
cin >> num;
if (num == 1) { // 어휘 삽입
cout << "영어 단어에 exit을 입력하면 입력 끝" << endl;
while (true) {
string eng, kor;
cout << "영어 >>";
cin >> eng;
if (eng == "exit") break;
cout << "한글 >>";
cin >> kor;
v.push_back(Word(eng, kor)); // 입력을 받아 새로 추가합니다.
}
}
else if (num == 2) {
while (true) {
int index = rand() % v.size();
cout << v[index].getEng() << "?" << endl;
int exIndex = rand() % 4;
example[exIndex] = v[index].getKor();
for (int i = 0; i < 4; ++i) {
if (i != exIndex) {
sw = true;
while (sw) { // 보기에 중복이 없게 하기
n = rand() % v.size();
if (example[0] != v[n].getKor() &&
example[1] != v[n].getKor() &&
example[2] != v[n].getKor() &&
example[3] != v[n].getKor())
{
example[i] = v[n].getKor();
sw = false;
}
}
}
}
for (int i = 0; i < 4; ++i)
cout << "(" << i + 1 << ") " << example[i] << ' ';
cout << ":>";
int answer;
cin >> answer;
if (answer >= 1 && answer <= 4) {
if (exIndex == answer - 1)
cout << "Excellent !!" << endl;
else
cout << "No. !!" << endl;
}
else
break;
}
}
else break;
}
for (int i = 0; i < 4; ++i) // 초기화를 안하면 중복 없게 할 때 문제가 생김
example[i] = "";
}
'C++' 카테고리의 다른 글
[C++]명품 C++ 프로그래밍 실습문제 10장 16번 (0) | 2023.01.25 |
---|---|
[C++]명품 C++ 프로그래밍 실습문제 10장 14번 (1) | 2023.01.25 |
[C++]명품 C++ 프로그래밍 실습문제 10장 10번 (0) | 2023.01.25 |
[C++]명품 C++ 프로그래밍 실습문제 10장 9번 (0) | 2023.01.25 |
[C++]명품 C++ 프로그래밍 실습문제 10장 8번 (0) | 2023.01.25 |