Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need help on the driver program!!! #ifndef SCHEDULE_H #define SCHEDULE_H #includ

ID: 658502 • Letter: N

Question

need help on the driver program!!!

#ifndef SCHEDULE_H

#define SCHEDULE_H

#include "appointment.h"

#include <iostream>

using std::ostream;

const int SCH_ENTRIES = 10;

class schedule {

   public:

      schedule( void); // Default Constructor

      schedule( const char * p); // title only

      schedule( const schedule &); // copy constructor

      bool addtoSchedule(const appointment &); // if full, return false

                               // otherwise place in the schedule and return true

      bool isFull(void) const; // true if no cells left, false otherwise

      void print(ostream &) const; // print all appointments

      void printForSource(long s, ostream &) const;

                                           // print only appointments that match that source

      appointment search( long s) const;

                   // will return a copy of the first appointment found that matches

                   // the source s, if no match, return an appointment with

                   // a source of -1 and a description of "Not Found";

      static void setDateFlag(int);

   private:

      char title[40]; // title of the schedule

      int count; // number of appointments currently in the schedule

      appointment appointmentArray[SCH_ENTRIES];

      static int dateFlag;

};

#endif

           // Driver program functions

bool keyBoardEnterAppointment( schedule & ); // return true if successful

                                                      // return false if full

bool addFutureAppointment( schedule &, const appointment & e, int d);

                       // return true if successful, false if full

                       // the appointment added has the same source and

                       // desc as the appointment e, but a date of d days later

bool addRecurringAppointment( schedule &, const appointment & e, int cycle, int times);

// return true if successful, false if full

// times will indicate the number of appointments to add

// each appointment added will have the same source and

// desc as the appointment e, but a date of cycle days later

                               // than the previous appointment added to the schedule

schedule::schedule( void)

{

count = 0;

strcpy(title, "");

  

  

}

schedule::schedule( const char * p)

{

// count = p;

// title = p;

strcpy(title, p);

count = 0;

cout << title << endl;

cout << count << endl;

cout << " ---- " << endl;

  

  

}

schedule::schedule( const schedule & other)

{

count = other.count;

strcpy(title, other.title);

}

bool schedule::addtoSchedule(const appointment & tempApoint)

{

if(this->isFull() ){

return false;}

  

else{

appointmentArray[count] = tempApoint;

count++;

  

return true;}

  

  

/*

if(this->count == tempApoint.count){

return *this ;}

else{

return tempApoint;

}*/

}

bool schedule::isFull(void) const

{

if(count == SCH_ENTRIES){

return true;}

else{

return false;}

}

void schedule::print(ostream & out) const

{

//print(out);

for( int i=0; i < count; i++)

appointmentArray[i].print(out, 1);

  

  

// out << ' ' <<apointmentArray[SCH_ENTRIES] << ' ' << dateFlag << endl;

}

void schedule::printForSource(long s, ostream & outs) const

{

// print(outs);

// addtoSchedule << " " << appointmentArray[] << ' ' << dateFlag << endl;

for(int i=0; i < count; i++)

{

if (appointmentArray[i].getSource() == s)

{

print(outs);

}

  

}

}

appointment schedule::search( long s) const

{

// appointment temp;

for (int i = 0; i < count; i++)

{

if (appointmentArray[i].getSource() == s)

{

   return appointment(appointmentArray[i]);

}

}

  

return appointment(-1, "Not found", 1,3,2015);

}

void schedule::setDateFlag(int temp)

{

temp = dateFlag;

}

bool keyBoardEnterAppointment( schedule & tempKey )

  

{

if(tempKey.isFull())

{

return false;

}

else{

appointment temp;

temp.keyBoardInput();

return tempKey.addtoSchedule(temp);

}

  

}

bool addFutureAppointment( schedule & s, const appointment & e, int d)

{

   // return true if successful, false if full

   // the appointment added has the same source and

   // desc as the appointment e, but a date of d days later

appointment temp(e);

  

if(s.isFull())

{

return false;

}

else{

for ( int i = 0; i < d; i++){

temp.incrementDate();

//s.add(temp);

   s.addtoSchedule(temp);}

  

return true;}

}

bool addRecurringAppointment( schedule & sch, const appointment & e, int cycle, int times)

{

// return true if successful, false if full

// times will indicate the number of appointments to add

// each appointment added will have the same source and

// desc as the appointment e, but a date of cycle days later

// than the previous appointment added to the schedule

appointment temp(e);

  

if(sch.isFull())

{

return false;

  

}

else{

  

  

for (int j=1; j<= times; j++) {

addFutureAppointment(sch, temp, j*cycle);

}

return true;}

}

