Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,376 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,162 people online right now. Registration is fast and FREE... Join Now!




Class and ctime - assignment

 
Reply to this topicStart new topic

Class and ctime - assignment

beberenne
post 23 Oct, 2006 - 07:02 AM
Post #1


New D.I.C Head

*
Joined: 23 Oct, 2006
Posts: 6


My Contributions


Hi guys. Have have this assignment which consists of 7 questions.I manage to finish 6 but i'm stuck on this. I hope you guys would help me out by pointing out what i should do first in this programming. You help is required but i wish to do the code on my own effort. So, i need help and guidelines. I'mstuck because i'm not familiar with ctime.h and with those member functions. Here's the question which i'm stuck.
-------------------------------------------------------------------
Create a Date class with the following capabilities:
a) Output the date in multiple formats such as
June 14, 1992
cool.gif Use overloaded constructors to create Date objects initialized with dates of the formats in part (a).
c) Create a Date constructor that reads the system date using the standard library functions of the <ctime> header and sets the Date members.

Your Date.h file – class definition, should contain the following codes

// Date2.H
#ifndef Date2_H
#define Date2_H
#include <ctime>
#include <cstring>
class Date {
public:
Date();
Date( char *, int, int );
void setMonth( int );
void setDay( int );
void setYear( int );
void printDateMonth( void ) const;
const char *monthName( void ) const;
bool leapYear( void ) const;
int daysOfMonth( void ) const;
void convert( const char * const );
const char *monthList( int ) const;
int days( int ) const;
private:
int day;
int month;
int year;
};
#endif

Your program should give the following input and output.

July 4, 1998
March 27, 1999
July 26, 2000
September 1, 1998
------------------------------------------------------------------

another question regarding this question.
just for example, can this code be used with the header file given? and are those commands allowed? any feedback would be most helpful.
------------------------------------------------------------------

using std::endl;

#include "Date2.h"

Date::Date( char *year, int month, int day )
{
}


void Date::setMonth(int mn)
{
if (mn > 0 && mn <=12){
month = mn;
}
else {
month = 1;
cout<<"Invalid month"<<"\n"<<endl;
}
}

void Date::setDay(int dy)
{

if(mn = 1 || mn = 3 || mn = 5 || mn = 7 || mn = 8 || mn = 10 || mn = 12)
{
if (dy > 0 && dy <=31){
day = dy;
}

}

if(mn = 4 || mn = 6|| mn = 9 || mn = 11)
{
if (dy > 0 && dy <=30){
day = dy;
}
}

}
User is offlineProfile CardPM

Go to the top of the page

gregoryH
post 24 Oct, 2006 - 01:34 AM
Post #2


D.I.C Regular

Group Icon
Joined: 4 Oct, 2006
Posts: 417



Dream Kudos: 50
My Contributions


QUOTE(beberenne @ 23 Oct, 2006 - 08:02 AM) *

Hi guys. Have have this assignment which consists of 7 questions.I manage to finish 6 but i'm stuck on this. I hope you guys would help me out by pointing out what i should do first in this programming. You help is required but i wish to do the code on my own effort. So, i need help and guidelines. I'mstuck because i'm not familiar with ctime.h and with those member functions. Here's the question which i'm stuck.
-------------------------------------------------------------------
Create a Date class with the following capabilities:
a) Output the date in multiple formats such as
June 14, 1992
cool.gif Use overloaded constructors to create Date objects initialized with dates of the formats in part (a).
c) Create a Date constructor that reads the system date using the standard library functions of the <ctime> header and sets the Date members.

Your Date.h file – class definition, should contain the following codes


Did it ever occur to you that you can read ctime.h for your self?

Its usually in the compilers "Include" Folder (or subfolder)
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 06:11AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month