Write a C program that asks users first name last name and d

Write a C++ program that asks user’s first name, last name, and date of birth, and stores the information in the structure data type ‘Person’. The data type ‘Person’ has four member variables: first name, last name, date of birth, and age. First name and last name are string types, age is an integer type, and date of birth is another structure type ‘Date’. The data type ‘Date’ has three member variables: year, month, day as integer. Age, a member variable of the structure ‘Person’, should be calculated based on the current date. For example, if the user’s birth year is 1995 and the birthday has not passed yet, the user’s age would be 20. As an output, the program should print user’s name and calculated age.

USING THIS?

OUTPUT?

First name: Kate

Last name: Lee

Birth year: 1995

Birth month: 11

Birth day: 10

Name: Kate Lee

Age: 20

Thank you!!

Solution

#include<iostream>
#include<string.h>
using namespace std;

struct date
{
int year,month,day;
};

struct Person
{
string firstName,lastName;
date dob;
int age;
};

int main()
{
Person p;
date today = {2016,10,30};
  
cout << \"Please enter your first name : \";
cin >> p.firstName;
  
cout << \"Please enter your last name : \";
cin >> p.lastName;
  
cout << \"Please enter your birth year : \";
cin >> p.dob.year;
  
cout << \"Please enter your birth date : \";
cin >> p.dob.day;
  
cout << \"Please enter your birth month : \";
cin >> p.dob.month;
  
p.age = today.year - p.dob.year - 1;
  
cout << \"Person Details : \ \";
cout << \"First Name : \" << p.firstName << endl;
cout << \"Last Name : \" << p.lastName << endl;
cout << \"Birth Year : \" << p.dob.year << endl;
cout << \"Birth Month : \" << p.dob.month << endl;
cout << \"Birth Day : \" << p.dob.day << endl;
cout << \"Name : \" << p.firstName << \" \" << p.lastName << endl;
cout << \"Age : \" << p.age << endl;
return 0;
}

OUTPUT:

Please enter your first name : Kate

Please enter your last name : Lee

Please enter your birth year : 1995

Please enter your birth date : 10

Please enter your birth month : 11

Person Details :
First Name : Kate
Last Name : Lee
Birth Year : 1995
Birth Month : 11
Birth Day : 10
Name : Kate Lee
Age : 20

Write a C++ program that asks user’s first name, last name, and date of birth, and stores the information in the structure data type ‘Person’. The data type ‘Pe
Write a C++ program that asks user’s first name, last name, and date of birth, and stores the information in the structure data type ‘Person’. The data type ‘Pe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site