Programming help

DarkKnight

Golden Member
Apr 21, 2001
1,197
0
0
here is an rar with my code

for my compsci class I'm working on inheritence and in this probject there is a Base class Event whose derived classes are TimedEvent and TeamEvent. My problem is when it outputs a timeevent or teamevent to the ostream, it only outputs the Event info and not the TimeEvent or TeamEvent information, even though the writeout function (output function) is virtual. Can someone with programming experience plz look over my code to see whats wrong?
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Originally posted by: jman19
Originally posted by: notfred
I'm not going to buy winrar to help you with your homework.

Isn't there an evaluation version you can use?

Yes, however, the point is to make it easy for people to assist OP.

A facility exists for the code to be made visible.

If the amount of code is too large, then the OP should trim it down to the problem area.

 

DarkKnight

Golden Member
Apr 21, 2001
1,197
0
0
sry, here it is.

Event.h
---------

#ifndef EVENT_H
#define EVENT_H

#include "NameList.h"
#include <iostream>
#include <string>

class Event
{
friend std::istream&amp; operator>>(std::istream&amp; is, Event&amp; target);
friend std::eek:stream&amp; operator<<(std::eek:stream&amp; os, const Event&amp; scr);

public:
Event(std::string title_in = "NONE", int year_in = 0,
std::string venue_in = "NONE", int start_in = 0,
int duration_in = 0, NameList partlist_in = NameList());
virtual ~Event();

// This function is NOT virtual (the description is wrong)
// Do NOT change this function's prototype:
std::string classType() const;

virtual Event* duplicate() const;

std::string getKey() const;
std::string getTitle() const;
int getYear() const;
std::string getVenue() const;
int getStartDay() const;
int getDuration() const;
NameList getParticipants() const;

bool operator==(const Event&amp; rhs) const;
bool operator!=(const Event&amp; rhs) const;
bool operator<(const Event&amp; rhs) const;
bool operator>(const Event&amp; rhs) const;
bool operator<=(const Event&amp; rhs) const;
bool operator>=(const Event&amp; rhs) const;

protected:
std::string type;

// moved here - see FAQ
virtual std::istream&amp; readin(std::istream&amp; input);
virtual std::eek:stream&amp; writeout(std::eek:stream&amp; output) const;

private:
std::string title;
int year;
std::string venue;
int start_day;
int duration;
NameList participants;
};

#endif


Event.cpp
-------------
#include <iostream>
#include "Event.h"

using namespace std;

//default constructor
Event::Event(string title_in, int year_in,
string venue_in, int start_in,
int duration_in, NameList partlist_in)
{
title = title_in;
year = year_in;
venue = venue_in;
start_day = start_in;
duration = duration_in;
participants = partlist_in;
type = "Event";
}

//Event destructor
Event::~Event()
{

}

//gets title
string Event::getKey() const
{
return title;
}

//returns the title
string Event::getTitle() const
{
return title;
}

//returns year
int Event::getYear() const
{
return year;
}

//returns the venue
string Event::getVenue() const
{
return venue;
}

//returns when the event starts
int Event::getStartDay() const
{
return start_day;
}

//returns duration of event
int Event::getDuration() const
{
return duration;
}

//returns the NameList, or paticipants in the event
NameList Event::getParticipants() const
{
return participants;
}

//overload == operator
bool Event::eek:perator==(const Event&amp; rhs) const
{
return (title == rhs.title);
}

//overload != operator
bool Event::eek:perator!=(const Event&amp; rhs) const
{
return (title != rhs.title);
}

//overload < operator
bool Event::eek:perator<(const Event&amp; rhs) const
{
return (title < rhs.title);
}

//overload > operator
bool Event::eek:perator>(const Event&amp; rhs) const
{
return (title > rhs.title);
}

//overload <= operator
bool Event::eek:perator<=(const Event&amp; rhs) const
{
return (title <= rhs.title);
}

//overload >= operator
bool Event::eek:perator>=(const Event&amp; rhs) const
{
return (title >= rhs.title);
}

//read Event information through input stream
istream&amp; Event::readin(istream&amp; input)
{
input >> title;
input >> year;
input >> venue;
input >> start_day;
input >> duration;
input >> participants;

return input;
}

//outputs Event information in output stream
ostream&amp; Event::writeout(ostream&amp; output) const
{
output <<"EVENT WRITEOUT" << endl;
output << "Title: " << title << ", Year: "<< year << ", Venue: " <<
venue << ", Start Day: " << start_day << ", Duration: "
<< duration << endl;
output << "Participants: " << endl << participants;

return output;
}

//read Event information through input stream
istream&amp; operator>>(std::istream&amp; is, Event&amp; target)
{
target.readin(is);
return is;
}


//outputs Event information in output stream
ostream&amp; operator<<(ostream&amp; os, const Event&amp; scr)
{
scr.writeout(os);

return os;
}

Event* Event::Duplicate() const
{
Event *newEvent;

newEvent = new Event;
*newEvent = *this;

return newEvent;
}

string Event::classType() const
{
return type;
}

TeamEvent.h
---------------
#ifndef TEAMEVENT_H
#define TEAMEVENT_H

#include <iostream>
#include <string>
#include "Event.h"

using namespace std;

