Write a pseudo code function in terms of the ADT appointment book, described in
ID: 3875381 • Letter: W
Question
Write a pseudo code function in terms of the ADT appointment book, described in Section1.4.1, for each of the following tasks. Do you need to add operations to the ADT to perform these tasks?a. Change the purpose of the appointment at a given date and time.b. Display all the appointments for a given date.
Example:
bstraction: The Walls how to accomplish th ointment book apptBook. The following pseudocode indicates ng the previous ADT operations: Get the folowing data from the user: oldDate oldrine, newDate, newTime / Get purpose of appointment oldPurpose apptBook.getAppointment Purpose(oldDate, oldTime) if (oldPurpose is not the empty string) Change the date or time of an appointment 1 See whether a new date/time is available if (apptBook.isAppointment (nenDate, newTime)) New date/time is booked write("You already have an appointment at ", newTime, "on ", newDate) else / New datertime is available; cancel old uppointment; make new one. apptBook.cancelAppointment (oldDate, oldTime) if (apptBook.nakeAppointnent (newDate, newTime, oldPurpose)) writeC"Your appointnent has been rescheduled to". newTime, " on", newDate) else write("You do not have an appointment at ", oldTime, on, oldDate) Again n ADT is implemented. The exercise can perform with this ADT ce that you can design applications that use ADT operations without s at the end of this chapter provide examples of 1.4.2 ADTs That Suggest Other ADTExplanation / Answer
As per your requirement the below one is solution please follow it
//QuestionA Change purpose of an appointment
Get the following data from the user: appointmentDate, appointmentTime, newPurpose
//Get existing purpose of the appointment
oldPurpose=apptBook.getAppointmentPurpose(appointmentDate,appointmentTime)
if(oldPurpose is not an empty string) //if appointment exists the purpose won't be empty
{
if(oldPurpose is equal to newPurpose) //if existing purpose of appointment is same as the new one, there's no need to update it
write("This purpose is already on the appointment. No need to change.")
else
{ //to update the purpose of an existing appointment, first cancel the existing appointment
apptBook.cancelAppointment(appointmentDate,appointmentTime)
if(apptBook.makeAppointment(appointmentDate,appointmentTime,newPurpose)) //and make a new appointment with exactly the same dat & time but new purpose.
write("Purpose of the appointment on ",appointmentDate," at ",appointmentTime," updated to ",newPurpose)
}
}
else //if oldPurpose is empty, there was no appointment at the specified time on the specified date
write("You do not have an appointment on ",appointmentDate," at ",appointmentTime)
We don't need to add any operations for this as we can use the exsiting ones, getAppointmentPurpose, cancelAppointment and makeAppointment to accomplish this task.
//QuestionB- Display all appointments for a given date
Get the following data from the user: Date
initialize startTime to 8 a.m. //all appointments are made between 8 a.m. & 5 p.m.
while startTime < 5 p.m.
{
purpose=apptBook.getAppointmentPurpose(Date,startTime)
if purpose is not an empty string //if appointment exists at this time, display its details
write("Appointment Time : ", startTime," Appointment Purpose: ",purpose)
increment startTime by an hour and a half //because appointments are only made on the hour and half hour
}
We did not need to add an operation for this task as well because the getAppointmentPurpose operation was sufficient for completing it.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.