USE C++ (20 points) You can determine the day of the month when your friend was
ID: 2268304 • Letter: U
Question
USE C++
(20 points) You can determine the day of the month when your friend was born by asking five questions. Each question asks whether the day is in one of the following five sets of numbers.
Set 1 Set 2 Set 3 Set 4
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
4
5
6
7
12
13
14
15
20
21
22
23
28
29
30
31
8
9
10
11
12
13
14
15
24
25
26
27
28
29
30
31
2
3
6
7
10
11
14
15
18
19
22
23
26
27
30
31
Set 5
The birthday is the sum of the first numbers in the sets where the day appear. For example, if the birthday is 19, it appears in Set1, Set2, and Set 5. The first numbers in these three sets are 1, 2, and 16. Their sum is 19. Write a program that asks the user to answer whether the day is in Set1, in Set2, in Set3, in Set4, and in Set 5, then displays the birthday.
Sample Run:
Is your birthday in Set1?
1 357
9 11 13 15
17 19 21 23
25 27 29 31
Enter N/n for No and Y/y for Yes: n
Is your birthday in Set2?
2367
10 11 14 15
18 19 22 23
26 27 30 31
Enter N/n for No and Y/y for Yes: y
Is your birthday in Set3?
4567
12 13 14 15
20 21 22 23
28 29 30 31
Enter N/n for No and Y/y for Yes: y
Is your birthday in Set4?
89 10 11
12 13 14 15
24 25 26 27
28 29 30 31
Enter N/n for No and Y/y for Yes: n
Is your birthday in Set5?
16 17 18 19
20 21 22 23
24 25 26 27
28 29 30 31
Enter N/n for No and Y/y for Yes: y
Your birthday is 22.
Submission Instruction:
• Submit your source files via Canvas by the beginning of the class on February 16, 2018.
• You only need to submit your source code les (.cpp).
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
Explanation / Answer
#include <iostream>
using namespace std;
void main()
{
int d = 0;
char ans;
cout << "Is your birthday in Set1?" << endl;
cout << " 1 3 5 7 " <<
" 9 11 13 15 " <<
"17 19 21 23 " <<
"25 27 29 31" << endl;
cout << "Enter N/n for No and Y/y for Yes: ";
cin >> ans;
if (ans == 'Y' || ans == 'y')
d = d + 1;
cout << " Is your birthday in Set2?" << endl;
cout << " 2 3 6 7 " <<
"10 11 14 15 " <<
"18 19 22 23 " <<
"26 27 30 31" << endl;
cout << "Enter N/n for No and Y/y for Yes: ";
cin >> ans;
if (ans == 'Y' || ans == 'y')
d = d + 2;
cout << " Is your birthday in Set3?" << endl;
cout << " 4 5 6 7 " <<
"12 13 14 15 " <<
"20 21 22 23 " <<
"28 29 30 31" << endl;
cout << "Enter N/n for No and Y/y for Yes: ";
cin >> ans;
if (ans == 'Y' || ans == 'y')
d = d + 4;
cout << " Is your birthday in Set4?" << endl;
cout << " 8 9 10 11 " <<
"12 13 14 15 " <<
"24 25 26 27 " <<
"28 29 30 31" << endl;
cout << "Enter N/n for No and Y/y for Yes: ";
cin >> ans;
if (ans == 'Y' || ans == 'y')
d = d + 8;
cout << " Is your birthday in Set5?" << endl;
cout << "16 17 18 19 " <<
"20 21 22 23 " <<
"24 25 26 27 " <<
"28 29 30 31" << endl;
cout << "Enter N/n for No and Y/y for Yes: ";
cin >> ans;
if (ans == 'Y' || ans == 'y')
d = d + 16;
cout << "Your birthday is " << d << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.