CSCI 136
Fundamentals of Computer Science II
Spring 2018

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



Assignment 14

ASSIGNMENT 14

The goal of this assignment is to get experience working with multi-file programs and file input/output.You will be using the linked list you wrote for Lab 12 to track homework assignments as a base for this assignment. (If you didn't complete that asignment, one solution is available here. If you use this solution, be sure to add your name as another auther.) As with all these labs, I want you to do all of your work on katie so that you get practice using Linux and command line compilation.


Problem Description
Recall that for Lab 12 you wrote a homework assignment manager, but anything you entered disappeared as soon as you exited the program. That is not very useful.

This week I want you to change that program in two ways:

1. Separate declarations from definitions by using a header file. The struct you defined for your assignment along with any function declarations should go in the header file. You should also put all the included library statements in this header file. Don't forget to use the #ifndef, #define and #endif preprocessor directives so that the header file won't be included multiple times at some future point. In your .cpp code, you will need to add, for example, #include "Homework.h". Hint: Do this part first and test that your program still works correctly before going on to the second part.

2. Add two new functions to your code - one to read a text file as the program starts, and one to write to a text file when the user exits the program. Your program should ask the user for the name of the file. That file will be used for both input to the program and output from the program. Hint 1: I would write the writeFile function first, get it working, and then use it to write and test the readFile function. Don't forget that you will have to add the function declarations for these to your header file. Hint 2: If you use a string data type for your file name, you will need to use the c_str() function to pass the name to the file stream constructor. For example, if your file name is stored in the string variable fileName, you will need to use something like:
ifstream myAsmtFile(fileName.c_str());

The rest of your program should stay the same - execpt for minor changes to make it work by reading from and writing to files. I would suggest that you change the order of writing out (and reading in) your variables to month, day, time, then name. This way the string data is all at the end of each entry line in the text file, and the code will be easier to write.

Caution: You will likely still encounter the dreaded segmentation fault. You just have to look through your pointers and try to isolate the fault. Using cout 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 header file
4
Correct inclusion of header file
2
Read File Function
6
Write File Function
6
Text output file is human readable
2
Program Runs Correctly
(including correctly formatted output)
4
Total
30


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

Page last updated: December 27, 2018



Page last updated: December 27, 2018