📄 http:^^www.cs.wisc.edu^~milo^cs302^program6.html
字号:
Date: Mon, 11 Nov 1996 17:12:54 GMTServer: NCSA/1.5Content-type: text/htmlLast-modified: Mon, 04 Nov 1996 18:34:52 GMTContent-length: 8486<HTML><HEAD><TITLE>Program 6 - CS 302 Fall 1996 - Section 4</TITLE></HEAD><BODY><H1 ALIGN=CENTER> <!WA0><!WA0><!WA0><!WA0><!WA0><!WA0><!WA0><!WA0><!WA0><A HREF="http://www.cs.wisc.edu/~cs302/">CS 302</A> Fall 1996 - <!WA1><!WA1><!WA1><!WA1><!WA1><!WA1><!WA1><!WA1><!WA1><A HREF="http://www.cs.wisc.edu/~milo/cs302.html">Section 4</A></H1> <H2 ALIGN=CENTER>Algebraic Language Programming in C++</H2><H4 ALIGN=CENTER>Instructor: <!WA2><!WA2><!WA2><!WA2><!WA2><!WA2><!WA2><!WA2><!WA2><A HREF="http://www.cs.wisc.edu/~milo">Milo M. Martin</A> (milo@cs.wisc.edu)</H4><hr><br><H1 ALIGN=CENTER>Program 6</H1><H3 ALIGN=CENTER>Due Friday, November 8, 1996</H3> <hr><br><b>Objective</B>: Give the student practice with classes and emumerations. <p><H3>Update - November 4, 1996</H3>You are required to use a project and separate compilation for thisproject. See the page <!WA3><!WA3><!WA3><!WA3><!WA3><!WA3><!WA3><!WA3><!WA3><A HREF="http://www.cs.wisc.edu/~milo/cs302/using_projects.html">UsingProjects</A> for the details.<p><H3>Program Description</H3><P>The phone service 1-800-DOCTORS has decided to expand their business.In addition to their usual service of finding doctors, they will now findpeople dentists and hair dressers as well, and even make the appointmentsfor them. They need to be able to save all of this information, though,and everyone is sick and tired of writing stuff down on paper and killingtrees. Obviously, the information needs to be stored in a computer.Believe it or not, this is where you come in. <p>You need to write a program that will fill up to three appointments at theusers request (doctor, dentist, hair). For each appointment it shouldfirst ask the user if they want to make that particular appointment. Ifthey do, you should then ask for the relevent time information (month,day, hour, minute). After all appointments have been made, you shouldprint out the user's appointments, with the time either in military orstandard format (you should ask which they want for each).<p><hr><p>A typical run of the program would look something like this:<br><br>Do you want to make a doctor's appointment?<br><b>Y</b><br>Enter the month (1-12): <b>1</b><br>Enter the day of the month (1-30): <b>15</b><br>Enter the hour (0-23): <b>18</b><br>Enter the minute (0-59): <b>0</b><br><br>Do you want to make a dental appointment?<br><b>N</b><br><br>Do you want to make a hair appointment?<br><b>Y</b><br>Enter the month (1-12): <b>3</b><br>Enter the day of the month (1-30): <b>13</b><br>Enter the hour (0-23): <b>13</b><br>Enter the minute (0-59): <b>13</b><br><br><br>Doctor's Appointment:<br>Military (M) or Standard (S) time?<br><b>S</b><br>The appointment is on Monday, January 15 at 6:00 PM.<br><br>Hair Appointment:<br>Military (M) or Standard (S) time?<br><b>M</b><br>The appointment is on Wednesday, March 13 at 13:13.<br><br><p><hr><p>There are lots of variables needed to store the information for anappointment. They are as follows:<br><UL><LI>the <b>month</b>: the month of the year (JAN, FEB, MAR, ..., DEC -- must be an enumerated type)<p><LI>the <b>day of month</b>: the day of the month (to make your life easier, all months of the year will have 30 days, so this should be an integer with legal values of 1-30)<p><LI>the <b>day of week</b>: the day of the week (MON, TUE, ..., SUN -- must be an enumerated type)<p><LI>the <b>hour of day</b>: the hour of the day (appointments are stored in military time, so this will be an integer between 0 and 23 where the 0th hour is between midnight and 1 AM)<p><LI>the <b>minute of hour</b>: the minute of the hour (this is an integer between 0 and 59 -- THIS CAN NOT BE 60!!!)<p><LI><b>filled</b>: whether or not the data for this appointment has been set (must be an enumerated boolean type, that is, an enumerated types with tags true and false)<p> <p></UL>There are six variables in all. Since we are storing three differentappointments, this would mean 18 variable declarations. Also, itwould be nice if we could have our own set of member functions justfor appointments and be able to protect the appointment data fromother parts of the program. The sane solution to these potentialproblems is to define and implement an Appointment class. We willthen not only get away with only three declarations of appointmentobjects, but will have a nicely modularized program. <p>As stated above, you should define an Appointment class. It must containthe six variables for storing the appointment information. It should alsocontain the following method functions:<UL><LI><b>Appointment</b> - public<UL><LI>this is the constructor<LI>it should initialize <b>filled</b> to false to indicate that the appointment has not been set yet </UL><p><LI><b>get_day</b> - private<UL><LI> this function will set the day of week variable based upon the current month and day of month <LI>you can assume that January 1 is a Monday and that all months have exactly 30 days<LI>since we are dealing with classes, this should not need to have any formal parameters and should not need to return anything</UL><p><LI><b>read_app</b> - public<UL><LI>this function will fill all of the necessary appointment information<LI>it should first prompt for and read from cin the <b>month</b>, <b>day of month</b>, <b>hour</b>, and <b>minute</b> and make sure that they all have legitimate values<LI>the hour should be read in military format<LI>the month should be read in as an int and then type cast to the month enumerated type<LI>it should then set the <b>day of week</b> (by calling <b>get day</b> -- thus, <b>read_app</b> should not prompt the user for the day of the week)<LI>it should then set filled to indicate that the appointment has been set</UL><p><LI><b>is_filled</b> - public<UL><LI>should return true if the current object's appointment has been set and false otherwise<LI>this function is necessary because the filled variable is private and can not be accessed by the caller</UL><p><LI><b>print_mil_time</b> - private<UL><LI>this function will print the time in military (24 hour) format<LI>this should not require any parameters and does not need to return anything</UL><p><LI><b>print_stan_time</b> - private<UL><LI>this function will print the time in standard (12 hour) format<LI>this should not require any parameters and does not need to return anything</UL><p><LI><b>write_app</b> - public<UL><LI>this function will write out to cout the appointment informationif the information has been filled in, if not a message should bedisplayed which says that no information has been entered yet.<LI>otherwise it should ask if the user wants the time printed in military or standard format and do appropriate error checking (you will probably want a function to do this)<LI>it should then print out the <b>day of week</b>, the <b>month</b>, the <b>day of month</b><LI>the <b>entire</b> name of the month should be written, not just the number<LI>it should then print the time in the format the user requests (by calling one of the two private time print functions)</UL><p></UL><br>Main should not be able to harm any of the class's data, so all variablesint the class must be made private. The constructor function, <b>Appointment</b> must be made public (this is a hard and fast rule ofconstructors). Also, the functions <b>read_app, write_app, </b> and<b>is_filled</b> are all called by main and should be made public. Noother functions are needed outside the class and the remainingfunctions must therefore remain private.<p>The main part should be relatively simple. The first thing you need to dois declare three objects of type appointment. For each appointment, youshould prompt if the user wants to fill that particular appointment (e.g.doctor's). If so, call <b>read_app</b> to fill the necessary information.After this is done for all three appointments, you should print out eachappointment that is set (this should be checked by calling <b>is_filled</b>) in a manner similar to the example.<H3>What To Turn In</H3> As usual, I only want an electronicsubmission, printed copy of your source code, and 2 or more test runswhich thoroughly tests your program's features and error checking.<H3>Suggestions/Final Notes</H3>Notice that in both main and within one of the class functions, we havethe need to read in a character for a yes/no type question and do errorchecking. This is something that should be done within a function. <P><p> <hr> <p>Written by Dave Zimmermann <I>(dzimm@cs.wisc.edu)</I></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -