In: Computer Science
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)
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