class TeamEvent:public Event
{
public:
TeamEvent(string title_in = "NONE", int year_in = 0,
string venue_in = "NONE", int start_in = 0,
int duration_in = 0, NameList partlist_in = NameList(),
bool exhibit_in = false, int numTeams_in = 0,
string teams_in[] = NULL);
// NOTE: "teams_in" is an array which would have a COPY of the
// list of initial teams the event should have - the size
// of the array will be at least the value of "numTeams_in"
// The array "teams_in" might NOT be in sorted order.

string classType() const;

TeamEvent* duplicate() const;
bool getExhibition() const;
int getNumTeams() const;
string* getTeams() const;


private:
bool exhibition;
int numTeams;
string *teams;

istream&amp; readin(istream&amp; input);
ostream&amp; writeout(ostream&amp; output) const;
};

#endif

TeamEvent.cpp
------------------

#include <iostream>
#include <string>
#include "TeamEvent.h"

TeamEvent::TeamEvent(string title_in, int year_in,
string venue_in, int start_in,
int duration_in, NameList partlist_in,
bool exhibit_in, int numTeams_in,
string teams_in[]):Event(title_in,year_in, venue_in, start_in,
duration_in, partlist_in)
{
type = "TeamEvent";
exhibition = exhibit_in;
numTeams = numTeams_in;
teams = new string[numTeams];
for (int i =0; i < numTeams; i++)
teams [ i ] = teams_in [ i ];
}

string TeamEvent::classType() const
{
return type;
}

bool TeamEvent::getExhibition() const
{
return exhibition;
}

int TeamEvent::getNumTeams() const
{
return numTeams;
}

string* TeamEvent::getTeams() const
{
return teams;
}

TeamEvent* TeamEvent::Duplicate() const
{
TeamEvent *newEvent;

newEvent = new TeamEvent;
*newEvent = *this;

return newEvent;
}

istream&amp; TeamEvent::readin(istream&amp; input)
{
Event::readin(input);
string exhib;
input >> exhib;
if (exhib == "EXHIBIT")
exhibition = true;
else
exhibition = false;
input >> numTeams;
teams = new string[numTeams];
for (int i =0; i < numTeams; i++)
input >> teams[ i ];
return input;
}

ostream&amp; TeamEvent::writeout(ostream&amp; output) const
{
output <<"TEAMEVENT WRITEOUT" << endl;
Event::writeout(output);
if (exhibition)
output<<"Exhibition: Yes" << endl;
else
output <<"Exhibition: No" << endl;
output <<"Teams:" << endl;
if (numTeams > 0)
for (int i= 0; i < numTeams; i++)
output << teams << endl;
else
output <<"none" << endl;
return output;
}


TimedEvent and TeamEvent are also the same and both show the same problem, so i didnt include it
The outputing of TeamEvent and TimedEvent are called in BST.cpp in the print functions

BST.cpp
----------
//this function prints out the elements of the binary search tree in
//lexicographical order
template <class BSTData, class BSTDataKey>
void BST<BSTData, BSTDataKey>::printForward(ostream &amp;output,
string option) const
{
output <<"**************** Printing Forward ****************";
printInOrder(root, output, option);
output <<"************** End Printing Forward **************"<<endl;
}

//this function prints out the elements of the binary search tree in
//reverse lexicographical order
template <class BSTData, class BSTDataKey>
void BST<BSTData, BSTDataKey>::printBackward(ostream &amp;output,
string option) const
{
output <<"**************** Printing Backward ****************";
printInReverse(root, output, option);
output <<"************** End Printing Backward **************"<<endl;
}

//prints out the elements of the Binary search tree in alphabetical order
template <class BSTData, class BSTDataKey>
void BST<BSTData, BSTDataKey>::printInOrder(BSTNode<BSTData> *root,
ostream &amp;output, string option) const
{
if (root->left != NULL)
printInOrder (root->left, output, option);
if (root != NULL &amp;&amp; (option == "All" || option==root->data->classType()))
{
output << endl<<root->data->classType();
output << endl<<*root->data;
}
if (root->right != NULL)
printInOrder(root->right, output, option);
}

//prints out the elements of the Binary search tree in reverse alphabetical
//order
template <class BSTData, class BSTDataKey>
void BST<BSTData, BSTDataKey>::printInReverse(BSTNode<BSTData> *root,
ostream &amp;output, string option) const
{
if (root->right != NULL)
printInReverse (root->right, output, option);
if (root != NULL &amp;&amp; (option == "All"||option == root->data->classType()))
{
output << endl<<root->data->classType();
output << endl <<*(root->data);
}
if (root->left != NULL)
printInReverse(root->left, output, option);
}
 

jman19

Lifer
Nov 3, 2000
11,225
664
126
Originally posted by: EagleKeeper
Originally posted by: jman19
Originally posted by: notfred
I'm not going to buy winrar to help you with your homework.

Isn't there an evaluation version you can use?

Yes, however, the point is to make it easy for people to assist OP.

A facility exists for the code to be made visible.

If the amount of code is too large, then the OP should trim it down to the problem area.

Oh, yeah, I agree with you completely... I wasn't trying to say that notfred should have to deal with the burden of downloading a prog to help someone else with their hw, but rather just to point out that you don't have to pay for WinRAR.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Originally posted by: jman19
Originally posted by: EagleKeeper
Originally posted by: jman19
Originally posted by: notfred
I'm not going to buy winrar to help you with your homework.

Isn't there an evaluation version you can use?

Yes, however, the point is to make it easy for people to assist OP.

A facility exists for the code to be made visible.

If the amount of code is too large, then the OP should trim it down to the problem area.

Oh, yeah, I agree with you completely... I wasn't trying to say that notfred should have to deal with the burden of downloading a prog to help someone else with their hw, but rather just to point out that you don't have to pay for WinRAR.
And that is the reason for the first word of my response.

;)