Can somebody take a look the code. Please!!!!!!
//Schedule.cpp
#include <iostream>
#include "Schedule.h"
using namespace std;
Schedule::Schedule(int maxEntries)
{
m_maxEntries = 0;
m_actualEntryCount = 0;
m_entryArr = new Entry[1];
}
Schedule::~Schedule()
{
delete [] m_entryArr;
}
bool Schedule::addEntry(int hour,int minute, const char *todo)
{
if(m_maxEntries > 0)
{
m_actualEntryCount++;
return true;
}
else return false;
}
void Schedule::printSchedule()
{
this-> m_actualEntryCount;
}
//Schedule.h
#include <iostream>
#include <string>
using namespace std;
class Entry
{
private:
int m_hour;
int m_minute;
string m_todo;
public:
Entry()
{
m_hour = -1;
m_minute = -1;
m_todo = "N/A";
}
void setData(int hour, int munute, const char *td);
void setData(Entry &e);
void printEntry();
};
class Schedule
{
private:
Entry *m_entryArr;
int m_maxEntries;
int m_actualEntryCount;
public:
Schedule(int maxEntries);
Schedule::Schedule(Schedule &s)
{
m_actualEntryCount = s.m_actualEntryCount;
m_maxEntries= s.m_maxEntries;
m_entryArr = new Entry[m_maxEntries];
for(int i = 0; i<m_actualEntryCount; i++)
{
m_entryArr[i].setData(s.m_entryArr[i]);
}
}
~Schedule();
bool addEntry(int hour, int minute, const char *todo);
void printSchedule();
};
//main driver
#include"Schedule.h"
#include <iostream>
void mian()
{
Schedule s1(10);
s1.addEntry(1,20, "Feed Cat");
s1.addEntry(2,40, "Feed Dog");
s1.addEntry(2,50, "Walk Dog");
s1.addEntry(4,0, "Fix Dinner");
s1.addEntry(5,15, "Eat Dinner");
s1.printSchedule();
Schedule s2(s1);
cout <<endl <<"Output from s2" << endl;
s2.printSchedule();
}
Last edited on
Thank Scorpic. Here is my entire coide. I post it here because there are some fetal problem. If someone can help, I am sooooooooo appreciate!!
#include <iostream>
#include "Schedule.h"
using namespace std;
Schedule::Schedule(int)
{
m_maxEntries = 0;
m_actualEntryCount = 0;
m_entryArr = new Entry[3];
}
Schedule::~Schedule()
{
delete [] m_entryArr;
}
bool Schedule::addEntry(int hour,int minute, const char *td)
{
if(m_entryArr > 0)
{
m_actualEntryCount++;
return true;
}
else return false;
}
void Schedule::printSchedule()
{
this-> m_actualEntryCount;
}
#include <iostream>
#include <string>
using namespace std;
class Entry
{
private:
int m_hour;
int m_minute;
string m_todo;
public:
Entry()
{
m_hour = -1;
m_minute = -1;
m_todo = "N/A";
}
void setData(int hour, int munute, const char *td);
void setData(Entry &e);
void printEntry();
};
class Schedule
{
private:
Entry *m_entryArr;
int m_maxEntries;
int m_actualEntryCount;
public:
Schedule(int maxEntries);
Schedule::Schedule(Schedule &s)
{
m_actualEntryCount = s.m_actualEntryCount;
m_maxEntries= s.m_maxEntries;
m_entryArr = new Entry[m_maxEntries];
for(int i = 0; i<m_actualEntryCount; i++)
{
m_entryArr[i].setData(s.m_entryArr[i]);
}
}
~Schedule();
bool addEntry(int hour, int minute, const char *todo);
void printSchedule();
};
#include"Schedule.h"
#include <iostream>
void mian()
{
Schedule s1(10);
s1.addEntry(1,20, "Feed Cat");
s1.addEntry(2,40, "Feed Dog");
s1.addEntry(2,50, "Walk Dog");
s1.addEntry(4,0, "Fix Dinner");
s1.addEntry(5,15, "Eat Dinner");
s1.printSchedule();
Schedule s2(s1);
cout <<endl <<"Output from s2" << endl;
s2.printSchedule();
}