//appointment.h

#ifndef APPOINTMENT_H

#define APPOINTMENT_H

#include <fstream>

using std::ostream;

#include<iostream>

#include <cstring> // Needed for string functions

using namespace std;

// The Designer decides upon the following data and actions (i.e. Functions)

// and places the class in the file appointment.h

class appointment {

   public:

           appointment(void); // default constructor

           appointment(long, const char [],int d,

                   int m, int y); // 5 argument constructor

           appointment(const appointment &); // copy constructor

           void keyBoardInput(void); // Assume no blanks in the desc

           long getSource(void) const; // return source

           void setSource(long); // change source

           void setMonth(int);

           void setDay(int);

           void setYear(int);

           int getMonth(void) const;

           int getDay(void) const;

           int getYear(void) const;

           const char * getDescription(void) const; // return the address of the description

           void changeDescription(const char *) ; // change an existing description

           void copyTo( appointment & ) const; // copy invoking instance to parameter

           void incrementDate(void); // advance the date by ONE day

                                                      // You can assume 30 days in each month

           void print(ostream &, int dateFormat) const; // print all fields

                       // dateFormat == 1 month/day/year

                       // dateFormat == 2 day/month/year

           ~appointment(); // destructor - indicate the address

                                           // of the variable that is leaving

// **********************************************************************

  

// The implementer will write all of the member functions

// and place these functions in a separate file "appointment.cpp"

  

  

// *********************************************************************

  

  

// The Client, i.e. User, will create the file drhw3.cpp

// and prototype, write, and use the following 3 functions

  

appointment makeAppointment(long, const char [], int d, int m, int y);

  

long getSource(const appointment &); // will return the source in the parameter

  

  

// The following function will return an appointment with the same source and desc

// as the parameter appointment. The day, month, and year will reflect numberOfDays

// into the future.

appointment advanceDate( const appointment &, int numberOfDays);

  

   private:

           void setDescription(const char *); // used to allocated memory

           // data

           long source; // id of the person scheduling the appointment

           char * desc; // description of the appointment - Dynamic Data

           int day; // day, month, and year when the appointment

           int month; // will happen

           int year;

   };

#endif


//apointment.cpp

#include "appointment.h"

using namespace std;

#include<iostream>

appointment makeAppointment(long s, const char n[], int d, int m, int y)

{

return appointment(s, n, d, m, y);

}

long getSource(const appointment & e) // will return the source in the parameter

{

return e.getSource();

}

appointment advanceDate( const appointment & e, int numberOfDays)

{

appointment nextAppointment(e);

for(int i=0; i < numberOfDays; i++)

{

nextAppointment.incrementDate();

}

return nextAppointment;

}

// **********************************************************************

appointment::appointment(void)

{

   setSource(0);

   setDescription("No desciption");

   setDay(1);

   setMonth(1);

   setYear(2000);

  

}

appointment::~appointment()

{

   delete [] desc;

}

appointment::appointment(long pSource, const char pDesc [],int d,int m, int y)

{

   setSource(pSource);

   setDescription(pDesc);

   setDay(d);

   setMonth(m);

   setYear(y);

}

appointment::appointment(const appointment & other)

{

   setSource(other.getSource());

   setDescription(other.getDescription());

   setDay(other.getDay());

   setMonth(other.getMonth());

   setYear(other.getYear());

}

void appointment::keyBoardInput(void)

{

long input;

cout<< "Input scheduler's ID: ";

cin >>input;

setSource(input);

cout << "Input description (no spaces ): ";

char descInput[80];

cin >> descInput;

changeDescription(descInput);

cout<< "Input Day: " ;

cin >>input;

setMonth(input);

cout << "Input Year: ";

cin >>input;

setYear(input);

  

}

long appointment::getSource(void) const

{

   return source;

}

void appointment::setSource(long pSource)

{

   source = pSource;

}

void appointment::setMonth(int pMonth)

{

   month = pMonth;

}

void appointment::setDay(int pDay)

{

day = pDay;

}

void appointment::setYear(int pYear)

{

year = pYear;

}

int appointment::getMonth(void) const

{

   return month;

}

int appointment::getDay(void) const

{

   return day;

}

int appointment::getYear(void) const

{

   return year;

}

const char * appointment::getDescription(void) const

{

   return desc;

}

void appointment::changeDescription(const char * description)

{

   delete [] desc;

   setDescription(description);

}

void appointment::copyTo( appointment & other) const

