CSCI 136
Fundamentals of Computer Science II
Spring 2022

Montana Tech of The University of Montana
Computer Science & Software Engineering



Assignment 11

ASSIGNMENT 11

The goal of this assignment is to get experience working with C++ pointers and dynamic memory management. You will be writing a linked list, similar to what you have done before in Python, but this time you will be using pointers. Like last week's lab, I don't mind if you write your code on a local machine, but make sure the it runs on lumen because that is where we will test it.

Remember, to compile a C++ program on lumen use:

g++ MyProgram.cpp
Or, to create an executable file with a meaningful name, use::
g++ -o MyProgram MyProgram.cpp

Problem Description
For this assignment you are going to write a homework assignment manager. Name your program Homework.cpp. The program will have a text based user menu interface where the user can pick one of four options. This should be in a loop so that the user can continue working with the program until they choose option 4, Quit:

Enter the number for your choice:
  1. Enter a new assignment
  2. Delete an assignment
  3. Print out a list of assignments
  4. Quit

Assignment data will be stored in a struct data structure. You need to keep track of the name of an assignment, the month and day it is due (numeric), and the number of hours you estimate it will take to complete.

Your list of assignments are to be stored in a linked list. So in addition to the data elements in your struct, you should have a variable that stores a pointer to the next assignment. Assignments are to be stored in the list sorted by their due dates, with earlier due dates in front. Each time the user enters an assignment, the code needs to create a new structure to hold the data and then insert it into the list in the appropriate place.

When the user adds an assignment to the list, the program should query the user for all the information it needs: the name of the assignment, the month it is due, the day it is due, and the estimated hours to complete it. An example is shown below.

What is the name of this assignment? COMX 230 Presentation 5
  Due date information:
    What month is it due? 3
    What day is it due? 3
How many hours will it take you to complete? 1
When an assignment is deleted, you need to remove that element from the list and from memory. The user should specify which one to remove by the name of the assignment. If there are two assignments with the same name, remove the first one encountered in the list.

If the user chooses to print an assignment, all assignment still on the list should be printed to the screen. If the linked list insertion was done correctly, they should end up printing out in order of due date:

Due: 2/2       CSCI 136 Lab Asmt 1		3 hours
Due: 3/3       COMX 230 Presention 5		1 hour

Each of the tasks should be performed in their own function. That is, you should have at least three functions; one that adds an assignment, one that deletes an assignment, and one that prints all assignments. It is ok to add more functions if it makes your code better. The pointer to the head of the linked list should be passed as a parameter to each of the functions. Any function that modifes the list should return the pointer to the head of the list for the return value. You might find it helpful to define a function that tests whether one due date is earlier than another.

Caution: You will likely encounter the dreaded segmentation fault (that old seg fault you may have heard people talking about). This happens when your program compiles correctly but something goes badly wrong when you run it. The most likely reason this happens is that you have an unassigned pointer somewhere, or you are trying to use a null pointer. Unfortunately, C++ is not very descriptive about where this might have occurred. You just have to look through your pointers and try to isolate the fault. Using cout (print) statements can be very helpful here to see how far your program gets before it crashes.

Good luck! And have fun!!


Grading You will be graded according to the following criteria:

Grade ItemDistancePoints Earned
Program Compiles
2
Program Runs
2
Header Comment
2
Correct struct
4
Correct User Menu Input
4
Add Assignment Function
6
Delete Assignment Function
6
Print Assignment Function
2
Program Runs Correctly
(including correctly formatted output)
2
Total
30


Submission. Submit your program, Homework.cpp, via Moodle. Be sure your code has the required header with your name, and a description of the program. Use comments on all functions - this will be factored into your score! Also be sure to submit the .cpp source files and not the executable files! Note: in order to do this, you will likely need to use winscp to copy files from lumen to your local machine.

Page last updated: January 06, 2022



Page last updated: January 06, 2022