Question & Answer: Draw a complete flowchart for the following C++ prog……

Draw a complete flowchart for the following C++ prog.

#include <iostream>
using namespace std;
int main()
{
int birthyear, birthmonth, birthday, currentyear, currentmonth, currentday, currentageyear, currentagemonth, currentageday;
char yesno;
cout << “nntt Basili’s Age Calculator nn”;
cout << “In which year where you born? (Example: 1996) “;
cin >> birthyear;
cout << endl << “In which month were you born? ” << endl << endl;
cout << ” 1) January n 2) February n 3) March n 4) April n 5) May n 6) June n 7) July”;
cout << endl << ” 8) August n 9) September n 10) October n 11) November n 12) December”;
cout << endl << endl << “Enter a value: “;
cin >> birthmonth;
while(birthmonth <= 0 || birthmonth > 12)
{

cout << endl << birthmonth << ” is an invalid value. “;
cout << “1 to 12 are valid values.” << endl;
cout << “Enter a valid value: “;
cin >> birthmonth;
}
cout << endl << “On which day of the month were you born? “;
cin >> birthday;
if(birthmonth == 1 || birthmonth == 3 || birthmonth == 5 || birthmonth == 7 || birthmonth == 8 || birthmonth == 10 || birthmonth == 12)
{
while(birthday <= 0 || birthday > 31)
{

cout << endl << birthday << ” is an invalid value for a day of a month.” << endl;
cout << “Enter a valid value. 1 to 31 are valid values: “;
cin >> birthday;
}
}
if(birthmonth == 4 || birthmonth == 6 || birthmonth == 9 || birthmonth == 11)
{
while(birthday <= 0 || birthday > 30)
{

cout << endl << birthday << ” is an invalid value for a day of a month.” << endl;
cout << “Enter a valid value. 1 to 30 are valid values: “;
cin >> birthday;
}
}
if(birthmonth == 2)
{
if(birthyear%4 == 0)
{
if(birthyear%100 == 0 && birthyear%400 != 0)
{
while(birthday <= 0 || birthday > 28)
{

cout << endl << birthday << ” is an invalid value for a day of a month.” << endl;
cout << “Enter a valid value. 1 to 28 are valid values: “;
cin >> birthday;
}
}
else
{
while(birthday <= 0 || birthday > 29)
{

cout << endl << birthday << ” is an invalid value for a day of a month.” << endl;
cout << “Enter a valid value. 1 to 29 are valid values: “;
cin >> birthday;
}
}
}
else
{
while(birthday <= 0 || birthday > 28)
{

cout << endl << birthday << ” is an invalid value for a day of a month.” << endl;
cout << “Enter a valid value. 1 to 28 are valid values: “;
cin >> birthday;
}
}
}
if(birthmonth == 1)
{

cout << endl << “You were born on the ” << birthday << “th January ” << birthyear << “.” << endl;
cout << endl << “Is that right? (Y/N) “;
cin >> yesno;
if(yesno != ‘Y’ && yesno != ‘y’)
{
cout << endl << “The program will be restarted so you can enter your “;
cout << “data again.” << endl << endl;
main();
}
}
if(birthmonth == 2)
{

cout << endl << “You were born on the ” << birthday << “th February ” << birthyear << “.” << endl;
cout << endl << “Is that right? (Y/N) “;
cin >> yesno;
if(yesno != ‘Y’ && yesno != ‘y’)
{
cout << endl << “The program will be restarted so you can enter your “;
cout << “data again.” << endl << endl;

main();
}
}
if(birthmonth == 3)
{

cout << endl << “You were born on the ” << birthday << “th March ” << birthyear << “.” << endl;
cout << endl << “Is that right? (Y/N) “;
cin >> yesno;
if(yesno != ‘Y’ && yesno != ‘y’)
{
cout << endl << “The program will be restarted so you can enter your “;
cout << “data again.” << endl << endl;

main();
}
}
if(birthmonth == 4)
{

cout << endl << “You were born on the ” << birthday << “th April ” << birthyear << “.” << endl;
cout << endl << “Is that right? (Y/N) “;
cin >> yesno;
if(yesno != ‘Y’ && yesno != ‘y’)
{
cout << endl << “The program will be restarted so you can enter your “;
cout << “data again.” << endl << endl;

main();
}
}
if(birthmonth == 5)
{

cout << endl << “You were born on the ” << birthday << “th May ” << birthyear << “.” << endl;
cout << endl << “Is that right? (Y/N) “;
cin >> yesno;
if(yesno != ‘Y’ && yesno != ‘y’)
{
cout << endl << “The program will be restarted so you can enter your “;
cout << “data again.” << endl << endl;

main();
}
}
if(birthmonth == 6)
{

cout << endl << “You were born on the ” << birthday << “th June ” << birthyear << “.” << endl;
cout << endl << “Is that right? (Y/N) “;
cin >> yesno;
if(yesno != ‘Y’ && yesno != ‘y’)
{
cout << endl << “The program will be restarted so you can enter your “;
cout << “data again.” << endl << endl;

main();
}
}
if(birthmonth == 7)
{

cout << endl << “You were born on the ” << birthday << “th July ” << birthyear << “.” << endl;
cout << endl << “Is that right? (Y/N) “;
cin >> yesno;
if(yesno != ‘Y’ && yesno != ‘y’)
{
cout << endl << “The program will be restarted so you can enter your “;
cout << “data again.” << endl << endl;

main();
}
}
if(birthmonth == 8)
{

cout << endl << “You were born on the ” << birthday << “th August ” << birthyear << “.” << endl;
cout << endl << “Is that right? (Y/N) “;
cin >> yesno;
if(yesno != ‘Y’ && yesno != ‘y’)
{
cout << endl << “The program will be restarted so you can enter your “;
cout << “data again.” << endl << endl;

main();
}
}
if(birthmonth == 9)
{

cout << endl << “You were born on the ” << birthday << “th September ” << birthyear << “.” << endl;
cout << endl << “Is that right? (Y/N) “;
cin >> yesno;
if(yesno != ‘Y’ && yesno != ‘y’)
{
cout << endl << “The program will be restarted so you can enter your “;
cout << “data again.” << endl << endl;

main();
}
}
if(birthmonth == 10)
{

cout << endl << “You were born on the ” << birthday << “th October ” << birthyear << “.” << endl;
cout << endl << “Is that right? (Y/N) “;
cin >> yesno;
if(yesno != ‘Y’ && yesno != ‘y’)
{
cout << endl << “The program will be restarted so you can enter your “;
cout << “data again.” << endl << endl;

main();
}
}
if(birthmonth == 11)
{

cout << endl << “You were born on the ” << birthday << “th November ” << birthyear << “.” << endl;
cout << endl << “Is that right? (Y/N) “;
cin >> yesno;
if(yesno != ‘Y’ && yesno != ‘y’)
{
cout << endl << “The program will be restarted so you can enter your “;
cout << “data again.” << endl << endl;

main();
}
}
if(birthmonth == 12)
{

cout << endl << “You were born on the ” << birthday << “th December ” << birthyear << “.” << endl;
cout << endl << “Is that right? (Y/N) “;
cin >> yesno;
if(yesno != ‘Y’ && yesno != ‘y’)
{
cout << endl << “The program will be restarted so you can enter your “;
cout << “data again.” << endl << endl;

main();
}
}

