An Event Class with Time and Date objects

Need help getting rit of 14 errors and a little other take a look at m

Page 1 of 1

2 Replies - 2870 Views - Last Post: 01 February 2010 - 02:32 PM Rate Topic: -----

#1 cali420  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-February 10

An Event Class with Time and Date objects

Posted 01 February 2010 - 02:00 PM

#include "stdafx.h"
#include "Date.h"
#include "Time.h"
#include <iostream>
#include <string>


int main()
{
time myTime;
cout << "Default time: ";
myTime.printTime();
myTime.setTime(11,10);
cout << "Time set to 11:10 -->";
myTime.printTime();

myTime.incrementHrs();
myTime.incrementMin();
cout << "After incrementing hours and minutes: ";
myTime.printTime();

system("pause");
return 0;
}

EVENT

#include "stdafx.h"
//#include "Event.h"
//#include <iostream>
//#include <string>
using namespace std;

Event::Event(void)
{
string eventName = "Default Event";
int hour = 0;
int minute = 0;
int day = 1;
int month = 1;
int year = 1900;
};

Event::~Event(void)
{


}

Event::Event(std::string eventName){


}
Event::setEventDate(std::string eventName, int hour, int minute, int month, int day, int year){
eventName = name;
eventTime.setTime(hr, min);
eventDate.setDate(mon, day, yr);

}
Event::eventTime{
hour();
minute();
}

void Event::printEventData() {
cout << eventName << "occurs";
eventDate.printDate();
cout <<"at";
eventTime.printTime();

//cout << eventDay << day << "" <<endl;
//cout << eventTime << endl;}


EVENT

#pragma once
#ifndef H_Event
#define H_Event
#include "time.h"
#include "date.h"
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

class Event
{
public:
Event(void);
~Event(void);
void setEventDate(string EventName, int hour, int minute, int month, int day, int year);
void printEventData();
void printEvent();
Event(string eventName = "Generic Event",int hour = 0,int minute = 0,int month = 1,int day = 1,int year = 2000);//constructor
//Event();




private:
string eventName;
Time eventTime;//the event object is composed of a time object
Date eventDate;//and date object
};
#endif

TIME

#include "Stdafx.h"
#include "time.h"

time::time(int hr, int min)
{
hour = hr;
minute = min;
};
time::time(){
hour = 0;
minute = 0;
};

time::~time(void)
{
//hour(0);
//minute(0);
}
void time::setTime(int h, int m){
hour = h;
minute = m;
}
void time::getTime(int& hr, int& min){
hr = hour;
min = minute;
}
void time::printTime(){
cout << hour << ":";
if (minute < 10)
{
cout << 0;
}
cout << minute << endl;
}
void time::incrementHrs(){
//ToDo: Complete the logic here!
hour = hour++ % 24;
}
void time::incrementMin(){
//ToDo: Complete the logic here!
minute = minute++ % 60;
}


TIME

#pragma once
#ifndef H_Time
#define H_Time
#include "stdafx.h"
#include <iostream>
using namespace std;

class time
{
//this is a simple time class to demonstrate
//the use of object within another (compostion)
public:
void time::setTime(int , int);
void time::getTime(int&, int&);
void time::printTime();
void time::incrementHrs();
void time::incrementMin();
time(int, int);//constructor with parameters
time();//the default constructor
~time();

private:
int hour;
int minute;
};
#endif

DATE

#include "stdafx.h"
#include "Date.h"
#include <iostream>
using namespace std;

Date::Date(void){
};

Date::Date(int month = 1, int day = 1, int year = 2000){

}
//Date::Date(int m, int d, int yr) {
/*m = month;
d = day;
yr = year;*/
//}

void Date::getDate(int m, int d, int yr){
m = month;
d = day;
yr = year;
};

Date::setDate(int m,int d,int yr){
m = month;
d = day;
yr = year;
};

Date::printDate(){
cout << month << " ," << day << " ," << year << endl;
}


DATE

#pragma once

class Date
{
public:
Date(void);
Date(int month, int day, int year);
~Date(void);
void Date::setDate(int = 1, int = 1, int = 2000);
void Date::getDate(int m, int d, int y);
void Date::printDate();


private:
int month;
int day;
int year;
};

Is This A Good Question/Topic? 0
  • +

Replies To: An Event Class with Time and Date objects

#2 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 967
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: An Event Class with Time and Date objects

Posted 01 February 2010 - 02:03 PM

Damn use code tags next time please, and post the exact error messages that you are getting ...
From far as I could see, you don't know how to declare member functions:
void time::setTime(int , int);
void time::getTime(int&, int&);
void time::printTime();
void time::incrementHrs();
void time::incrementMin();


Should be:
void setTime(int, int);
// etc, just get rid of time::


There is the same error in your Date class too. Event class seems to be fine lol

This post has been edited by sarmanu: 01 February 2010 - 02:05 PM

Was This Post Helpful? 0
  • +
  • -

#3 cali420  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-February 10

Re: An Event Class with Time and Date objects

Posted 01 February 2010 - 02:32 PM

These are my errors Got it down to 11

1. error c4430: missing type specfier- int assumed. Note: C++ does not support default-int
2. error C2556: 'int Date::setDate(int,int,int)': overloaded function differs only by return type from 'void Date::setDate(int,int,int)'
3. error C2371: 'Date::setDate' : redefinition, different basic types
4. error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
5. error C2556: 'int Date::printDate(void)' : overloaded function differs only by return type from 'void Date::printDate(void)'
6. error C2371: 'Date::printDate' : redefinition; dufferent basic types
7. error C2653: 'Event' : is not a class or namespace name
8. error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
9. warning C4508: 'Event' : function should return a value; 'void' return type assumed
10. error C2653: 'Event' : is not a class or namespace name
11. fatal error C1903: unable to recover from previous error(s); stopping compilation
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1