Question

In: Computer Science

Implement in C++ a game called “Your Lucky Number”. The lucky number is calculated based on...

Implement in C++ a game called “Your Lucky Number”. The lucky number is calculated based on an individual’s birth month, day, and year. The algorithm assigns any person a number between 1 and 9. Many people believe that a group of people with the same lucky number share common features. The lucky number is calculated as the sum of digits of the birth month, day, and year numbers. If this sum is not a single digit then you need to keep adding up its digits. Use the C++ functions when you implement the game. Test your program for corrections. To start the game you should enter your full birthdate in the format: month day year, e.g. 9 21 1985. The month is represented by its corresponding integer: January is 1, February is 2, ..., and December is 12. Be sure that your program will verify the input format and print an error message when the format is incorrect (use exceptions), and will ask to re-enter the birthdate again.

The algorithm for calculating the lucky number

(a) Enter the month as an integer from 1 to 12.

(b) Reduce the month, day and year numbers down to a one-digit number by adding all digits in month, day and year numbers, see the example below.

(c) Map the number to the category listed below and display the message on the screen with at least four features for a person in each category. I provided only one feature (as an adjective) for each category and you should complete the list.

(d) Test your program using at least 10 your friends’ or relatives’ birthdays.

(e) Provide statistics in the README file about the results of your testing by giving the percentage of people that confirm that they belong to the category calculated by your program. Write in the README file about what you have learned by writing this assignment. Write also about your (possible) problems, errors or mistakes.

Categories:

1. The Leader: original thinker (add 3 more features)

2. The Mediator: diplomatic (add 3 more features)

3. The Communicator: expressive (add 3 more features)

4. The Teacher: trustworthy (add 3 more features)

5. The Freedom Seeker: adventurous (add 3 more features)

6. The Nurturer: family-oriented (add 3 more features)

7. The Seeker: analytic (add 3 more features)

8. The Power House: authoritative (add 3 more features)

9. The Humanitarian: charitable (add 3 more features)

Solutions

Expert Solution

luckyNumber.cpp

#include<bits/stdc++.h>
using namespace std;

//function to get sum of digits
int digitSum(int num)
{
   if (num == 0)
   return 0;
   return (num % 9 == 0 ) ? 9 : (num % 9);
}

int main ()
{
   int day,month,year,luckyNumber; //variable declaration
  
  
   //enter date of birth
   cout<<"\nEnter Your Date of Birth (dd mm yyyy): ";
   cin>>day>>month>>year;
  
   //enter date of birth until input is in correct format
   while(true)
   {
       try
       {
           if (day<0 || day>31 || month<0 || month>12) //if input not in correct format throw an exception
           throw 1;
           else break;   
       }
       catch(int x) //catch exception and show an error message
       {
       cout<<"Invalid Date of Birth:"<<endl;
   cout<<"\nEnter Your Date of Birth (dd mm yyyy) : "; //again enter date of birth
   cin>>day>>month>>year;
       }
         
   }
  
   //categories according to lucky Number
   // more features you can add
   string categories [] = {
   "The Leader: original thinker (add 3 more features)",
"The Mediator: diplomatic (add 3 more features)",
"The Communicator: expressive (add 3 more features)",
"The Teacher: trustworthy (add 3 more features)",
"The Freedom Seeker: adventurous (add 3 more features)",
"The Nurturer: family-oriented (add 3 more features)",
"The Seeker: analytic (add 3 more features)",

"The Power House: authoritative (add 3 more features)",

"The Humanitarian: charitable (add 3 more features)"
  
  
   };
  
  
   //find lucky number by adding digits
   // until get single digit
luckyNumber = digitSum(digitSum(day) + digitSum(month) + digitSum(year));
      
//print category as lucky number
   cout<<categories[luckyNumber-1];
  
   return 0; //end of program
  
}

OUTPUT SCREEN


Related Solutions