{

   other.setSource(getSource());

   other.changeDescription(getDescription());

   other.setDay(getDay());

   other.setYear(getYear());

   other.setMonth(getMonth());

}

void appointment::incrementDate(void)

{

   setDay(getDay() + 1 ) ;

   if(getDay() > 30 )

   {

   setDay(1);

   setMonth(getMonth() +1);

   }

   if(getMonth() > 12)

   {

   setMonth(1);

   setYear(getYear() +1);

   }

}

                                                     

void appointment::print(ostream & out, int dateFormat) const

{

out << " Source: " << getSource() << endl;

out << " Description: " << getDescription() << endl;

switch (dateFormat)

{

  

case 1: out << getMonth() << "/ " << getDay() << "/" << getYear() << endl; break;

case 2: out <<getDay() << "/ " << getMonth() << "/" << getYear() << endl; break;

default: out << "Invalid format :(" ;

  

}

}

void appointment::setDescription(const char * description)

{

   desc = new char[strlen(description) + 1 ];

   strcpy(desc, description);

}

             

int main) char title [40]; couttitle; schedule s(title); schedule sltutlel: appointment a; bool added = s.addtoSchedule (a); if (added-true) { keyBoardEnterAppointment(s) return

Explanation / Answer

Appointment.cpp

#include "appointment.h"

#include <iostream>

using std::cin;

using std::cout;

appointment::appointment(): source(), desc(), day(), month(), year()

{

    cout << "default appt ";

}

appointment::appointment(long lSource, const char cDescription[], int d, int m, int y)

    : source(lSource), desc(), day(d), month(m), year(y)

{

    setDescription(cDescription);

}

appointment::appointment(const appointment & aToCopy)

    : source(aToCopy.getSource())

    , desc()

    , day(aToCopy.getDay())

    , month(aToCopy.getMonth())

    , year(aToCopy.getYear())

{

    setDescription(aToCopy.getDescription());

}

void appointment::setDescription(const char * cSource)

{

    if (desc != NULL) free (desc);

    if (cSource == NULL)

        return;

    desc = (char *)malloc (strlen (cSource) + 1);

    strcpy(desc, cSource);

}

long appointment::getSource(void) const

{

     return source;

}

void appointment::setSource(long lSource)

{

     source = lSource;

}

void appointment::setMonth(int iMonth)

{

     month = iMonth;

}

void appointment::setDay(int iDay)

{

     day = iDay;

}

void appointment::setYear(int iYear)

{

     year = iYear;

}

int appointment::getMonth(void) const

{

     return month;

}

int appointment::getDay(void)   const

{

     return day;

}

int appointment::getYear(void) const

{

     return year;

}

//return the address of the description

const char * appointment::getDescription(void) const

{

     return desc;

}

//change an existing description

void appointment::changeDescription(const char * cDescription)

{

    setDescription(cDescription);

}

void appointment::copyTo(appointment &p) const

{

    p.source = source;

    p.day = day;

    p.month = month;

    p.year = year;

    p.setDescription(desc);

}

void appointment::incrementDate(void)

{

    int days;

    switch (month)

    {

        case 1: // Jan: 31 Days

        case 3: // Mar: 31 Days

        case 5: // May: 31 Days

        case 7: // Jul: 31 Days

        case 10: // Oct: 31 Days

        case 12: // Dec: 31 Days

            days = 31;

            break;

        case 4: // Apr: 30

        case 6: // Jun: 30

        case 8: // Aug: 30

        case 9: // Sep: 30

        case 11: // Nov: 30

            days = 30;

            break;

        case 2: // Feb: 28/29 Days (Depends on year modulus 4 a modulus 100).

            days = !(year % 4) || !(year % 100) ? 29 : 28;

            break;

  }

    day++;

    if (day > days)

    {

        month++;

        day = 1;

        if (month > 12)

        {

            month = 1;

            year++;

        }

    }

}

void appointment::printS(ostream &out, int dateFormat) const

{

    if (dateFormat == 1)

    {

        out << month << "/" << day << "/" << year << " ";

    }

    else if (dateFormat == 2)

    {

        out << day << "/" << month << "/" << year << " ";

    }

    else

        out << "Unsupported dateFormat parameter specified (should be 1 or 2).";

}

appointment::~appointment()

{

    if (desc != NULL)

    {

        free (desc);

        desc = NULL;

    }

}

void appointment::keyBoardInput()

{

    char temp[1024];

    cout << "Please type the description: ";

    cin.getline (temp, sizeof(temp) - 1, ' ');

    cout << std::endl;

    setDescription(temp);

}