I need with my homework in C++. Can someone help me with weekly. cpp? Here is th
ID: 3909213 • Letter: I
Question
I need with my homework in C++. Can someone help me with weekly.cpp?
Here is the test.cpp file which is the main:
// test the appointment class
#include "weekly.h"
#include
#include
int main()
{
bool success;
appt a1(1, 1000, "laundry", false);
appt a2(1, 1300, "homework assignment", false);
appt a3(2, 900, "mow lawn", false);
appt a4(2, 1500, "clean room", false);
appt a5(3, 1230, "lunch with friends", false);
appt a6;
appt* a7;
appt a8(1, 1730, "dentist", false);
weekly w;
a6.set_day(3);
a6.set_time(1800);
a6.set_task("tennis lesson");
std::cout << "Testing the weekly class" << std::endl << std::endl;
std::cout << "Several things will be scheduled, and then displayed." << std::endl << std::endl;
success = w.schedule(a1);
if(!success){ std::cout << "There was a problem scheduling that." << std::endl; }
success = w.schedule(a2);
if(!success){ std::cout << "There was a problem scheduling that." << std::endl; }
success = w.schedule(a3);
if(!success){ std::cout << "There was a problem scheduling that." << std::endl; }
success = w.schedule(a4);
if(!success){ std::cout << "There was a problem scheduling that." << std::endl; }
success = w.schedule(a5);
if(!success){ std::cout << "There was a problem scheduling that." << std::endl; }
success = w.schedule(a6);
if(!success){ std::cout << "There was a problem scheduling that." << std::endl; }
a7 = w.lookup(1, 1000);
std::cout << "The task for Monday at 10:00 is: " << a7->get_task() << std::endl;
w.show_times(1, 1100, 1700);
w.show_times(2, 800, 1800);
w.show_times(3, 0, 2345);
std::cout << "Removing a task from Wednesday and re-printing:" << std::endl;
w.unschedule(a5);
w.show_times(3, 0, 2345);
std::cout << "Clearing the schedule and re-printing." << std::endl;
w.clear();
w.show_times(3, 0, 2345);
system("pause");
return 0;
}
Here is the weekly.cpp:
#include "weekly.h"
// implementation of the weekly class
weekly::weekly()
{
}
weekly::~weekly()
{
}
// takes an appointment object and puts it in the schedule, returning true on success
bool weekly::schedule(appt a)
{
return true;
}
// returns a pointer to an appointment object at the day and time
appt* weekly::lookup(int day, int hour)
{
appt a;
return &a;
}
// removes an appointment at the given day and time in appointment a returns true on success
bool weekly::unschedule(appt a)
{
return true;
}
// shows all the appointments on the given day between the given times
void weekly::show_times(int day, int start, int end)
{
}
// clears the entire schedule, returning true on success
bool weekly::clear()
{
return true;
}
Here is a sample output (The appt.cpp is included but dont need help for that in this question)
Testing the weekly class Several things will be scheduled, and then displayed. The task for Monday at 10:00 is: laundry These are the requested appointments: Day: Monday Time: 1300 Task: homework assignment Not Finished These are the requested appointments: Day Tuesday Time: 900 Task mow lawn Not Finished Day Tuesday Time 1500 Task clean room Not Finished These are the requested appointments: Day Wednesday Time: 1230 Task lunch with friends Not Finished Day Wednesday Time: 1800 Task tennis lesson Not Finished Removing a task from Wednesday and re-printing: These are the requested appointments: Day Wednesday Time 1800 Task: tennis lesson Not Finished Clearing the schedule and re-printing. These are the requested appointments: ~/workspace/week/ $Explanation / Answer
#include "weekly.h"
weekly::weekly(){
appointments = new appt[100];
max = 100;
size = 0;
}
weekly::~weekly(){
delete [] appointments;
}
bool weekly::schedule(appt a){
if (size < 100) {
apt1 *temp = new appt[2*max];
for (int i = 0; i<size; i++){
temp[i].set_day(appointments[i].get_day());
temp[i].set_time(appointments[i].get_time());
temp[i].set_task(appointments[i].get_task());
temp[i].set_status(appointments[i].get_status());
}
appointments = temp;
delete [] appointments;
}
apt[size].set_day(a.get_day());
apt[size].set_time(a.get_time());
apt[size].set_task(a.get_task());
apt[size].set_status(a.get_status());
size++;
return true;
}
appt* weekly::lookup(int day, int hour){
appt *a = NULL;
for (int i = 0; i<size; i++){
if (appointments[i].get_day() == day && appointments[i].get_hour() == hour){
a->set_day(appointments[i].get_day());
a->set_time(appointments[i].get_time());
a->set_task(appointments[i].get_task());
a->set_status(appointments[i].get_status());
}
}
return a;
}
bool weekly::unschedule(appt a){
for (int i = 0; i<size; i++){
if (appointments[i].day == day && appointments[i].hour == hour){
for (int j = i+1; j<size; j++){
appointments[j-1].set_day(appointments[j].get_day());
appointments[j-1].set_time(appointments[j].get_time());
appointments[j-1].set_task(appointments[j].get_task());
appointments[j-1].set_status(appointments[j].get_status());
}
return true;
}
}
return false;
}
void weekly::show_times(int day, int start, int end){
string d;
switch (day) {
case 1 : d = "Monday";
break;
case 2 : d = "Tuesday";
break;
case 3 : d = "Wednesday";
break;
case 4 : d = "Thursday";
break;
case 5 : d = "Friday";
break;
case 6 : d = "Saturday";
break;
case 7 : d = "Sunday";
break;
};
cout << "These are the requested appointments:" << endl;
for (int i = 0; i<size; i++){
if (appointments[i].get_day() == day && appointments[i].get_time() >= hour && appointments[i].get_time() <= end){
cout << "Day: " << d << endl;
cout << "Time: "appointments[i].get_time();
cout << "Task: " << appointments[i].get_task();
cout << "Status: " << appointments[i].get_status();
}
}
}
void weekly::clear(){
size = 0;
return true;
}