In C++, I need with writing codes for each function. Below is the instructions and the two files stockTester.cpp and sto

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

In C++, I need with writing codes for each function. Below is the instructions and the two files stockTester.cpp and sto

Post by answerhappygod »

In C++, I need with writing codes for each function.
Below is the instructions and the two files stockTester.cpp and
stockFunctions.h -- Specifically I need to add codes for each
functions that can work with the unit testing. :
In C I Need With Writing Codes For Each Function Below Is The Instructions And The Two Files Stocktester Cpp And Sto 1
In C I Need With Writing Codes For Each Function Below Is The Instructions And The Two Files Stocktester Cpp And Sto 1 (66.69 KiB) Viewed 30 times
Below is the two files stockTester.cpp and
stockFunctions.h -- Specifically I need to add codes for each
functions shown in stockFunctions.h that can work with the unit
testing (test functions) in the stockTester.cpp.
1. stockFunctions.h:
In C I Need With Writing Codes For Each Function Below Is The Instructions And The Two Files Stocktester Cpp And Sto 2
In C I Need With Writing Codes For Each Function Below Is The Instructions And The Two Files Stocktester Cpp And Sto 2 (47.53 KiB) Viewed 30 times
2. stockTester.cpp
In C I Need With Writing Codes For Each Function Below Is The Instructions And The Two Files Stocktester Cpp And Sto 3
In C I Need With Writing Codes For Each Function Below Is The Instructions And The Two Files Stocktester Cpp And Sto 3 (52.27 KiB) Viewed 30 times
Update about the questions so basically in the provided
stockFunctions.h above, it has included the functions with
explanations how they work. And so, the task I need to do is to add
code to each provided functions shown in that file
(stockFunctions.h) that make the functions work accordingly.
The stockTester.cpp is the file that will test each functions with
given cases to make sure the functions work
correctly.
Objective Upon completion of this assignment the student will be able to write programs that use arrays. Files to submit • stock Functions.cpp • I should be able to add my own copy of stockFunctions.h stockTester.cpp and compile and run your program with:* g++ -std=c++11 stockFunctions.cpp stockTester.cpp -o program.exe program.exe (-/program.exe on a mac) Test building and running from the command prompt. It is possible to have something set up in QTCreator that works there but does not work when I compile your code using the commands shown above.

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 stockTester.cpp and replace it with the starter code from this copy of stockTester.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 stockTester.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. • 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 stockTester.cpp.

#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/statis ... tative-dat */ double standardDev(const double values[], int startDay, int endDay); /** * @brief Read arrsize pieces of data from the **inputSource** into the array * @param 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 inputSource. * The inputsource 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 * @param changes array where results are stored * @param 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); * /** * @brief Calculates the worst drop in value that might be experienced by an investor during the indicated time period. * @param values array of stock values * @param startDay First day - inclusive * @param endDay Last day - inclusive @return The worst possible loss, expressed in $s. If the price never declines, returns 0. * * * * * This function determines the worst possible investment situation within a given time period. i.e. How much money you could possibly lose if you * bought at some point at or after startDay and then sold before or on endDay. * * Given this array with size 7: 10.0, 6.0, 20.0, 12.0, 13.0, 11.0, 17.0 * The maxDrawDown from 0 to 6 is -9.0 (Buy on day 2, sell on day 5) * The maxDrawDown from 3 to 5 is -2.0 (Buy on day 4, sell on day 5) * The maxDrawDown from 0 to 2 is -4.0 (Buy on day 0, sell on day 1) * The maxDrawDown from 1 to 2 is 0 (No decline) */ double maxDrawdown (const double values[], int startDay, int endDay);

const int TEST_ARRI_SIZE = 5; const double TEST_ARRI[TEST_ARR1_SIZE] = {12.25, 12.15, 12.17, 12.20, 12.06}; TEST_CASE( "highestValue" ) { cout << "1: highestValue" << endl; CHECK( highestValue (TEST_ARRI, 1, 3) == } Approx(12.20) ); TEST_CASE( "average" ) { cout << "2: average" << endl; CHECK( average (TEST_ARRI, 1, 3) == Approx(12.173333) ); } TEST_CASE( "standardDev" ) { cout << "3: standardDev" << endl; CHECK( standardDev (TEST_ARRI, 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_ARRI_SIZE ); CHECK( changes [1] == Approx (-0.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