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

I need with my homework in C++. Can someone help me with appt.cpp? Here is the t

ID: 3909202 • Letter: I

Question

I need with my homework in C++. Can someone help me with appt.cpp?

Here is the test.cpp file which is the main:

// test the appointment class

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

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 appt.cpp

#include "appt.h"

appt::appt(int d,int h,std::string item,bool done)

{

}

appt::~appt()

{

}

void appt::set_day(int d)

{

}

void appt::set_time(int h)

{

}

void appt::set_task(std::string item)

{

}

void appt::set_is_done(bool done)

{

}

int appt::get_day()

{

return 0;

}

int appt::get_time()

{

return 0;

}

std::string appt::get_task()

{

return (std::string)"";

}

bool appt::get_is_done()

{

return true;

}

void appt::clear()

{

}

void appt::show_appt()

{

}

Here is a sample output (The weekly.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

// File Name: Appointment.h
#ifndef _APPOINTMENT_H
#define _APPOINTMENT_H
#include <iostream>
#include <string>
using namespace std;

// Class Appointment definition
class Appointment
{
public:
// Prototype of member functions
Appointment(int ,int ,std::string ,bool);
Appointment();
void set_day(int);
void set_time(int);
void set_task(std::string);
void set_is_done(bool);
int get_day();
int get_time();
string get_task();
bool get_is_done();
void show_appt();
private:
// Data member to store appointment information
int day;
int time;
string task;
bool done;
};
#endif // End defined _APPOINTMENT_H

-----------------------------------------------------------------------------------------------------------

#include "Appointment.h"
#include <iostream>
#include <string>
using namespace std;

// Default constructor definition to assign default values to data members
Appointment::Appointment()
{
day = 0;
time = 0;
task = "No Task";
done = false;
}// End of default constructor

// Parameterized constructor to assign parameter values to data members
Appointment::Appointment(int d,int h,std::string item,bool done)
{
day = d;
time = h;
task = item;
this -> done = done;
}// End of parameterized constructor

// Function to set day
void Appointment::set_day(int d)
{
day = d;
}// End of function

// Function to set time
void Appointment::set_time(int h)
{
time = h;
}// End of function

// Function to set task
void Appointment::set_task(std::string item)
{
task = item;
}// End of function

// Function to set done status
void Appointment::set_is_done(bool done)
{
this -> done = done;
}// End of function

// Function to return day
int Appointment::get_day()
{
return day;
}// End of function

// Function to return time
int Appointment::get_time()
{
return time;
}// End of function

// Function to return task
std::string Appointment::get_task()
{
return (task);
}// End of function

// Function to return done status
bool Appointment::get_is_done()
{
return done;
}// End of function

// Function to print appointment information
void Appointment::show_appt()
{
cout<<" Day: ";
// Checks the day number and prints the string form of day
switch(day)
{
case 1:
cout<<" Monday.";
break;
case 2:
cout<<" Tuesday.";
break;
case 3:
cout<<" Wednesday.";
break;
case 4:
cout<<" Thursday.";
break;
case 5:
cout<<" Friday.";
break;
case 6:
cout<<" Saturday.";
break;
case 7:
cout<<" Sunday.";
}// End of switch - case
cout<<" Time: "<<time;
cout<<" Task: "<<task;
// Checks if done is true
if(done)
cout<<" Finished.";
// Otherwise false
else
cout<<" Not Finished.";
}// End of function

----------------------------------------------------------------------------------------------------------

// File Name: WeeklyAppointment.h
#ifndef _WEEKLYAPPOINTMENT_H
#define _WEEKLYAPPOINTMENT_H
#include "Appointment.h"

// Class weekly definition
class weekly
{
public:
// Prototype of member functions
weekly();
bool schedule(Appointment a1);
Appointment *lookup(int, int);
void clear();
void show_times(int, int, int);
void unschedule(Appointment);
private:
// Data member to store weekly appointment
Appointment *app;
static int count;
};// End of class
// Initializes counter to zero
int weekly::count = 0;

#endif // End defined _WEEKLYAPPOINTMENT_H

------------------------------------------------------------------------------------------------------

// File Name: WeeklyAppointment.cpp
#include "Appointment.cpp"
#include "WeeklyAppointment.h"
#include <iostream>
#define MAX 10
using namespace std;

// Default constructor to allocate memory to appointment array of pointers
weekly::weekly()
{
// Dynamically allocates of size MAX to array of pointers
app = new Appointment[MAX];
}// End of default constructor

// Function to schedule an appointment to week
bool weekly::schedule(Appointment a1)
{
// Checks if count is equals to MAX return false
// Cannot schedule
if(count == MAX)
return false;
// Adds the appointment object to counter index position of the array of pointer app
app[count] = a1;
// Increase the counter by one
count++;
// Returns true for success
return true;
}// End of function

// Function to return an appointment object based on given day and time as parameter
Appointment *weekly::lookup(int d, int t)
{
// Declares an appointment object
Appointment a;
// Declares an appointment pointer points to appointment object object
Appointment *ap = &a;
// Loops till number of appointments
for(int x = 0; x < count; x++)
{
// Checks if current appointment day and time is equals to given day and time (d, t) as parameter
if(app[x].get_day() == d && app[x].get_time() == t)
// Assigns the object to ap
ap = &app[x];
}// End of for loop
// Returns the object
return ap;
}// End of function

// Function to clear all the appointments
void weekly::clear()
{
// Loops till number of appointments
for(int x = 0; x < count; x++)
{
// Resets all the data members to null using setter method
app[x].set_day(0);
app[x].set_time(0);
app[x].set_task("");
app[x].set_is_done(false);
}// End of for loop
// Reset the counter to zero
count = 0;
}// End of function

// Function to show appointment based on day
void weekly::show_times(int d, int t1, int t2)
{
// Loops till number of appointments
for(int x = 0; x < count; x++)
{
// Checks if the current appointment day is equals to the day (d) given as parameter
if(app[x].get_day() == d)
// Calls the function to display the appointment
app[x].show_appt();
}// End of for loop
cout<<endl;
}// End of function

// Function to delete an appointment passed as parameter
void weekly::unschedule(Appointment a5)
{
int pos;
// Loops till number of appointments
for(int x = 0; x < count; x++)
// Checks if the current appointment day is equals to parameter object day
if(app[x].get_day() == a5.get_day())
// Stores the position
pos = x;
// Loops from the position till number of appointments
for(int x = pos; x < count; x++)
// Shifts each one position left
app[x] = app[x+1];
// Decrease the counter by one
count--;
}// End of function

---------------------------------------------------------------------------------------------------

// File Name: AppointmentTest.h

// Test the appointment class
#include "WeeklyAppointment.cpp"
#include <iostream>
#include <string>

// main function definition
int main()
{
// To store schedule() function return status
bool success;

// Creates appointment object using parameterized constructor
Appointment a1(1, 1000, "laundry", false);
Appointment a2(1, 1300, "homework assignment", false);
Appointment a3(2, 900, "mow lawn", false);
Appointment a4(2, 1500, "clean room", false);
Appointment a5(3, 1230, "lunch with friends", false);
Appointment a6;
Appointment* a7;
Appointment a8(1, 1730, "dentist", false);

// Declares a weekly object
weekly w;
// Sets the day, time, and task using setter function
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;

// Calls the function to schedule
success = w.schedule(a1);
// Checks if not success (false)
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;
}

// Calls the function to search an appointment based no day and time
a7 = w.lookup(1, 1000);
std::cout << "The task for Monday at 10:00 is: " << a7->get_task() << std::endl;

// Calls the function to display the appointment
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;
// Calls the function to delete a5 appointment object
w.unschedule(a5);

w.show_times(3, 0, 2345);


std::cout << "Clearing the schedule and re-printing." << std::endl;
// Calls the function clear all the appointments
w.clear();

w.show_times(3, 0, 2345);

return 0;
}// End of main function

Sample Output:

Testing the weekly class

Several things will be scheduled, and then displayed.

The task for Monday at 10:00 is: laundry

Day: Monday.
Time: 1000
Task: laundry
Not Finished.
Day: Monday.
Time: 1300
Task: homework assignment
Not Finished.

Day: Tuesday.
Time: 900
Task: mow lawn
Not Finished.
Day: Tuesday.
Time: 1500
Task: clean room
Not Finished.

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:

Day: Wednesday.
Time: 1230
Task: lunch with friends
Not Finished.
Clearing the schedule and re-printing.