In: Computer Science
Given a file of birthdays in the format YYYY-MM-DDTHH:mm:ss:sss.
Using C++ write a program to find the:
Age and bday of the oldest individuals in the file.
Age and bday of the youngest individual in the file.
Standard deviation of the ages with respect to 3/29/2019.
Average age with respect to 3/29/2019.
#include<iostream.h>
using namespace std;
class age
{
private:
int day;
int month;
int year;
public:
age():day(1), month(1), year(1)
{}
void get()
{
cout<<endl;
cout<<"enter the day(dd):";
cin>>day;
cout<<"enter the month(mm):";
cin>>month;
cout<<"enter the year(yyyy):";
cin>>year;
cout<<endl;
}
void print(age a1, age a2)
{
if(a1.day>a2.day &&
a1.month>a2.month)
{
cout<<"your age is
DD-MM-YYYY"<<endl;
cout<<"\t\t"<<a1.day-a2.day<<"-"<<a1.month-a2.month<<"-"<<a1.year-a2.year;
cout<<endl<<endl;
}
else if(a1.day<a2.day &&
a1.month>a2.month)
{
cout<<"your age is
DD-MM-YYYY"<<endl;
cout<<"\t\t"<<(a1.day+30)-a2.day<<"-"<<(a1.month-1)-a2.month<<"-"<<a1.year-a2.year;?
cout<<endl<<endl;
}
else if(a1.day>a2.day &&
a1.month<a2.month)
{
cout<<"your age is
DD-MM-YYYY"<<endl;
cout<<"\t\t"<<a1.day-a2.day<<"-"<<(a1.month+12)-a2.month<<"-"<<(a1.year-1)-a2.year;
cout<<endl<<endl;
}
else if(a1.day<a2.day &&
a1.month<a2.month)
{
cout<<"your age is
DD-MM-YYYY"<<endl;
cout<<"\t\t"<<(a1.day+30)-a2.day<<"-"<<(a1.month+11)-a2.month<<"-"<<(a1.year-1)-a2.year;
cout<<endl<<endl;
}
else if(a1.year<a2.year)
{
cout<<"you entered wrong date. plz enter the correct
date."<<endl;
}
}
};
int main()
{
age a1, a2, a3;
cout<<"\t enter the current date.";
cout<<endl<<endl;
a1.get();
cout<<"\t enter your DOB.";
cout<<endl<<endl;
a2.get();
a3.print(a1,a2);
return 0;
}
this is the way to get the age and eldest person bday in simple way, keep this method and find youngest (first sort the ages and take the first person as youngest , using of class is very usefull . so every person will be a class ,easy to access. Better code this in python3.6 or 3.7.
so easy access of file from library os, starting of the code write import os
before using os, in command prompt type pip3 install os ,so it get download to your pc.