cout << endl << “Which year is it now? “;
cin >> currentyear;
while(currentyear < birthyear)
{
cout << endl << “Your birthyear can’t be bigger than the current year.” << endl;
cout << “Enter a valid year: “;
cin >> currentyear;
}
cout << endl << “Which month is it now? ” << endl << endl;
cout << ” 1) January n 2) February n 3) March n 4) April n 5) May n 6) June n 7) July”;
cout << endl << ” 8) August n 9) September n 10) October n 11) November n 12) December”;
cout << endl << endl << “Enter a value: “;
cin >> currentmonth;
while(currentmonth <= 0 || currentmonth > 12)
{

cout << endl << birthmonth << ” is an invalid value. “;
cout << “1 to 12 are valid values.” << endl;
cout << “Enter a valid value: “;
cin >> currentmonth;
}
while(currentyear == birthyear && currentmonth < birthmonth)
{

cout << endl << “You aren’t born yet. This program is only intended for the people who are born” << endl;
cout << “Just wait a few months, or enter a valid current month: “;
cin >> currentmonth;
}
cout << endl << “Which day of the month is it now? “;
cin >> currentday;
if(currentmonth == 1 || currentmonth == 3 || currentmonth == 5 || currentmonth == 7 || currentmonth == 8 || currentmonth == 10 || currentmonth == 12)
{
while(currentday <= 0 || currentday > 31)
{

cout << endl << birthday << ” is an invalid value for a day of the month.” << endl;
cout << “1 to 31 are valid values. Enter a valid value: “;
cin >> birthday;
}
}
if(currentmonth == 4 || currentmonth == 6 || currentmonth == 9 || currentmonth == 11)
{
while(currentday <= 0 || currentday > 30)
{

cout << endl << birthday << ” is an invalid value for a day of the month.” << endl;
cout << “1 to 30 are valid values. Enter a valid value: “;
cin >> birthday;
}
}
if(currentmonth == 2)
{
if(currentyear%4 == 0)
{
if(currentyear%100 == 0 && currentyear%400 != 0)
{
while(currentday <= 0 || currentday > 28)
{

cout << endl << birthday << ” is an invalid value for a day of the month.” << endl;
cout << “1 to 28 are valid values. Enter a valid value: “;
cin >> birthday;
}
}
else
{
while(currentday <= 0 || currentday > 29)
{

cout << endl << birthday << ” is an invalid value for a day of the month.” << endl;
cout << “1 to 29 are valid values. Enter a valid value: “;
cin >> birthday;
}
}
}
else
{
while(currentday <= 0 || currentday > 28)
{

cout << endl << birthday << ” is an invalid value for a day of the month.” << endl;
cout << “1 to 28 are valid values. Enter a valid value: “;
cin >> birthday;
}
}
}
if(currentyear == birthyear && currentmonth == birthmonth && currentday < birthday)
{

cout << endl << “You aren’t born yet. This program is only intended for the people who are born.” << endl;
cout << “Just wait a few days, or enter a valid day: “;
cin >> currentday;
}
cout << endl << “The system is calculating your age…” << endl << endl;
currentageyear = currentyear – birthyear;
currentagemonth = currentmonth – birthmonth;
currentageday = currentday – birthday;
if(currentagemonth < 0)
{
currentageyear = currentageyear – 1;
currentagemonth = 12 + currentagemonth;
}
if(currentageday < 0 && currentagemonth == 0)
{
currentageyear = currentageyear – 1;
currentagemonth = 12 – 1;
if(currentmonth == 1 || currentmonth == 3 || currentmonth == 5 || currentmonth == 7 || currentmonth == 8 || currentmonth == 10 || currentmonth == 12)
{
currentageday = 31 + currentageday;
}
if(currentmonth == 4 || currentmonth == 6 || currentmonth == 9 || currentmonth == 11)
{
currentageday = 30 + currentageday;
}
if(currentmonth == 2)
{
currentageday = 28 + currentageday;
if(currentyear%4 == 0)
{
currentageday = 29 + currentageday;
if(currentyear%100 == 0 && currentyear%400 != 0)
{
currentageday = 28 + currentageday;
}
}
}
}
if(currentageday < 0 && currentagemonth != 0)
{
currentagemonth = currentagemonth – 1;
if(currentmonth == 1 || currentmonth == 3 || currentmonth == 5 || currentmonth == 7 || currentmonth == 8 || currentmonth == 10 || currentmonth == 12)
{
currentageday = 32 + currentageday;
}
if(currentmonth == 4 || currentmonth == 6 || currentmonth == 9 || currentmonth == 11)
{
currentageday = 31 + currentageday;
}
if(currentmonth == 2)
{
currentageday = 29 + currentageday;
if(currentyear%4 == 0)
{
currentageday = 30 + currentageday;
if(currentyear%100 == 0 && currentyear%400 != 0)
{
currentageday = 29 + currentageday;
}
}
}
}
cout << “Birthyear: ” << birthyear << endl;
cout << “Birthmonth: ” << birthmonth << endl;
cout << “Birthday: ” << birthday << endl << endl;
if(currentageday != 1 && currentagemonth != 1)
{
cout << “You are ” << currentageyear << ” years, ” << currentagemonth << ” months and ” << currentageday << ” days old.”;
}
if(currentageday == 1 && currentagemonth == 1)
{
cout << “You are ” << currentageyear << ” years, ” << currentagemonth << ” month and ” << currentageday << ” day old.”;
}
if(currentageday != 1 && currentagemonth == 1)
{
cout << “You are ” << currentageyear << ” years, ” << currentagemonth << ” month and ” << currentageday << ” days old.”;
}
if(currentageday == 1 && currentagemonth != 1)
{
cout << “You are ” << currentageyear << ” years, ” << currentagemonth << ” months and ” << currentageday << ” day old.”;
}
if(currentageyear == 0 && currentagemonth == 0 && currentageday == 0)
{
cout << endl << “You are just born!” << endl;
}
if(currentageyear != 0 && currentagemonth == 0 && currentageday == 0)
{
cout << endl << endl << “Happy birthday! You have become ” << currentageyear << ” years old now!” << endl;
}
cout << endl << endl;

return 0;
}

Expert Answer

 

Still stressed from student homework?
Get quality assistance from academic writers!