EECS 280 Lab 04: Abstract Data Types

Lab Due Sunday, 17 Feb 2019, 8pm

In this lab, you will review Abstract Data Types (ADTs) by implementing both C-style structs and C++ classes. Additionally, you’ll learn about the debugging process, which will help you debug your future projects. Finally, we’ve prepared an Exam Prep that reviews similar topics.

You may work alone or with a partner. Please see the syllabus for partnership rules.

Submit the code files below on the autograder. We encourage you to complete the lab Exam Prep, but it is not turned in for credit.

Files to submit

Completion Criteria/Checklist:

To pass this lab, you must finish tasks 1 through 3.

Lab Exercises

The Files

We have provided starter files for this lab. Use the following commands in a terminal at your working directory to download the files.

$ wget
$ tar -xvzf starter-files.tar.gz

Here’s a summary of this lab’s files. You will turn in the bolded ones.

File Description
lab04.h Declarations of the C-style and C++ ADTs.
lab04.cpp Implementations of the C-style and C++ ADTs.
main.cpp Contains the main function that runs testing code.
spellcheck.cpp A version of the spell-checker program from a previous lab that contains a number of bugs.
words.txt A list of all properly spelled words, one word per line.

The main function

The main function in main.cpp is initially empty, but throughout the lab tasks you will add code to use your ADTs and produce output. Visually inspect this output to check that your code is working correctly. The autograder will also verify that main produces the correct output.

The starter code should “work” out of the box, so make sure you are able to compile and run it with the following commands. The code may be missing some pieces, contain some bugs, or crash when you run it, but you’ll fix each throughout the course of the lab.

$ g++ -Wall -Werror -g -pedantic --std=c++11 lab04.cpp main.cpp -o lab04.exe
$ ./lab04.exe


In this lab, we will develop both C-Style and C++ style ADTs for employees at a company, as well as a C++ style ADT for a company itself, which has several employees. Finally, we’ll use the ADTs in a main function to represent employees at a newly-founded software development company, called eecsSoft!

Task 1 - C-Style EmployeeRecord Struct

Implement the EmployeeRecord ADT

For a C-style ADT, we first create a struct that groups the data into member variables. Then, we implement functions that take a pointer to the struct, which will define the actions related to this data. Take a look inside lab04.h to see the EmployeeRecord ADT and then implement the functions inside of lab04.cpp according to their RMEs.

Use EmployeeRecord in main.cpp

Add code to main.cpp to do the following:

Task 2 - C++ Employee and Company Classes

For a C++ ADT, we use classes, which consist of both data and functions. Classes have many benefits over C-style structs. They enforce an interface that prevents access to private member variables. They also guarantee that the object starts in a valid state by enforcing the use of constructors.

Implement the Employee ADT

Take a look inside lab04.h to see the Employee ADT. Implementations for its member functions go in lab04.cpp. Some are already provided for you. Implement the rest in lab04.cpp according to their RMEs.

(Note: We have not provided stubs for the Employee functions you must implement, so that you can practice writing out the full definition of a member function. Remember to use the :: operator!)

Read, Understand, and Complete the Company ADT

You will also find the definition for the Company ADT in lab04.h. Read the documentation for the ADT in the comments and RMEs. Most of the implementation is provided for you in lab04.cpp, but you will need to fill in the definitions of the promote_employee and demote_employee member functions. Make sure to use find_employee in your solutions for both.

Being the Boss at eecsSoft

We will now use the Employee and Company ADTs in main.cpp.

First, create a Company named "eecsSoft". Next, we need some employees. Since this is a live demo of our ADTs, you should use realistic names, genders, and ages. Use ranks between 1 and 9, inclusive. (A larger number denotes a higher rank.)

Specifically, add code to main.cpp do the following:

However, it turns out some of our employees are performing above expectations, while other are slacking. Therefore, additionally write code in main.cpp to:

Note: When adding, promoting, and demoting employees, you must use the public member functions of the Company class.

Task 3 - Debugging Tutorial

We’ve written a version of the spell-checker program from the previous lab that contains some bugs, together with a tutorial that will show the debugging mentality in action using the visual debugger you set up in Lab 01. You will find it at the link above.

Note: This is a required part of the lab, and you must submit spellcheck.cpp to receive credit.


Submit the required files to the autograder.