In: Computer Science
Struct PERSON Assignment
Outcomes:
Program Specifications:
DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON.
Create a struct using the typedef command for a DATE.
Create a struct for a PERSON with the following fields.
Create three variables of type PERSON. Create a function that populates the data for each person (all 3 of them). Create a function that outputs all data about each of the people in a nice formatted manner.
Data Validation:
All dates entered must be validated. Make sure you account for the number of days in each month, the fact that there are exactly 12 months and every four years there is a leap year.
The name for each PERSON will be stored in sentence case.
The gender will either be M, F, or O.
The annual income will between 0 dollars and 1 million dollars.
Submission Requirements:
Requirements will be same as the first assignment which will be the same for all future assignments except that you do NOT NEED a design tool for this assignment.
DO NOT:
CONSIDERING THE PARAMETERS FROM QUESTION WE SHOW THE FOLLOWING AS
# include<bits/stdc++.h>
using namespace std;
struct valid_years {
static const int MAX_VALID_YR = 9999;
static const int MIN_VALID_YR = 1800;
};
typedef struct Date {
int date, month, year;} DATE;
typedef struct Person_details {
string name;
DATE birthday;
char gender;
float annual_income;
} PERSON;
bool isLeap(int year) {
return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
}
bool isValidDate(int d, int m, int y)
{
if (y > valid_years::MAX_VALID_YR || y < valid_years::MIN_VALID_YR)
return false;
if (m < 1 || m > 12)
return false;
if (d < 1 || d > 31)
return false;
if (m == 2)
{
if (isLeap(y))
return (d <= 29);
else
return (d <= 28);
}
if (m == 4 || m == 6 || m == 9 || m == 11)
return (d <= 30);
return true;
}
/*
check recursively whether gender is correct or not
*/
char check_gender(char gender) {
if(gender=='M' || gender=='F' || gender=='O')
return gender;
cout<<"\n Entered gender is not correct.... Enter again(M,F,O)\n";
char re_gender;
cin>>re_gender;
return check_gender(re_gender);
}
/*
check recursively whether income lies in the range or not
*/
float check_income(float income) {
if(income>=0.00 && income<= 1000000.00 )
return income;
cout<<"\n Entered income is not in range (0 - 1000000).... re enter. \n";
float re_income;
cin>> re_income;
return check_income(re_income);
}
/*
check recursively whether date is correct or not
*/
DATE check_date(DATE birthday) {
if(isValidDate(birthday.date, birthday.month, birthday.year))
return birthday;
cout<<"\n entered birthday is not valid... enter again\n";
DATE d1;
cin>>d1.date>>d1.month>>d1.year;
return check_date(d1);
}
/*
converts first letter of name to uppercase
*/
char check_name(char name) {
return toupper(name);
}
/*
this method validate the entered data for each person
*/
void validate(PERSON person[],int size) {
for(int i=0;i<size;i++) {
cout<<"\n ....verifying person: "<<i+1;
person[i].name[0] = check_name(person[i].name[0]);
person[i].gender = check_gender(person[i].gender);
person[i].annual_income = check_income(person[i].annual_income);
person[i].birthday = check_date(person[i].birthday);
}
}
/*
this method populate the Person Object for each person
*/
void populate_person(PERSON person[],int size) {
for(int i=0;i<size;i++) {
cout<<"\n----------------------------------";
cout<<"\n\nEnter details for person: "<<i+1<<"\n";
cout<<"\n enter name\n";
cin>>person[i].name;
cout<<"\n enter birthday is (dd mm yyyy) format\n";
cin>>person[i].birthday.date>>person[i].birthday.month>>person[i].birthday.year;
cout<<"\n enter gender:\n";
cin>>person[i].gender;
cout<<"\n enter annual income:\n";
cin>>person[i].annual_income;
cout<<"\n----------------------------------";
}
}
/*
this method display the Person object for each person
*/
void show_person(PERSON person[],int size) {
for(int i=0;i<size;i++) {
cout<<"\n ** Details for person:"<<i+1;
cout<<"\n name: "<<person[i].name;
cout<<"\n birthday: "<<person[i].birthday.date<<"-";
cout<<person[i].birthday.month<<"-"<<person[i].birthday.year;
cout<<"\n Gender: "<<person[i].gender;
cout<<"\n annual income: "<<person[i].annual_income<<"\n\n";
}
}
int main() {
PERSON person[3];
populate_person(person,3);
validate(person,3);
show_person(person,3);
}
PLEASE UPVOTE ITS VERY NECESSARY FOR ME