IN C++ Implement in C++ a game called “Your Lucky Number”. The lucky number is calculated...
IN C++ Implement in C++ a game called “Your Lucky Number”. The lucky number is calculated based on an individual’s birth month, day, and year. The algorithm assigns any person a number between 1 and 9. Many people believe that a group of people with the same lucky number share common features. The lucky number is calculated as the sum of digits of the birth month, day, and year numbers. If this sum is not a single-digit then you need...
Assignment Implement Conway’s Game of Life IN C The Game of Life is a simple simulation...
Assignment Implement Conway’s Game of Life IN C The Game of Life is a simple simulation that takes place in a grid of cells. Each cell can be either alive or dead, and it interacts with its neighbors (horizontally, vertically, or diagonally). In each iteration, a decision will be made to see if living cells stay alive, or if dead cells become alive. The algorithm is as follows: If a cell is alive: If it has less than two living...
In the game of Lucky Sevens, the player rolls a pair of dice. If the dots...
In the game of Lucky Sevens, the player rolls a pair of dice. If the dots add up to 7, the player wins $4; otherwise, the player loses $1. Suppose that, to entice the gullible, a casino tells players that there are lots of ways to win: (1, 6), (2, 5), and so on. A little mathematical analysis reveals that there are not enough ways to win to make the game worthwhile; however, because many people’s eyes glaze over at...
In the game of Lucky Sevens, the player rolls a pair of dice. If the dots...
In the game of Lucky Sevens, the player rolls a pair of dice. If the dots add up to 7, the player wins $4; otherwise, the player loses $1. Suppose that, to entice the gullible, a casino tells players that there are many ways to win: (1, 6), (2, 5), and soon. A little mathematical analysis reveals that there are not enough ways to win to make the game worthwhile; however, because many people's eyes glaze over at the first...
The objective of this assignment is to implement the tic-tac-toe game with a C program. The...
The objective of this assignment is to implement the tic-tac-toe game with a C program. The game is played by two players on a board defined as a 5x5 grid (array). Each board position can contain one of two possible markers, either ‘X’ or ‘O’. The first player plays with ‘X’ while the second player plays with ‘O’. Players place their markers in an empty position of the board in turns. The objective is to place 5 consecutive markers of...
Number guessing Game (20 Marks) Write a C program that implements the “guess my number” game....
Number guessing Game Write a C program that implements the “guess my number” game. The computer chooses a random number using the following random generator function srand(time(NULL)); int r = rand() % 100 + 1; that creates a random number between 1 and 100 and puts it in the variable r. (Note that you have to include <time.h>) Then it asks the user to make a guess. Each time the user makes a guess, the program tells the user if...
Design and implement a C++ class called Module that handles information regarding your assignments for a specific module.
Design and implement a C++ class called Module that handles information regarding your assignments for a specific module. Think of all the things you would want to do with such a class and write corresponding member functions for your Module class. Your class declaration should be well-documented so that users will know how to use it.Write a main program that does the following: Declare an array of all your modules. The elements of the array must be of type Module....
Implement a C++ program to implement the Banker’s algorithm for deadlock avoidance. Number of process 5,...
Implement a C++ program to implement the Banker’s algorithm for deadlock avoidance. Number of process 5, number of resources 3 and the number of instances of each given resource is in available. You should complete the functionalities for safe state check and resource request processing. To Do 1. Complete the definition of isSafe function. The function take, the process array, 1D array of available resources, 2D array storing current allocation, and 2D array of current need. The function does not...
Please generate code in PYTHON: In the game of Lucky Sevens, the player rolls a pair...
Please generate code in PYTHON: In the game of Lucky Sevens, the player rolls a pair of dice. If the dots add up to 7, the player wins $4; otherwise, the player loses $1. Suppose that, to entice the gullible, a casino tells players that there are lots of ways to win: (1, 6), (2, 5), and so on. A little mathematical analysis reveals that there are not enough ways to win to make the game worthwhile; however, because many...
This is done in C++. This is a game where one player thinks of a number...
This is done in C++. This is a game where one player thinks of a number between 1 and a 1000 and the other player has to guess in 10 tries or less. Allow two variations: the computer to pick the number and the player guesses or the player to pick the number and the computer to guesses. 1 – Player one picks a number 2 – Player two guesses the number. 3 – Player one either confirms that the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT