Question

Write a C++ program that determines the user's age after the user enters both the current...

Write a C++ program that determines the user's age after the user enters both the current date and hisher birthdate as 3 integers: yyyy mm dd Define a class which is named DateType and will be used to declare 2 objects: "birthday" and "today". The class will have a function "output" which will display the date in conventional form (like it is above next to Date Assigned: Month dd, yyyy EXAMPLE: If the user entered the #’s: 2018 2 6 then output would display Feb 6, 2018 After the user enters the birthdate, display the dates in conventional form and the user's age. EXAMPLE: If the user entered a birthdate: 1999 7 4 The program would display: Today is Feb 6, 2018 Your birthday was on Jul 4, 1999 You are 18 years old

Program Must Use a Class

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This is the Output Screenshot of desired Program.

Below is the code:

C++ Code:

#include<iostream>
using namespace std;
class DateType
{
   public:
           int dd,mm,yyyy;
   public:
       void input()
       {
               cout<<"Enter Year:";
               cin>>yyyy;
               cout<<"Enter Month:";
               cin>>mm;
               cout<<"Enter Day:";
               cin>>dd;
       }
       void output()
       {
       if(mm==1)
       cout<<"Jan"<<" "<<dd<<", "<<yyyy;
       if(mm==2)
       cout<<"Feb"<<" "<<dd<<", "<<yyyy;
       if(mm==3)
       cout<<"Mar"<<" "<<dd<<", "<<yyyy;
       if(mm==4)
       cout<<"Apr"<<" "<<dd<<", "<<yyyy;
       if(mm==5)
       cout<<"May"<<" "<<dd<<", "<<yyyy;
       if(mm==6)
       cout<<"June"<<" "<<dd<<", "<<yyyy;
       if(mm==7)
       cout<<"July"<<" "<<dd<<", "<<yyyy;
       if(mm==8)
       cout<<"Aug"<<" "<<dd<<", "<<yyyy;
       if(mm==9)
       cout<<"Sep"<<" "<<dd<<", "<<yyyy;
       if(mm==10)
       cout<<"Oct"<<" "<<dd<<", "<<yyyy;
       if(mm==11)
       cout<<"Nov"<<" "<<dd<<", "<<yyyy;
       if(mm==12)
       cout<<"Dec"<<" "<<dd<<", "<<yyyy;
       }
  
};

int main ()
{
DateType birthday,today ;
cout<<"Enter Today's Date"<<endl;
today.input();
today.output();
cout<<endl;
cout<<"------------------------------------------------------------"<<endl;
cout<<"Enter Birth Date"<<endl;
birthday.input();
cout<<"Today is ";today.output();cout<<" Your birthday was on ";birthday.output();cout<<" You are ";
if(today.mm<=birthday.mm)
{
    if(today.dd<birthday.dd)
    cout<<today.yyyy-birthday.yyyy-1;
    else
    cout<<today.yyyy-birthday.yyyy;
}
else
cout<<today.yyyy-birthday.yyyy;
cout<<" years old";
cout<<endl;
cout<<"-----------------------------------------------------------"<<endl;

}

I have created program as per your need by keeping various Test Cases in mind .

Hope You will like it.

Thank You Dear.

Add a comment
Answer #1

This is the Output Screenshot of desired Program.

Below is the code:

C++ Code:

#include<iostream>
using namespace std;
class DateType
{
   public:
           int dd,mm,yyyy;
   public:
       void input()
       {
               cout<<"Enter Year:";
               cin>>yyyy;
               cout<<"Enter Month:";
               cin>>mm;
               cout<<"Enter Day:";
               cin>>dd;
       }
       void output()
       {
       if(mm==1)
       cout<<"Jan"<<" "<<dd<<", "<<yyyy;
       if(mm==2)
       cout<<"Feb"<<" "<<dd<<", "<<yyyy;
       if(mm==3)
       cout<<"Mar"<<" "<<dd<<", "<<yyyy;
       if(mm==4)
       cout<<"Apr"<<" "<<dd<<", "<<yyyy;
       if(mm==5)
       cout<<"May"<<" "<<dd<<", "<<yyyy;
       if(mm==6)
       cout<<"June"<<" "<<dd<<", "<<yyyy;
       if(mm==7)
       cout<<"July"<<" "<<dd<<", "<<yyyy;
       if(mm==8)
       cout<<"Aug"<<" "<<dd<<", "<<yyyy;
       if(mm==9)
       cout<<"Sep"<<" "<<dd<<", "<<yyyy;
       if(mm==10)
       cout<<"Oct"<<" "<<dd<<", "<<yyyy;
       if(mm==11)
       cout<<"Nov"<<" "<<dd<<", "<<yyyy;
       if(mm==12)
       cout<<"Dec"<<" "<<dd<<", "<<yyyy;
       }
  
};

