In response to the emergence of the novel coronavirus, testing has become widely available with results being shared in the community to help it track and monitor the extent of the problem.
For this assignment, suppose that a sensor is recording virus test results in batches in a results string. For example,
R2+1-1
would indicate that a single batch of two tests are being reported with one test being reported as positive for the virus and one test being reported as negative for the virus. From this information, note that the character R is being used to start a batch of test results, the character + is being used to identify positive results and the character - is being used to report negative results. More than one batch of results can be reported in a single results string. For example,
R2-1+1R5+3-2
would indicate two batches of results, one with two test results and one with five test results with a total of four positives tests and three negative tests being reported.
Precisely, to be a valid test results string,
All of the following are examples of valid result strings:
All of the following are examples of invalid result strings:
For this project, you will implement the following five functions, using the exact function names, parameter types, and return types shown in this specification. (The parameter names may be different if you wish).
bool isValidResultString(string results)
This function returns true if its parameter is a well-formed test result string as described above, or false otherwise.
int positiveTests(string results)
If the parameter is a well-formed test result string, this function should return the total number of positive tests from all the batches being reported in the string. If the parameter is not valid, return -1 .
int negativeTests(string results)
If the parameter is a well-formed test result string, this function should return the total number of negative tests from all the batches being reported in the string If the parameter is not valid, return -1.
int totalTests(string results)
If the parameter is a well-formed test result string, this function should return the total number of tests being reported from all the batches in the string. If the parameter is not a valid, return -1.
int batches(string results)
If the parameter is a well-formed test result string, this function should return the total number of batches being reported in the string. If the parameter is not a valid, return -1.
These are the only five functions you are required to write. Your solution may use functions in addition to these five if you wish. While we won't test those additional functions separately, using them may help you structure your program more readably. Of course, to test them, you'll want to write a main routine that calls your functions. During the course of developing your solution, you might change that main routine many times. As long as your main routine compiles correctly when you turn in your solution, it doesn't matter what it does, since we will rename it to something harmless and never call it (because we will supply our own main routine to thoroughly test your functions).
Clearly, I am expecting the last four functions to invoke the first function as they complete their assigned task. This code reuse is one of the major benefits of having functions. So please do that.