Michael L.

asked • 05/23/22

CS161, C++ using QTCreator, Assignment 8: Stock Statistics

You will be writing various functions to help calculating information about the stock and its performance, as well as to read in data about a stock. These functions need to be able to work on arrays of different sizes and with different values.

here is the stock tester.cpp tests:

#include
#include
using namespace std;
#include "stockFunctions.h"
const int TEST_ARR1_SIZE = 5;
const double TEST_ARR1[TEST_ARR1_SIZE] = {12.25, 12.15, 12.17, 12.20, 12.06};
TEST_CASE( "highestValue" ) {
cout << "1: highestValue" << endl;
CHECK( highestValue(TEST_ARR1, 1, 3) == Approx(12.20) );
}
TEST_CASE( "average" ) {
cout << "2: average" << endl;
CHECK( average(TEST_ARR1, 1, 3) == Approx(12.173333) );
}
TEST_CASE( "standardDev" ) {
cout << "3: standardDev" << endl;
CHECK( standardDev(TEST_ARR1, 1, 3) == Approx(0.0205480) );
}
TEST_CASE( "getData" ) {
cout << "4: getData" << endl;
const int TEST_ARR2_SIZE = 4;
double TEST_ARR2[TEST_ARR2_SIZE];
stringstream input("1.1 12.3 4.6 -1.0");
getData(input, TEST_ARR2, TEST_ARR2_SIZE);
CHECK( TEST_ARR2[0] == Approx(1.1) );
}
TEST_CASE( "calculateChangeArray" ) {
cout << "5: calculateChangeArray" << endl;
//Initialize the changes with obviously bad values
double changes[TEST_ARR1_SIZE] = {-99, -99, -99, -99, -99};
calculateChangeArray(TEST_ARR1, changes, TEST_ARR1_SIZE );
CHECK( changes[1] == Approx(-0.1) );
}
TEST_CASE( "maxDrawdown" ) {
cout << "6: maxDrawdown" << endl;
const int TEST_ARR2_SIZE = 7;
const double TEST_ARR2[TEST_ARR2_SIZE] = {10.0, 6.0, 20.0, 12.0, 13.0, 11.0, 17.0};
CHECK( maxDrawdown(TEST_ARR2, 0, 6) == Approx(-9) );
}

I need help with functions to test against these, and proper functions in general, thank you!

1 Expert Answer

By:

Donald W. answered • 05/24/22

Tutor
5.0 (214)

Experienced and Patient Tutor for Math and Computer Science

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.