For this project you will write a class and a nontrivial method (or function). You will use it all in a program with smart pointers and optionals. You will write a testing suite to ensure your program functions properly.
-
All of your programming files should be in a private GitHub repository in your section’s organization.
- The repository must be named with your initials + dash + Project2 (e.g. LD-Project2).
- The repository should have a
.gitignore
file and a README file. - You may reuse your code from Project 1 if you want, but you have to create a new repository.
-
Firstly, in a header file, declare a class that has at least three fields and at least one method that is not a constructor/destructor/getter/setter. Why did you choose this class?
I chose to use the class I made for Project 1 since I was pretty happy with the results, but I found it to be a little messy. Perhaps I will be able to clean it up a bit in this project.
- One of the fields must be an optional.
Why does it make sense for this field to be an optional?
I made the
delay
field an optional because a user may not care about the delay between the notes. If they just want the default delay then the field will remain anullopt
and proceed to play using the default delay. - You must use at least one smart pointer in your program, either in your class/function(s) or in your main program.
Why did you use a pointer here?
I made the Piano object a unique pointer in
main.cpp
because I wanted this one pointer to be the only thing accessing this one object. - If you are reusing your class from Project 1, declare a new global function that uses at least one object of the class.
Why did you choose this function?
I made the
currentMusic
function which shows the music currently stored in the piano object, and theplayAgain
function which asks the user if they would like to hear it again, and does so if "Y" is enterd.
- One of the fields must be an optional.
Why does it make sense for this field to be an optional?
-
Secondly, write test cases for the methods/function(s) in a
testing.cpp
file. Commit to GitHub.- If you are reusing code from Project 1, you still need to write test cases for that code (as well as for the new global function).
- Put an add_executable line in CMakeLists.txt to create an executable for your testing program.
-
Thirdly, implement the methods/function(s) in a
.cpp
file. Did all of your test cases pass on the first try? Commit to GitHub.Yes! I actually spent a lot of time working out the logic for this program. So far, I haven't been able to find any bugs.
-
Fourthly, add more test cases now that you have finished implementing the methods/function(s). Why do you think you did not have these cases before you implemented the algorithm(s)? Commit to GitHub.
There were some cases that I hadn't considered. For instance, I didn't think about spaces in the middle of the input, and because I used
cin >> input
, only the string that leads up to the space would get processed, even though the input does not follow the format. My fix as a result was to usegetline(cin, input)
.- In your README file, you must write answers to all of the above questions.
-
Fifthly, write a
main.cpp
that creates a fully functioning, creative, and impressive program.- The program should use the optional field of the class in some way.
- The program should use at least one smart pointer.
- Put an
add_executable
line inCMakeLists.txt
to create an executable for your main program.
-
Your
main.cpp
andtesting.cpp
should both have a main function. The twoadd_executable
lines will ensure that you are not running these simultaneously.- Make sure that the two
add_executable
lines create executables with different names (i.e. the first argument to the function call must be different).
- Make sure that the two
-
All of the above must be committed and pushed to your GitHub repository.
-
On Gradescope, submit the URL of the repository in a file named submission.txt.
The project is out of 70 points.
- 5 pts Project compiles and runs. GitHub repository includes all files as described above.
- 5 pts Good coding style and consistent style throughout project.
- 5 pts Commits as described above.
- 10 pts Class satisfies requirements described above.
- 15 pts Testing is robust and readable.
- 10 pts Main function uses the optional field from your class and at least one smart pointer.
- 15 pts Main program is fully functional, creative, and impressive.
- 5 pts The README file contains all that is described above. It is readable and grammatically correct.