Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Array Stats 1 Topics covered: 1D Arrays, Unit testing & Functions Lab Due Feb 19 at 11:55PM Objective: The objective of this lab is to

Array Stats 1

Topics covered: 1D Arrays, Unit testing & Functions

Lab Due Feb 19 at 11:55PM

Objective:

The objective of this lab is to gain experience creating and using 1-dimensional arrays, practice using functions, using git for revision control, use unit testing, and submit to the Mimir platform.

This goal of this lab and HW are to create a set of functions to act and analyze 1-dimensional integer arrays. Once these functions are created, you should be able to create(modify) a cpp file to give statistics on a large file containing integers.

Task 1: Update your private github.uc.edu repository to bring down the starter files.

In our VM, navigate inside your cloned the XXXX-StudentCode repository, which you did in Lab/HW5.

Do a git pull to pull down the most recent revision. This should include a LabHW06 folder containing the starter files.

Task 2: Similar to Lab/HW5, there are 3 files which youll be modifying: stats.cpp, stats-sandbox.cpp, andstats_test.h. stats.cpp will contain the statistic functions below, stats_test.h will contain the unit tests forstats.cpp, and stats-sandbox.cpp will be a sandbox for making the functions, and will turn into the file analyzer in Task 4.

Create (fill-in) the following 8 functions in stats.cpp. Be sure to create at least 4 unit tests for each function for a total of at least 32 tests.

arrSum - Given an int array and its length, return the sum. The sum of an empty array should be 0.

arrMean - Given an int array and its length, return the mean of the values as a double. The mean of an empty array should be 0.

arrMin - Given an int array and its length, return the smallest value, or 0 if the array is empty.

arrMax - Given an int array and its length, return the largest value, or 0 if the array is empty.

arrStdDev - Given an int array and its length, return the population standard deviation as a double (divide by N not N-1). Return 0.0 if the array is empty.

arrNumPrimes - Given an int array and its length, return the number of prime numbers in the array. Return 0 if the array is empty. Remember 0, 1, and negative numbers are not considered prime.

arrSetSize - Given an int array and its length, return the size of the array if duplicates were removed, as in if it was a set (no duplicates). Return 0 if the array is empty.

arrNumCount - Given an int array, its length, and a value, return the number of times value is in the array. Return 0 if the array is empty.

Be sure to write unit tests in stats_test.h first, then implement the functions. Be sure to have at least 32 unit tests. To minimize compilation headaches later, do make test often. Also, be sure your unit tests cover all the code in your stats.cpp file. See Task 3 for more info.

Task 3: Code coverage is a measure of how much of your code is executed. The goal of unit testing is to verify your functions operate as they should. If there is code in your library (stats.cpp) that is not executed when your unit tests are run, there may be a bug hiding there. You can use the kcov tool to discover what lines are not executed:

When you are in the LabHW06 folder do make test to run your unit tests.

Running make test will compile and run your unit tests, but most importantly create the testrunner executable.

Create a temporary folder in LabHW06: mkdir temp

Run kcov: kcov temp ./testrunner

The temporary directory is where kcov will put its results.

Open up Firefox in Ubuntu, press ctrl-o to open up a file, and navigate to your LabHW06/temp folder. Openindex.html

A page should appear with a single line: testrunner, click on it.

This shows all the files that were executed when running testrunner. There are MANY files here, including files in the CXXTEST library, as well as system libraries. Some files may report incorrectly due to debugging information not being available.

Click on the top entry: /home/student/../stats.cpp. This is your library file you created.

Any orange highlighted lines (0/ something) were never executed. Go back and create unit tests to reach those lines, or comment that code out.

To rerun, do make test again, kcov temp ./testrunner, then refresh your Firefox window.

Some points will be devoted to unit test coverage. For 100%, you need to reach 85% coverage for your unit tests.

Task 4: Once stats.cpp and stats_test.h is done, modify stats-sandbox.cpp to read in integers from a file and report statistics on it.

We have given you code to read a file of integers, whose name was specified on the command-line. ./stats-sandbox small.txt

Modify stats-sandbox.cpp so it outputs statistics on the file. Do this by reading the values into an int array (set size to 100000) and feeding that into your library (stats.cpp) functions.

Print count, sum, mean, min, max, stdev, number of primes, and the set size. Follow the order of output and text given in the example output below.

Task 5: Submit your assignment to https://app.mimirplatform.io

Compress your source files into lab6.zip when in the folder: zip lab6.zip stats.cpp stats_test.h stats-sandbox.cpp

There should be a Lab 6: Array Stats I project to submit your zip file to.

Thats it! Be sure to sign the lab attendance sheet.

Lab Grading Rubric:

10% - Lab attendance

10% - Style for stats.cpp

7% - Correct arrSum

7% - Correct arrMean

7% - Correct arrMin

7% - Correct arrMax

7% - Correct arrStDev

7% - Correct arrNumPrimes

7% - Correct arrSetSize

7% - Correct arrNumCount

10% - At least 32 unit tests

4% - > 85% unit test coverage

10% - stats-sandbox.cpp correct output for files.

If program fails to compile 10% for attendance and style will be given.

Example Output of stats-sandbox.cpp:

make ./stats-sandbox small.txt

Count: 10

Sum: 576

Mean: 57.6

Min: 9

Max: 99

StDev: 25.3306

Primes: 0

Set Size: 9

./stats-sandbox medium.txt

Count: 100

Sum: 1044368

Mean: 10443.7

Min: 1610

Max: 19089

StDev: 4188.26

Primes: 8

Set Size: 100

./stats-sandbox large.txt

Count: 10000

Sum: 50181083

Mean: 5018.11

Min: 6

Max: 10093

StDev: 2885.05

Primes: 1202

Set Size: 6333

./stats-sandbox xlarge.txt

Count: 100000

Sum: -688257

Mean: -6.88257

Min: -5000

Max: 4999

StDev: 2896.66

Primes: 6667

Set Size: 9999

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago