Question: Create an abstract data type age. One of the methods will calculate the age of a person. The data for the code can be stored
Create an abstract data type age. One of the methods will calculate the age of a person. The data for the code can be stored as either structures or classes. This code can be written as a console application in C++ or similar language (inlcuidng C, C#, or Java) to meet the following requirements.
- The program should accept the users input and check for valid/invalid input and warn then the user of any invalid:
Sample input:
What is the First Name: Joe
What is the Last Name: Watson
What is the birth year: 2004
What is the birth month: 7
What is the birth day: 4
- Use system time to identify todays date
- The output should include the persons name, date of birth, todays date being used and the persons age:
Sample output:
Joe Watson, age 14 was born on 7-4- 2004 and today is 1-30-2019
- Use a separate file to store the data as structures (or equivalent constructs- e.g., classes would also be a good choice) to store the persons information.
The code below is not complete: refer to it if needed. Make sure to organize the code into modules (e.g., methods) also when writing the code, you need to take into account the month and the day. Add validation, and comments to the code.
#include
#include
using namespace std;
struct perosn
{
char name[20];
int day;
int month;
int year;
}person1;
int main()
{
// current date/time based on current system
time_t now = time(0);
// convert now to string form
char* dt = ctime(&now);
cout << "The local date and time is: " << dt << endl;
cout << "Enter age year: ";
cin >> person1.year;
// convert now to tm struct for UTC
tm *gmtm = gmtime(&now);
dt = asctime(gmtm);
cout << "The UTC date and time is:" << dt << endl;
//cout << "minute :"<< gmtm->tm_min < //int currentYear = (int)gmtm->tm_year; int currentYear = gmtm->tm_year +1900; cout << "year :" << 1900 + gmtm->tm_year << endl; cout << "month :" << gmtm->tm_mon + 1 << endl; cout << "day :" << gmtm->tm_mday - 1 << endl; char c; cout << "age: " << currentYear - person1.year; cin >> c; } Scenario Except the provided sample above, the rest of the code must be an original code written by you.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
