1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
// Birthdates.cpp : main project file.
/******SQU*******C++******SQU******C++*****SQU*******C++*****SQU*****
Name: sanalbarq.net
This Program is going to :
1. Read the birth date & another date.
2. Check & validation & Find the next date of the entered date ( NOT for the birthdate) .
3. Calculate The age up to the given date .
3. Check if the same date DD MM has passed or not in the current year &
calculate how many days still reamaining .
******SQU*******C++******SQU******C++*****SQU*******C++*****SQU******/
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std ;
// ***** ( PROTYPES ) ******
//1. CHECKING the validation of Birth Date
void check_birthdate(int month_birth , int day_birth , int year_birth );
//2. CHECKING the validation of CURRENT Date
void check_currentdate(int day_date , int month_date , int year_date ,int day_birth ,int month_birth ,int year_birth ) ;
//3. Finding the Next Day of Day Entered
void nxt_date(int day_date,int month_date,int year_date);
int main () //start main
{
string months[] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
//Declarations
int day_birth , month_birth , year_birth ;
int day_date , month_date , year_date ;
int day_age , month_age , year_age ;
// int nxt_day , nxt_month , nxt_year ;
// reading from user {BIRTH_DATE}
cout << "Type your Birth_date as (mm dd yyyy) : " ;
cin >> month_birth >> day_birth >> year_birth ;
cout<<endl;
//-----------
//<>**** CHECKING the validation of Birth Date ****
check_birthdate(month_birth , day_birth ,year_birth );
cout<<"***************************" << endl ;
cout<<"The BIRTH Date : "<< months[month_birth-1] <<" "<< day_birth<<", "<<year_birth<<endl<<endl;
//--> reading from user {CURRENT_DATE}
cout << "Type The Date (mm dd yyyy) : " ;
cin >> month_date >> day_date >> year_date ;
//------------
//<>**** CHECKING the validation of CURRENT Date
check_currentdate(day_date , month_date ,year_date,day_birth , month_birth ,year_birth );
cout << "*************************************" << endl ;
cout<<"The CURRENT DATE : "<< months[month_date-1] <<" "<< day_date<<", "<<year_date << endl;
cout<<" The BIRTH DATE : "<< months[month_birth-1] <<" "<< day_birth<<", "<<year_birth << endl;
cout << "*************************************" << endl ;
//-------------
// CallinG NeXt _ DaTe Finding Function .
nxt_date(day_date,month_date,year_date);
// Finding the age ...
year_age = year_date - year_birth ;
month_age = month_date - month_birth ;
day_age = day_date - day_birth ;
if(month_birth>month_date)
{
year_age--;
month_age = 12-(month_birth - month_date);
}
if(month_birth<month_date)
month_age = month_date - month_birth;
cout << endl << "The Age is : " << year_age << " years";
if (month_age)
{
cout << " and " << month_age << " month";
if (month_age >1)
cout << "s";
}
cout << " of age." << endl << endl;
system("PAUSE");
return 0;
} // end main
//*****************************************************
// CHECKING the validation of Birth Date
void check_birthdate(int month_birth , int day_birth , int year_birth)
{
// 1. while Month + Day is INVALID ..
while (( month_birth > 12)&&(day_birth > 30 ))
{
cout << "The Month & Day Entered are WRONG !! " << endl ;
cout << "Please Type your Birth_Date again ONLY Month & Day as (mm dd ) : " ;
cin >> day_birth >> month_birth ;
cout<<endl;
}
// 2. while Day is INVALID ..
while ( day_birth > 30)
{
cout << "The DAY Entered is WRONG !! " << endl ;
cout << "Please Type your Birth_date again ONLY the DAY : " ;
cin >> day_birth ;
cout<<endl;
}
// 3. while Month is INVALID ..
while ( month_birth > 12)
{
cout << "The Month Entered is WRONG !! " << endl ;
cout << "Please Type your Birth_Date again ONLY Month : " ;
cin >> month_birth ;
cout<<endl;
}
} // End of Birth date validation
//******************************************************
// CHECKING the validation of CURRENT Date
void check_currentdate(int day_date , int month_date , int year_date ,int day_birth ,int month_birth ,int year_birth )
{
// 1. while Month + Day is INVALID ..
while (( month_date > 12)&&(day_date > 30 ))
{
cout << "The Month and day Entered are WRONG !! " << endl ;
cout << "Please Type the CURRENT_Date again as (dd mm yyyy) : " ;
cin >> day_date >> month_date>> year_date ;
cout<<endl;
}
// 2. while Day is INVALID ..
while ( day_date > 30)
{
cout << "The DAY Entered is WRONG !! " << endl ;
cout << "Please Type CURRENT_date again as (mm dd yyyy) : " ;
cin >> month_date >> day_date >> year_date ;
cout<<endl;
}
// 3. while Month is INVALID ..
while ( month_date > 12)
{
cout << "The Month Entered is WRONG !! " << endl ;
cout << "Please Type the CURRENT_Date again as (mm dd yyyy) : " ;
cin >> month_date >> day_date >> year_date ;
cout<<endl;
}
// 4. while a confliction between BIRTH & CURRENT
while (( year_date <= year_birth) && ( month_date <= month_birth ) && ( day_date <= day_birth ))
{
cout << "The DATE Entered conflicts with the Birth_Date !! " << endl ;
cout << "Please Type the Date again as (mm dd yyyy) : " ;
cin >> month_date >> day_date >> year_date ;
cout<<endl;
}
} // End of CURRENT Date validation
//******************************************************
// Finding NEXT Date ..................
void nxt_date(int day_date,int month_date,int year_date)
{
if(day_date < 30 )
{
// nxt_day =day_date + 1 ;
cout << " NEXT Date is : " << day_date + 1 <<"/"<<month_date<<"/"<<year_date<<endl;
}
if(day_date == 30 )
{
// nxt_day = 1 ;
// nxt_month = month_date + 1 ;
cout << " NEXT Date is : " <<"1"<<"/"<< month_date+1 <<"/"<<year_date<<endl;
}
if(( day_date == 30 ) && (month_date == 12 ) )
{
// nxt_day = 1 ;
// nxt_month = 1 ;
// nxt_year = year_date+1 ;
cout << " NEXT Date is : " <<"1"<<"/"<<"1"<<"/"<<year_date+1 <<endl;
}
} // End next Date Function ...
//***********************************************************
|