Advanced Data Type "Age" ?

Hi guys,
Seriously, can someone show me how to do this?

Write a C++ program by using:
• Create a class Age, which has:
1. One attribute (DateOfBirth).
2. Default constructor.
3. Overloaded constructor

4. Function to set the radius.
5. Three accessor functions to get the (DateOfBirth, AgeInYears, AgeInMonths, AgeInWeeks, AgeInDays).
6. Function to display (DateOfBirth, AgeInYears, AgeInMonths, AgeInWeeks, AgeInDays).


I did this so far, but I am just overwhelmed with my own tryouts, how is it done?

Thanks!
Last edited on
What have you written so far? Make sure your code is [code]between code tags[/code] so that it has line numbers and syntax highlighting, as well as proper indentation.
It is only the int main that I am sure off, but not so sure about the "public" or the implementations.
I am not optimistic to share it, but if you insist:

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
#include<iostream>
using namespace std;

class age
{

private:
int day;
int month;
int year;

public:
age():day(1), month(1), year(1)
{}
void get()
{

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)
{

cout<<a1.day<<"-"<<a1.month<<"-"<<a1.year;
cout<<endl;
}

int main()
{
age a1;
a1.get();

return 0;
}
What's requirement 4 about? Since when do ages have radii?
I really do not know, that is what the professor asked for. but if it can be done without the radius, I would like to see how!
C++ doesn't currently have good facilities for working with dates. Writing your own date handling code is a very complex subject no matter which programming language you use. Since the goal of the assignment is to learn C++ and not date handling, don't stress yourself worrying about things like leap years and such - just use an existing library like Boost:
http://www.boost.org/doc/libs/1_59_0/doc/html/date_time.html
http://www.boost.org/doc/libs/1_59_0/doc/html/date_time/examples.html#date_time.examples.time_math

Learning to use existing libraries (like Boost) is an important part of learning C++.
Last edited on
I still don't find anything regarding my assignment, if you found any at boost.org could you provide me with the url, or just help me write the program?
You have already mostly written your program - do you have a specific question or some problem with it? I can only give general advice unless you have something specific.
As for the strange assignment requirements, just email your professor and ask them to clarify. Specifically, what does he want the overloaded operator to do? This will get you at least one of two answers: how you're supposed to write it, and how many parameters the overloaded constructor needs for its purpose.

You also might want to ask why your professor wanted a radius setter. It's their job to teach you, so even if they do it in a super roundabout manner, it's better than doing nothing and going "durr..pls help i dunno"

just help me write the program


No.
Yes LB, not asking for the full program lol.
But I would like to know how to write the overloading of the operation that takes the birthday and calculates the age in days.
no need for anything else, just how to implement the part where it calculates the idea that "if you are born in 12/13/1995 then your ageindays is something like 6334"
AmmmG 01 wrote:
no need for anything else, just how to implement the part where it calculates the idea that "if you are born in 12/13/1995 then your ageindays is something like 6334"
As I stated already, this is about date math and not about C++. There are all sorts of subtle nuances to dates, like leap years (which have more confusing rules than you would think) and the varying number of days in each month.

If you really want to go through the pain and effort of implementing date handling code yourself instead of just using Boost, let me know. But any good professor would be impressed if you used Boost instead.
Topic archived. No new replies allowed.