// Use the following .H file and driver function prototypes // Write all class f
ID: 655842 • Letter: #
Question
// Use the following .H file and driver function prototypes
// Write all class functions
// Write all driver functions
// Create a driver program to test all functions
// schedule header file
#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;
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;
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);
// out << ' ' <<apointmentArray[SCH_ENTRIES] << ' ' << dateFlag << endl;
}
void schedule::printForSource(long s, ostream & outs) const
{
print(outs);
addtoSchedule << " " << appointmentArray[] << ' ' << dateFlag << endl;
}
appointment schedule::search( long s) const
{
for (int i = 0; i < count; i++)
{
if (appointmentArray[i].getSource() == s)
{
return new appointment(appointmentArray[i]);
}
}
}
void schedule::setDateFlag(int temp)
{
temp = dateFlag;
}
bool keyBoardEnterAppointment( schedule & tempKey )
{
if(isFull())
{
return false;
}
else{
appointment temp;
temp.keyboardInput();
return tempKey.addtoSchedule();
}
}
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;
if(isFull())
{
return false;}
esle{
return true;}
s.
}
bool addRecurringAppointment( schedule & temp, 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
}
int main()
{
appointment a1, a2, a3;
return 0;
}
#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
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;
};
// **********************************************************************
// 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);
// **********************************************************************
// main driver program
int main()
{
// The client will test the 3 function above along with all
// of the member functions
appointment a1(0, "AI 12:30pm ", 10, 10, 2011);
a1.print(cout, 1);
appointment a2(a1);
a2.changeDescription("c++ 3:00pm");
a2.print(cout, 2);
appointment a3;
a3.print(cout, 1);
a3.keyBoardInput();
a3.print(cout, 1);
//test set function
a3.setSource(5001);
a3.changeDescription("Animation 9:00am");
a3.setDay(1);
a3.setMonth(1);
a3.setYear(1991);
//test get functions
cout << "Source" << getSource(a3) << endl;
cout << "Description "<< a3.getDescription() << endl;
cout << a3.getMonth() << "/" << a3.getDay() << "/" << a3.getYear() << endl;
a3.copyTo(a1);
a1.print(cout, 1);
//test date adavance
appointment a4 = advanceDate(a2, 75);
a4.print(cout, 1);
return 0;
}
// Client places the code for makeappointment, getSource and advanceDate here
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);
}
Explanation / Answer
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;
if(isFull())
{
return false;}
esle{ //syntax error 'esle' should be else
return true;}
s. //no method should be called here using object s because this line will not be executed at all because return statement is already placed above
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.