int main ()
{
DateType birthday,today ;
cout<<"Enter Today's Date"<<endl;
today.input();
today.output();
cout<<endl;
cout<<"------------------------------------------------------------"<<endl;
cout<<"Enter Birth Date"<<endl;
birthday.input();
cout<<"Today is ";today.output();cout<<" Your birthday was on ";birthday.output();cout<<" You are ";
if(today.mm<=birthday.mm)
{
    if(today.dd<birthday.dd)
    cout<<today.yyyy-birthday.yyyy-1;
    else
    cout<<today.yyyy-birthday.yyyy;
}
else
cout<<today.yyyy-birthday.yyyy;
cout<<" years old";
cout<<endl;
cout<<"-----------------------------------------------------------"<<endl;

}

I have created program as per your need by keeping various Test Cases in mind .

Hope You will like it.

Thank You Dear.

Add a comment
Know the answer?
Add Answer to:
Write a C++ program that determines the user's age after the user enters both the current...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program that determines the user's age after the   user enters both the current...

    Write a C++ program that determines the user's age after the   user enters both the current date and hisher birthdate as 3   integers:                yyyy mm dd                                                                                             Define a class which is named DateType and will be used to     declare 2 objects: "birthday" and "today". The class will have a function "output" which will display the date in conventional form (like it is above next to Date Assigned: Month dd, yyyy and it will have a second function named     “input”...

  • Write a program that prompts the user to enter the date in mm/dd/yyyy format. The program...

    Write a program that prompts the user to enter the date in mm/dd/yyyy format. The program should use a single input statement to accept the date, storing each piece of the date into an appropriate variable. Demonstrate that the input was obtained correctly by outputting the month, day, and year to the screen. Sample output: Enter (date (mm/dd/yyyy): 02/08/2011 Month entered: 2 Day entered: 8 Year entered: 2011 Challenge: Although the user entered 02, C++ drops the 0 as insignificant...

  • Python 3. Date Printer Write a program that reads a string from the user containing a...

    Python 3. Date Printer Write a program that reads a string from the user containing a date in the form mm/dd/yyyy. It should print the date in the format March 12, 2018 3. Date Printer Write a program that reads a string from the user containing a date in the form mm/dd/yyyy. It should print the date in the format March 12, 2018

  • C Programming Quesition (Structs in C): Write a C program that prompts the user for a...

    C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...

  • Write a program that accepts a date from the user in the form mm/dd/yyyy

    # C PROGRAMMING LANGUAGEWrite a program that accepts a date from the user in the form mm/dd/yyyy and then dis- plays it in the form month dd, yyyy, where month is the name of the month: Enter a date (mm/dd/yyyy): 2/17/2011 You entered the date February 17, 2011 Store the month names in an array that contains pointers to strings.

  • Write a Visual C# program that will input the user's name and a message. The user...

    Write a Visual C# program that will input the user's name and a message. The user will be able to choose from an option of formatting tools to change the way the message (and only the message) will look. The user can choose from bold, underline, italic, along with several different color options. All changes the user selects will be displayed in the message textbox. Once the user selects the Finish button, the two pieces of information entered by the...

  • IN PYTHON, Write a program that reads a string from the user containing a date in...

    IN PYTHON, Write a program that reads a string from the user containing a date in the form mm/dd/ yyyy. It should print the date in the form April 12, 2017. Hint: Get the "mm" from the user entered date "mm/dd/yyyy", then convert the "mm" into a month number. You may use an list month_list = ['January', 'February','March','April', 'May','June', 'July','August', 'September', 'October', 'November', 'December']. Use the month number you got from "mm" to get the month name.

  • Write a program that reads a string from the user containing a date in the form...

    Write a program that reads a string from the user containing a date in the form mm/dd/yyyy. It should print the date in the format March 12, 2018   I am asking for help in basic python please

  • Write a program named CheckMonth2 that prompts a user to enter a birth month and day....

    Write a program named CheckMonth2 that prompts a user to enter a birth month and day. Display an error message that says Invalid date if the month is invalid (not 1 through 12) or the day is invalid for the month (for example, not between 1 and 31 for January or between 1 and 29 for February). If the month and day are valid, display them with a message. For example, if the month entered is 2, and the day...

  • You will be developing a program that determines if a date is between a start and...

    You will be developing a program that determines if a date is between a start and end date. Ask the user for a starting and ending date in the form of YYYY MM DD. Then ask the user for a date in the same form. If the date is between the starting and ending date, print "IN RANGE", otherwise print "OUT OF RANGE". Example Enter start date: 2017 1 24 Enter end date : 2019 1 24 Enter date :...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT