I have spent a lot of time on this

Ok, I tried a few different things and i'm returning different errors now. Here is the code:
#include <iostream>
#include <string>
using namespace std;

class Time
{
public:

void setHour(int);
void setMinute(int);
int getHour();
int getMinute();
void printTime();
Time(); //default constructor
Time (int, int); //constructor with parameters

private:

int hour;
int minute;
};

Time::Time() //default constructor sets the hour and minute to 0
{
hour = 0;
minute = 0;
}

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

void Time::setHour(int hr)
{
if(0 <= hr && hr < 24)
hr = hour;
else
hour = 0;
}

void Time::setMinute(int min)
{
if(0 <= min && min < 60)
min = minute;
else
minute = 0;
}

int Time::getHour()
{
return hour;
}

int Time::getMinute()
{
return minute;
}

void Time::printTime()
{
cout << getHour() << ":" << getMinute();
}

class Date
{
public:
void setMonth(int);
void setDay(int);
void setYear(int);
int getMonth();
int getDay();
int getYear();
void printDate();
Date(); //default constructor
Date(int, int, int); //constructor with parameters

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

Date::Date()
{
month = 1;
day = 01;
year = 2000;
}

Date::Date(int mmm, int dd, int yyyy)
{
mmm = month;
dd = day;
yyyy = year;
}

void Date::setMonth(int mmm)
{
if(1 <= mmm && mmm <= 12)
mmm = month;
else
month = 1;
}

void Date::setDay(int dd)
{
if(1 <= dd && dd <= 31)
dd = day;
else
day = 1;
}
void Date::setYear(int yyyy)
{
if(0 <= yyyy && yyyy <= 2500)
yyyy = year;
else
year = 0;
}

int Date::getDay()
{
return day;
}
int Date::getMonth()
{
return month;
}
int Date::getYear()
{
return year;
}
void Date::printDate()
{
cout << getMonth() << "/" << getDay() << "/" << getYear();
}

class Event
{
public:
Event(); //default constructor
Event(string, int, int, int, int, int); //constructor with parameters
string getName();
void printName();
void printDate();
void printTime();
private:
string eventName;
Time eventTime; //event object composed of a time object
Date eventDate; //event object composed of a date object
};
Event::Event()
{
}
Event::Event(string eDate, int eHour, int eMinute, int eMonth, int eDay, int eYear)
{
eventTime.setHour(eHour);
eventTime.setMinute(eMinute);
eventDate.setMonth(eMonth);
eventDate.setDay(eDay);
eventDate.setYear(eYear);
}
string Event::getName()
{
return eventName;
}
void Event::printName()
{
eventName;
}
void Event::printDate()
{
eventDate.getMonth() << "/" << eventDate.getDay() << "/" << eventDate.getYear();
}
void Event::printTime()
{
eventTime.getHour() << ":" << eventTime.getMinute();
}


int main()
{
Event eventOne ("New Year's Day", 00, 01, 01, 01, 2010);
eventOne.printName() << " occurs on " << eventOne.printDate() << " at " << eventOne.printTime() << "." << endl;
Event eventTwo ("Valentine's Day", 12, 15, 02, 14, 2010);
eventTwo.printName() << " occurs on " << eventTwo.printDate() << " at " << eventTwo.printTime() << "." << endl;
cout << endl;


return 0;
}

error C2297: '<<' : illegal, right operand has type 'const char [2]'
error C2297: '<<' : illegal, right operand has type 'const char [2]'
warning C4552: '<<' : operator has no effect; expected operator with side-effect
error C2297: '<<' : illegal, right operand has type 'const char [2]'
warning C4552: '<<' : operator has no effect; expected operator with side-effect
error C2296: '<<' : illegal, left operand has type 'void'
error C2297: '<<' : illegal, right operand has type 'const char [12]'
error C2296: '<<' : illegal, left operand has type 'void'
error C2297: '<<' : illegal, right operand has type 'const char [12]'

As you can tell, I am completely new at this and I feel like I am botching up this assignment. Any help would be great.
[code] "Your code goes here" [/code]

The insertion/extraction operators (<<, >>) are used with streams (cin, cout, files, string-streams).
The way you are using it eventOne.printName() << " occurs on " So Event::printName must return a valid type, but void Event::printName().
This repeat in several functions.

Also
1
2
3
4
void Event::printTime()
{
eventTime.getHour() << ":" << eventTime.getMinute();
} 
That is bad programming. You already have an Time::printTime method, use it. Try to rewrite your code without getters (and maybe private setters).
Last edited on
Topic archived. No new replies allowed.