Run the Zodiac program – take note of Classes (custom types) Add a class Custome
ID: 3760170 • Letter: R
Question
Run the Zodiac program – take note of Classes (custom types)
Add a class Customer_T to model a customer that requested a horoscope. It will be composed of the first name, last name, a birthday (use the existing bd_T type) and a data memebrs to hold a Zodiac sign and a horoscope.
You can leverage the code for CustomerRecord structure written in the previous Lab (based on display 10.1) Not all the attributes will be needed, so remove what is not necessary (example: address fields)
Make sure all the data elements have a corresponding get_ and a set_ methods
Add a constructor to Customer_T which populates customer name and bd
Add a method to Customer_T which will display all the attributes with labels
Modify the “generate_horoscope” method in the Zodiac_T class to have a Customer_T argument passed by reference, and change the “generate_horoscope” method to set the zodiac sign in the passed-in object
The “main” would have to instantiate a Customer_T and set its attributes as read from the input stream
/*******************************************************************************************************
/ The CSC-160's Clairvoyant client requested a program ...
/
/
/********************************************************************************************************
Zodiac Sign names and dates :
Capricorn December 22 - January 19
Aquarius January 20 - February 18
Pices February 19 - March 20
Aries March 21 - April 19
Taurus April 20 - May 20
Gemini May 21 - June 21
Cancer June 22 - July 22
Leo July 23 - August 22
Virgo August 23 - September 22
Libra September 23 - October 22
Scorpio October 23 - November 21
Sagittarius November 22 - December 21
**************************************************************/
//Header file section
#include
<iostream>
#include
<fstream>
#include
<cstdlib> // exit
#include
<string>
using
namespace std;
class
bd_T {
int month;
int day;
public
:
bd_T();
// Default Constructor
bd_T(
int month, int day); // Constructor
void set_month(int month);
void set_day(int day);
int get_month();
int get_day();
bool validateBD();
};
class
zodiac_T {
// Private data types
struct zodiac_t {
string sign;
int boundary;
};
// Zodiac signs and boundaries in the array of structures
public:
zodiac_t zodiac_struct_array[12];
// Abrreviated Horoscope
private:
string horoscope_array[12];
// Horoscope line read from a file
string horoscope_array_more[12];
public:
zodiac_T();
void read_in_horoscope(string file_path);
void generate_horoscope(bd_T bd);
};
int
main()
{
int number;
char play_again = 0;
// bd_T encapsulates BD. Object get created and a Default Constructor is called
bd_T bd_Object;
// Zodiac_T encapsualtes all zodiac domain logic
zodiac_T zodiac_Object;
//////////////// Play loop
do
{
// Take BD input from user
cout << endl <<
"****** Welcome to CSC 160 Horoscope game! ******" << endl;
cout <<
"Enter birthday month in numeric form (1,2,... or 12):" << endl;
cin >> number;
cout <<
"Birthday Month: " << number << endl;
bd_Object.set_month(number);
cout <<
"Enter birthday day (1,2,... or 31):" << endl;
cin >> number;
cout <<
"Birthday Day: " << number << endl;
bd_Object.set_day(number);
// Validate BD, continue if invalid
if (!bd_Object.validateBD()) {
play_again =
'Y';
continue;
}
// Print Zodiac and horoscope
zodiac_Object.generate_horoscope(bd_Object);
// Play again?
cout <<
"Would you like another horoscope? ";
cin >> play_again;
}
while (play_again=='Y' || play_again=='y');
cin >> play_again;
// So the output (DOS) window stays open
}
//////////// END Main
////////////// Object bd_T
bd_T::bd_T(){
}
bd_T::bd_T(
int p_month, int p_day) {
month = p_month;
day = p_day;
}
void
bd_T::set_month(int p_month) {
month = p_month;
}
void
bd_T::set_day(int p_day) {
day = p_day;
}
int
bd_T::get_month(){
return month;
}
int
bd_T::get_day() {
return day;
}
bool
bd_T::validateBD() {
bool validation_result = true;
//////// Write code to validate bd_month and bd_day, return 'false' if invalid
if ((day < 1) || (day > 31) || (month < 1) || (month > 12))
validation_result =
false;
if (!validation_result)
cout <<
"You entered invalid BD! Please try again " << endl << endl;
return validation_result;
}
////////////// Object zodiac_T
zodiac_T::zodiac_T() {
zodiac_struct_array[0].sign =
"CAPRICORN";
zodiac_struct_array[0].boundary = 19;
zodiac_struct_array[1].sign =
"AQUARIUS";
zodiac_struct_array[1].boundary = 18;
zodiac_struct_array[2].sign =
"PISCES";
zodiac_struct_array[2].boundary = 20;
zodiac_struct_array[3].sign =
"ARIES";
zodiac_struct_array[3].boundary = 19;
zodiac_struct_array[4].sign =
"TAURUS";
zodiac_struct_array[4].boundary = 20;
zodiac_struct_array[5].sign =
"GEMINI";
zodiac_struct_array[5].boundary = 21;
zodiac_struct_array[6].sign =
"CANCER";
zodiac_struct_array[6].boundary = 22;
zodiac_struct_array[7].sign =
"LEO";
zodiac_struct_array[7].boundary = 22;
zodiac_struct_array[8].sign =
"VIRGIO";
zodiac_struct_array[8].boundary = 22;
zodiac_struct_array[9].sign =
"LIBRA";
zodiac_struct_array[9].boundary = 22;
zodiac_struct_array[10].sign =
"SCORPIO";
zodiac_struct_array[10].boundary = 21;
zodiac_struct_array[11].sign =
"SAGITTARIUS";
zodiac_struct_array[11].boundary = 21;
horoscope_array[0] =
"fun";
horoscope_array[1] =
"wise";
horoscope_array[2] =
"curious";
horoscope_array[3] =
"sad";
horoscope_array[4] =
"powerful";
horoscope_array[5] =
"interesting";
horoscope_array[6] =
"beautiful";
horoscope_array[7] =
"brave";
horoscope_array[8] =
"smart";
horoscope_array[9] =
"silly";
horoscope_array[10] =
"trustworthy";
horoscope_array[11] =
"ghostly";
}
void
zodiac_T::generate_horoscope(bd_T bd) {
// Cusp defined as 2 days before change of sign
const int cusp = 2;
// clear up variables
string zodiac_sign =
"";
string cusp_sign =
"";
string horoscope_txt =
"";
//if (bd_day <= zodiac_boundary[bd_month - 1]) {
if (bd.get_day() <= zodiac_struct_array[bd.get_month() - 1].boundary) {
zodiac_sign = zodiac_struct_array[bd.get_month() - 1].sign;
horoscope_txt =
"You will meet a " + horoscope_array[bd.get_month() - 1] + " person this week";
if (bd.get_day() >= zodiac_struct_array[bd.get_month() - 1].boundary - cusp) {
cusp_sign = zodiac_struct_array[bd.get_month()].sign;
}
}
else {
zodiac_sign = zodiac_struct_array[bd.get_month()].sign;
horoscope_txt =
"You will meet a " + horoscope_array[bd.get_month()] + " person this week";
}
// Print Zodiac sign
cout <<
"Your Zodiac is: " << zodiac_sign << endl;
//Print cusp
if (cusp_sign != "")
cout <<
" and you are on a cusp close to: " << cusp_sign << endl;
// Print Horoscope
cout <<
"Your Horoscope says: " << horoscope_txt << endl << endl;
}
Explanation / Answer
//Header file section
#include
<iostream>
#include
<fstream>
#include
<cstdlib> // exit
#include
<string>
using
namespace std;
class
bd_T {
int month;
int day;
public
:
bd_T();
// Default Constructor
bd_T(
int month, int day); // Constructor
void set_month(int month);
void set_day(int day);
int get_month();
int get_day();
bool validateBD();
};
class
zodiac_T {
// Private data types
struct zodiac_t {
string sign;
int boundary;
};
// Zodiac signs and boundaries in the array of structures
public:
zodiac_t zodiac_struct_array[12];
// Abrreviated Horoscope
private:
string horoscope_array[12];
// Horoscope line read from a file
string horoscope_array_more[12];
public:
zodiac_T();
void read_in_horoscope(string file_path);
void generate_horoscope(bd_T bd);
};
int
main()
{
int number;
char play_again = 0;
// bd_T encapsulates BD. Object get created and a Default Constructor is called
bd_T bd_Object;
// Zodiac_T encapsualtes all zodiac domain logic
zodiac_T zodiac_Object;
//////////////// Play loop
do
{
// Take BD input from user
cout << endl <<
"****** Welcome to CSC 160 Horoscope game! ******" << endl;
cout <<
"Enter birthday month in numeric form (1,2,... or 12):" << endl;
cin >> number;
cout <<
"Birthday Month: " << number << endl;
bd_Object.set_month(number);
cout <<
"Enter birthday day (1,2,... or 31):" << endl;
cin >> number;
cout <<
"Birthday Day: " << number << endl;
bd_Object.set_day(number);
// Validate BD, continue if invalid
if (!bd_Object.validateBD()) {
play_again =
'Y';
continue;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.