Question

In: Computer Science

One can find out date of the month when someone was born by asking five questions....

One can find out date of the month when someone was born by asking five questions. Each question asks whether the day is in one of the five sets of numbers below

1 3 5 7          2 3   6   7             4 5   6 7             8 9 10 11           16 17 18 19

9 11 13 15                  10 11 14 15          12 13 14 15          12 13 14 15          20 21 22 23

17 19 21 23                18 19 22 23          20 21 22 23          24 25 26 27          24 25 26 27

25 27 29 31                26 27 30 31          28 29 30 31          28 29 30 31          28 29 30 31

   Set1                              Set 2                      Set 3                    Set 4                    Set 5         

The birthday is the sum of the first numbers in the set where the day appears. For example, if the birthday is 19, it appears in Set 1, Set 2, and Set 5.

The first numbers in these three sets are 1, 2, and 16 whose sum is 19.

Write a C++ program using arrays that prompts the user to answer whether the day is in Sets 1‐5. If the number is in the particular set, the program adds the first number in the sets to calculate the day of the month. An array must be used in the problem. Refer to the sample output below.

Sample Run:

Is your birthday in Set 1?

1 3    5    7

9   11 13 15

17 19 21 23

25 27 29 31

Enter 0 for No and 1 for Yes: 1

Is your birthday in Set 2?

2 3 6 7

10 11 14 15

18 19 22 23

26 27 30 31

Enter 0 for No and 1 for Yes: 1

Is your birthday in Set 3?

4 5   6   7

12 13 14 15

20 21 22 23

28 29 30 31

Enter 0 for No and 1 for Yes: 1

Is your birthday in Set 4?

8 9 10 11

12 13 14 15

24 25 26 27

28 29 30 31

Enter 0 for No and 1 for Yes: 0

Is your birthday in Set 5?

16 17 18 19

20 21 22 23

24 25 26 27

28 29 30 31

Enter 0 for No and 1 for Yes: 0

Your birthday is on day: 7

Solutions

Expert Solution

//C++ program using arrays

#include<iostream>
using namespace std;
const int n = 4;   // n is the dimension of all 2D array
int sum = 0;
// function for printing all set values
void print_set(int arr[n][n]){
   int i,j;
   // static variable is used counting set number
   static int x = 1;
   cout<<"Is your birthday in Set"<<x++<<"?"<<endl;
   // printing set values of sets
   for(i=0;i<n;i++){
       for(j=0;j<n;j++) cout<<arr[i][j]<<" ";
       cout<<endl;
   }
   int no;
   cout<<"Enter 0 for No and 1 for Yes: ";
   cin>>no;
   // if Birthday is present in the set then adds the first number sets to calculate the day of the month
   if(no==1) sum = sum+arr[0][0];
   cout<<endl;
}
int main(){
  
   int set1[n][n] = {{1,3,5,7},{9,11,13,15},{17,19,21,23},{25,27,29,31}};   // set1
   int set2[n][n] = {{2,3,6,7},{10,11,14,15},{18,19,22,23},{26,27,30,31}};   // set2
   int set3[n][n] = {{4,5,6,7},{12,13,14,15},{20,21,22,23},{28,29,30,31}}; // set3
   int set4[n][n] = {{8,9,10,11},{12,13,14,15},{24,25,26,27},{28,29,30,31}}; // set4
   int set5[n][n] = {{16,17,18,19},{20,21,22,23},{24,25,26,27},{28,29,30,31}}; // set5
   print_set(set1);   // calling print_set() function for set1
   print_set(set2);       // calling print_set() function for set2
   print_set(set3);       // calling print_set() function for set3
   print_set(set4);       // calling print_set() function for set4
   print_set(set5);   // calling print_set() function for set5
   cout<<"Your birthday is on day: "<<sum<<endl;  
   return 0;
}


Related Solutions

Research techniques for asking questions to elicit appropriate responses. List five best practices for asking questions...
Research techniques for asking questions to elicit appropriate responses. List five best practices for asking questions as applied to patients of any culture. How may the best practices change for a Hispanic patient?
Can someone please explain how can someone find how to find the adiabatic flame temperature in...
Can someone please explain how can someone find how to find the adiabatic flame temperature in Kelvin when liquid methane reacts with liquid oxygen? Please show the calculations.
I have figured out the SPSS part, can someone answer the questions? Use SPSS to answer...
I have figured out the SPSS part, can someone answer the questions? Use SPSS to answer the following: Create a histogram to organize the following distributions of scores. How does the distribution look like? Normal curve, positive and negatively skewed? Construct a grouped frequency distribution table. Show the Mean Median and standard deviation of the data in your SPSS output. How many scores lie within the class interval that is equivalent to 100% Scores: 28 54 65 53 81 45...
R studio programing . can someone do an example of when to perform a one-sample wilcox...
R studio programing . can someone do an example of when to perform a one-sample wilcox signed-rank test. after, show modification to the previous function to perform a hypothesis comparing 2 population center with independent samples (mann-whitney test).
USE PYTHON to find out What day of the week is a given date? i.e. On...
USE PYTHON to find out What day of the week is a given date? i.e. On what day of the week was 5 August 1967? if it is given that 1 January 1900 was a tuesday Write a function is_leap() which takes 1 input argument, an integer representing a year, and returns True if the year was a leap year, and False if it was not. .Then, write a function days_since() which takes 3 input integers day, month, year, representing...
Find out the goals of the agreement, the date established, the countries participating, and summarize principal...
Find out the goals of the agreement, the date established, the countries participating, and summarize principal points of the agreement regarding tariffs, intellectual property, foreign direct investment, and rules regulating environmental, health and safety, minimum wages, and child labor. Research two of the following examples of regional economic cooperation. In 3 paragraphs TPP (Trans Pacific Partnership) APEC (Asia-Pacific Economic Cooperation) Mercosur (Southern Common Market) ASEAN (Association of Southeast Asian Nations)
Is there a way to have the same response when someone does not fill out the...
Is there a way to have the same response when someone does not fill out the number correctly on my second code. Is there a way to not use the alert. <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Untitled Document</title> <script>    function phonenumber(inputtxt){           var phoneno = (\(\d{3}\)|\d{3})[-\s]\d{3}-\d{4};       if(inputtxt.value.match(phoneno)){        document.getElementById("yourEntry").innerHTML = document.getElementById("myphone").value;    }    //if(!inputtxt.value.match(phoneno)){        // alert("Does not Work!")        //}    } </script> </head> <body> <form name="form1" action="#"> <input...
Can someone please answer these two by Friday? Problem 3 Five men and five women are...
Can someone please answer these two by Friday? Problem 3 Five men and five women are ranked according to their scores on an examination. Assume that no two scores are alike, and all 10! possible rankings are equally likely. Let X denote the highest ranking achieved by a woman (for example, X = 2 if the top-ranked person was a man, and the next-ranked person was a woman). Find the probability mass function (pmf) of the random variable X, and...
A baby who is born five days ago is showing a clinical symptom for infection. One...
A baby who is born five days ago is showing a clinical symptom for infection. One of the clinical symptoms is the body temperature increases to 40 celcius and what is the temperature scale in Fahrenheit?
Suppose that someone gives you an unknown solution, and you wish to find out whether this...
Suppose that someone gives you an unknown solution, and you wish to find out whether this solution contains glucose. To do this, you perform a Benedict’s test. Performing this test requires adding something called ____________________ solution to the solution of interest. Consider the solution you named in the previous question. After adding this to your solution of interest, what do you have to do next? If you perform a Benedict’s test on a solution that does contain glucose, then it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT