Background The value of at stock is recorded at the end of trading on a series of days in an array as shown below, where

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Background The value of at stock is recorded at the end of trading on a series of days in an array as shown below, where

Post by answerhappygod »

Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 1
Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 1 (40.62 KiB) Viewed 43 times
Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 2
Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 2 (56.21 KiB) Viewed 43 times
Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 3
Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 3 (52.59 KiB) Viewed 43 times
Below is the files provided:stockTester.cpp and stockFunctions.h
1. stockFunctions.h -- I need help write code for each functions below:
Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 4
Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 4 (54.22 KiB) Viewed 43 times
Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 5
Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 5 (65.06 KiB) Viewed 43 times
Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 6
Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 6 (68.76 KiB) Viewed 43 times
2. stockTester.cpp -- This unit testing for each function.
Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 7
Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 7 (55.3 KiB) Viewed 43 times
Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 8
Background The Value Of At Stock Is Recorded At The End Of Trading On A Series Of Days In An Array As Shown Below Where 8 (53.78 KiB) Viewed 43 times
Please help. I will upvote
Background The value of at stock is recorded at the end of trading on a series of days in an array as shown below, where values are the elements of the array and the indexes represent day number. This particular array represents the stock activity over a 5 day window. On the first day (day 0) the stock value is $12.25. The next day (day 1), the stock drops to $12.15. Day Value 0 12.25 1 12.15 2 12.17 3 12.20 4 12.06 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, not just the size 5 array shown above.

Assignment Instructions Make a UnitTest project in QTCreator, rename sample Tester.cpp to stock Tester.cpp and replace it with the starter code from this copy of stock Tester.cpp. To that project, add this stockFunctions.h add your own stockFunctions.cpp. For this project, you will NOT be submitting your tester file. The tests that are provided are minimal sanity checks of each function. I will use my own tests to grade with that do a more thorough job of testing each function. You can (and should) add your own tests to make sure your functions work for other input values. But do not modify the tests you were given. You should submit a stockFunctions.cpp that compiles against all of the provided tests in stock Tester.cpp. If you have one or more failing tests You can get partial credit for them (and full credit for ones that work). But if your program does not compile for me, then none of the tests will run and thus you will not be able to earn full credit for any of them. Start by "stubbing out" the functions. Write a version of each function that attempts no real work and just returns a value that is probably wrong. • Astub version of a void function should just return; A stub version of a bool function should just return .

Start by "stubbing out" the functions. Write a version of each function that attempts no real work and just returns a value that is probably wrong. • A stub version of a void function should just return; • A stub version of a bool function should just return false; or return true; • A stub version of an int function should just return 0; or some obvious nonsense value like return 12345678; Then you can worry about writing correct functions. A correct function works exactly as described in the doxygen comments for the function in the .h file. You can pass the provided tests with a version of the function that is only partially correct. Part of your job is to think about other situations that might be important to test and verify your code works correctly in them. To do this, you can add more tests to the stock Tester.cpp. If your code does not compile against all of the tests, your score will be limited to the 50% "does not compile" ceiling. Start by making sure you have versions of all the functions that at least compile, then worry about passing tests.

#ifndef STOCK_FUNCTIONS_H #define STOCK_FUNCTIONS_H #include <iostream> /** * @brief Calculates and returns the highest value of the stock * in the range that starts at startDay and ends at endDay. * @param values array of stock values * @param startDay First day - inclusive * @param endDay Last day - inclusive * @return Highest value found * The start and end are both inclusive - the highest value might be one * of them. * Given this array: 12.25, 12.15, 12.17, 12.20, 12.06 * The highestValue from 1 through 3 is 12.20 */ double highestValue(const double values[], int startDay, int endDay); * * * /** * @brief Find the average value within a range of days * @param values array of stock values * @param startDay First day - inclusive * @param endDay Last day - inclusive * @return mean of values * Given this array: 12.25, 12.15, 12.17, 12.20, 12.06 * * * The average from 1 through 3 is -12.17333333333333333 */ double average (const double values[], int startDay, int endDay);

/** * @brief Find the standard deviation for the values within a range of days * @param values array of stock values * @param startDay First day - inclusive * @param endDay Last day - inclusive * @return standard deviation of values * * * * Given this array: 12.25, 12.15, 12.17, 12.20, 12.06 * The stddev from 1 through 3 is -0.0205480466766 * How to calculate standard deviation - this is a "population" standard deviation. * 1) Calculate the average of the items. * 2) For each item, subtract the average value, then square this difference. Sum up these values. * 3) Divide by the number of items. * 4) Take the square root. * https://www.khanacademy.org/math/statistics- probability/summarizing-quantitative-data/ variance-standard deviation-sample/a/population- and-sample-standard deviation-review */ double standardev(const double values[], int startDay, int endDay); * /** * @brief Read arrSize pieces of data from the **inputSource** into the array * Oparam inputSource stream to read data from * @param values array of stock values * @param arrSize number of elements in values * Fills the values array by reading arrSize number of doubles from the input Source. * The input Source could be a file, or a stringstream, or cin. *

/** * @brief Read arrsize pieces of data from the **inputSource** into the array * @param inputSource stream to read data from * Oparam values array of stock values * @param arrSize number of elements in values * * Fills the values array by reading arrSize number of doubles from the inputSource. * The input source could be a file, or a stringstream, or cin. * * Hint: just read from inputSource like it was a file or cin using >> but make sure * to refer to it as inputSource, not "cin". */ void getData(std::istream& inputSource, double values[], int arrSize); * * @brief Calculate the amount each element in values changed from the previous value and store to the changes array. The change for the first element * will always be considered to be 0. * @param values array of stock values * Oparam changes array where results are stored * Oparam arrSize number of elements in values * * Given this array with size 5: 12.25, 12.15, 12.17, 12.20, 12.06 * changes should be set to: 0 -0.1 0.02 0.03 -0.14 */ void calculateChangeArray(const double values[], double changes[], int size);

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( "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)); }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply