CSCI 261 - Programming Concepts (C++)

Fall 2017 - Lab 5A

Quick Links: Canvas | CS @ Mines | Cloud9 | Piazza | zyBooks

|   Home |  Contact |  Syllabus |  Assignments |  Schedule |  Resources   |
This lab is due by Tuesday, October 24, 2017 11:59 PM .

Concepts



This assignment introduces you to a simple form of "unit testing" as a mechanism for exploring the string API. Focus on learning what unit tests are, what an "API" is, and what you can do with string objects.


APIs (Application Programming Interface)



As you can see above, the acronym API stands for Application Programming Interface. But what does that mean? In a nutshell, an API describes what you can do with a particular library or object that you are provided (or that you create). It describes how your code can "interface with" or "use" a particular library or object.

For example, the string API consists of member functions that tell you how long the string is, allow you to capitalize the string, tell you whether it contains a specific character, or allow you to extract a part of the string.

While the API really is the programmatic components that you can actually use, we often rely on API documentation to discover what you can do with a particular library or object. For example, in this assignment you will use the string API, and you will need to look up some API documentation about how you can use string objects.


Unit Testing



As entire books have been written on unit testing, we will merely introduce the topic here. A "unit test" is a small piece of code designed to test a specific part of a program's functionality. In other words, they are bits of code that test the functionality of other code!

For this assignment, that's all the preliminary information you really need to know about unit testing. You will actually write the unit tests, eventually getting the entire test suite to pass (at which point you should go outside and run a victory lap).


The string Mantra



How you read and interpret object-oriented code is important when it comes to understanding the difference between data types, variables, and the "values" that a variable represents. Take a look at the following code.

string name = "Jimi Hendrix";

You are familiar with that syntax, but as we delve into objects we want to emphasize a particular way of translating that from "computerese" to English. When reading the above code, you should say to yourself "name is a string whose contents are the words Jimi Hendrix." Say that sentence aloud while reading the line of code above. Seriously, say it aloud about three or four times:

"name is a string whose contents are the words Jimi Hendrix. name is a string whose contents are the words Jimi Hendrix. name is a string whose contents are the words Jimi Hendrix. name is a string whose contents are the words Jimi Hendrix."

Doing this will help hammer home the way you should translate this line of code (and make anyone near you think there is something seriously wrong with you).


Instructions



A skeletal test suite (a collection of functions) has been provided for you in StringTests_main.cpp. Notice that the functions in this code are defined below main.cpp. In this case, each function is performming a single test on a string. The function will need to return the result of the test.

Your job: complete the function implementations using the string API such that all tests pass. You should not modify the contents of main in this lab, and instead only implement the test functions.

You should start by reading the body of the function called runAllTests() in order to see what your functions must accomplish. For example, the function stringLength() must return the length of the string "Now" using the string API. Take a look at the function stringLength() to see an example of a successful implementation.

When your program prints "PASSED" for a given unit test instead of "FAILED," then you know that your function implementation for that test is complete. Once you get all functions to print "PASSED", do your victory lap!


Hints



  • We recommend that you complete the functions in the order in which they are called in runAllTests() .
  • If you have trouble getting a function to pass its test, use cout statements to help you troubleshoot what your code is doing.
  • The last four functions may require some extra effort (especially middleName() and substitute() ).
  • Leverage the string API as much as you can. Explore the string API to see how the functions work. The documentation may be somewhat confusing; thus, if there is something you don't understand, be sure to ask!


Functional Requirements



  • You must not modify the contents of main() or runAllTests().


Lab Submission



You will submit your solution to this lab with the rest of A5. Detailed instructions for doing this are posted in Assignment 5.


This lab is due by Tuesday, October 24, 2017 11:59 PM .
Last Updated: 10/10/17 20:14


Valid HTML 4.01 Strict Valid CSS! Level Triple-A conformance, W3C WAI Web Content Accessibility Guidelines 2.0