Project 0: Using GL

Due: Friday, February 10, 8:59:59pm

Note: there are no late submission folders for Project 0. Do this one on time.

Objectives

The objective of this programming assignment is to make sure that you are set up to compile C++ programs and that you are able to run and submit your projects on GL.

Introduction

In this project, you will go through all of the mechanical steps of submitting a C++ program on GL. If you have submitted programs on GL using shared directories (instead of the submit command), then these steps should be quite familiar.


Assignment

Step 1: link your shared directory

Follow the instructions on the Project Submission page to make a symbolic link to the shared directory in your home directory.

Even though you can read and write in your shared directories before the due date, you should NOT develop your programs in the shared directories. Furthermore, the files in the shared directories should NOT be your only copy of your programs. You should have a copy of your programs on your own computer or in a separate location in your GL account.


Step 2: write some functions for a knock-knock joke

Create a C++ file called joke.cpp and implement the three functions opening(), setup() and punchline() specified in the header file joke.h:

// File: joke.h // // CMSC 341 Spring 2017 Project 0 // // Header file for knock-knock jokes // // Do not make any changes to this file. // #ifndef _JOKE_H_ #define _JOKE_H_ #include <string> using namespace std ; string opening( ) ; string setup() ; string punchline() ; #endif

These functions simply have to return a string. When compiled with the following driver program,

// File: driver.cpp // // CMSC 341 Spring 2017 Project 0 // // Main program for knock-knock jokes // #include <string> #include <iostream> #include "joke.h" using namespace std ; int main() { cout << opening() << endl ; cout << "Who's there?" << endl ; cout << setup() << endl ; cout << setup() << ", who???" << endl ; cout << punchline() << endl ; return 0 ; } it might produce output that looks like: Knock, knock Who's there? Amos Amos, who??? A mosquito bit me!

This will be the typical situation for projects this semester. The project description will ask you to implement some functions (most often these will be member functions for a C++ class). You need to follow the specifications provided in the project description for each function. A main program may be given to you. This is mostly to check for compatibility for compilation and does not guarantee correctness. Your program will be graded by additional main functions. In general, you will not get to see these programs before submission, but just for Project 0, we will show you one:

// File: proj0test.cpp // // CMSC 341 Spring 2017 Project 0 // // main() function used for grading // #include <iostream> #include <string> using namespace std ; #include "joke.h" int main() { // Store output from student's functions string str1(opening()) ; string str2(setup()) ; string str3(punchline()) ; string result ; // string for comments int points = 100 ; // max score // check each string is not empty if (str1.length() > 0) { result = "Testing opening string ... passed\n" ; } else { result = "Opening string is empty -8pts\n" ; points -= 8 ; } if (str2.length() > 0) { result.append("Testing setup string ... passed\n") ; } else { result.append("Setup string is empty -8pts\n") ; points -= 8 ; } if (str3.length() > 0) { result.append("Testing punchline ... passed\n") ; } else { result.append("Punchline is empty -8pts\n") ; points -= 8 ; } // Print out scores cout << "Raw grade: " << points << endl ; cout << "Late penalty: 0\n" ; cout << "Total grade: " << points << endl ; cout << "\n\n------------------------------------------------\n\n" ; cout << "Opening = \"" << str1 << "\"\n" ; cout << "Setup = \"" << str2 << "\"\n" ; cout << "Punchline = \"" << str3 << "\"\n" ; cout << "\nResults of testing:\n\n" ; cout << result << endl ; // Check for originalilty if (str1 == "Knock, knock" && str2 == "Amos" && str3 == "A mosquito bit me!") { cout << "Don't you know any other knock-knock jokes???\n\n" ; } return 0 ; }

This is to show you the importance of keeping the main() function in a separate file. If you put a main() function in joke.cpp then the grading program above won't compile with your joke.cpp and that would be a problem.


Step 3: create a Makefile

Create a makefile that compiles joke.cpp and driver.cpp separately with targets for joke.o, driver.o and driver.out (the executable).

In addition, add targets for run and clean to your makefile. The make run command should compile your program (if needed) and run driver.out. The make clean command should remove the .o files and the executable file.

If you have not used makefiles before, follow the steps in the Spring 2016 CMSC 202 Lab on Makefiles and Separate Compilation.


Implementation Notes

Each project has a section on implementation notes. These point out some issues that you might encounter while developing your code. You should look through the Implementation Notes before you start coding. The first time you look through them, they might not make too much sense. However, you should re-read the notes as you develop your program, because these notes are often mistakes the instructors made while developing the project. These notes often point out pitfalls with sharp spikes at the bottom. We don't usually intend to set traps for you. This is where we tell you how to avoid them.

For Project 0, there are only a few notes:


What to Submit

You must submit the following files to the proj0 directory.

If you followed the instructions in the Project Submission page to set up your directories, you can submit your code using these Unix command.

cp joke.h joke.cpp driver.cpp Makefile ~/cs341proj/proj0/

Your copy of joke.h will actually be replaced by the original version during grading. Also, we won't use driver.cpp for grading. However, with those two files in the proj0 directory, you can go to the directory:

cd ~/cs341proj/proj0/ and type make run to check that you have all the pieces needed to compile and run your program. Please make clean after that.