EECS268:Lab2
Navigation |
---|
Home |
Information |
Classwork |
Contents
Due time
This lab is due Friday June 19th by 11:59pm
Lab conduct
- Do not use any unauthorized aid, such sites like rentacoder or chegg to obtain answers
- Do not use code provided by another student
- Do not reuse code (by you or anyone) from prior semesters
- If you need help, seek it from:
- Your lab TA.
- Me, Dr. Gibbons, my email is jwgibbo@ku.edu / jwgibbo@gmail.com
- If equipment you don't own (e.g. cycle servers) needs attention or you're having account issues put in a ticket!
Program Overview
Elevator Action!
You are being placed in charge of running an elevator in an office building. People enter your building on the ground floor to wait in line for the elevator.
Ground floor Rules:
- The first person in line will be the first to get on the elevator.
- There is no cap on how many people can be waiting for the elevator
Elevator Rules:
- The first person to get into the elevator will be last one off
You will read in from file what is happening to the elevator. You can assume the file will be well formatted, but you may not assume that the commands will be given in a logical order or have safe values. For example, the command "DROP_OFF 10" could be in the file when no one is in the elevator. When problems like this arise, you must handle the thrown exception! Do not simply disallow such actions to occur; you need to get practice catching and handling exceptions.
Commands from file:
Command | Description |
---|---|
WAIT <name> |
|
PICK_UP <num> |
|
DROP_OFF <num> |
|
INSPECTION |
Elevator status: The elevator is not empty. Mark will be the next person to leave the elevator. Stacy will be the next person to get on the elevator. |
Note, there is no exit command. You'll have to read until you reach the end of file.
Here's one way of reading until you reach the end of file:
while (inFileObject >> someVar) { //you just successfully read something into someVar //so you can proceed or perhaps even continue reading into other variables }
Example File
WAIT Bart WAIT Homer WAIT Marge WAIT Lisa WAIT Maggie WAIT Fred INSPECTION WAIT Wilma WAIT Betty WAIT Barney WAIT George WAIT Jane PICK_UP 7 INSPECTION DROP_OFF 3 PICK_UP 4 INSPECTION
File overview:
- Six people get in line for the elevator
- Inspection occurs. The following is printed:
Elevator status: The elevator is empty. No one is in the elevator. Bart will be the next person to get on the elevator.
- Five more people get in line for the elevator
- The elevator is filled
- Inspection occurs. The following is printed:
Elevator status: The elevator is not empty. Wilma will be the next person to leave the elevator. Betty will be the next person to get on the elevator.
- Three are dropped off
- The elevator filled
- Inspection occurs. The following is printed:
Elevator status: The elevator is not empty. Jane will be the next person to leave the elevator. No one is in line for the elevator
We will test your code with files that will cause exceptions.
Example:
WAIT Kirk WAIT Spock DROP_OFF 15
Notable departures from reality:
- Once people have been dropped off by the elevator, they cannot get back on the elevator (in other words you don't have keep track of all people in the building)
- We don't care what floor the elevator is going to
Stack and Queue classes
- We'll use the Stack and Queue classes we've been building in lecture
- DO NOT USE ANY PREBUILT OR STANDARD LIBRARY DATA STRUCTURES (e.g. vectors, stack, queue)
- You must build your own Stack and Queue classes
- Put the precondition, postcondition, return, and throws comments in this class also
- Stack/Queue will have standard destructors, copy constructors, and assignment operator overload
- Remember that some of your Stack/Queue methods will need thrown exception (refer to lecture for details)
Messages when exceptions are thrown
Any method that throws an exception needs to provide a meaningful message to the point in code doing the exception handling. For example:
- "Pop attempted on an empty stack"
- "Peek attempted on an empty stack"
Handling exceptions
Here is some sample code to handle an exception that is thrown.
try
{
something that could throw a std::runtime_error
}
catch(std::runtime_error& rte)
{
std::cout << rte.what(); //print what happened
}
Before Friday (June 12th) is over
Goals:
- Create a list of classes you'll need and what responsibilities each will have
- Create and complile a templated Node class and declare one in main
- Begin implementing your templated Stack and Queue classes
- Use the debugger to verify that your methods are being implemented correctly!
Rubric
- 60pts Main program
- [20pts] Stack and Queue implementation
- [10pts] All exceptions are handled
- [30pts] General functionality of the program matches requirements
- 20pts Modularity
- Code is well designed with a logical separation of responsibilities among classes
- 10pts Memory Management:
- There should be no memory leaks and a equal number of allocations and deallocations. Use valgrind ./YourProgramName to verify
- Any memory leaks or unequal number of allocations to deallocations (barring the bug mentioned in previous labs) will result in a loss of all 10 points
- 10pts Documentation
- Comments: Pre conditions, Post conditions, Return descriptions in header files. Not require for hpp/cpp files
- Formatting: Rational use of white space and indentation. Header and implementation files easily readable
Emailing Your Submission
Once you have created the tarball with your submission files, email it to your TA. The email subject line must look like "[EECS 268] SubmissionName":
- [EECS 268] Lab 0#
Note that the subject should be exactly like the line above. Do not leave out any of the spaces, or the bracket characters ("[" and "]"). In the body of your email, include your name and student ID.