Sale!

# COMP 3522 Lab 2 Let’s dive in! solution

Original price was: \$35.00.Current price is: \$28.00.

Category:

5/5 - (1 vote)

## Welcome!

Welcome back! In today’s lab, you will use random numbers to populate a new file. Then you will use
IO to read the file and perform a quick statistical analysis. Fun for all shall be had!

## ● Requirements

1. Clone your repo using github classroom: https://classroom.github.com/a/AfA3f0wq
2. Fill out your name and student number at the top of main.cpp
3. Ensure you commit and push your work frequently. You will not earn full marks if you don’t
4. Write a program that creates a file called Readings.txt. Inside the file, your program must create
a list. The list is composed of integer double pairs. There is one pair per line.

The integers are in
sequence (0, 1, 2, 3, …) beginning with zero and ending with some random value between 512
and 1024. The doubles should be random values between 50.000 and 90.000. The doubles only
have 3 decimal places. The file should look like this (of course your doubles will be random,
and there will be more than 5 readings):
0 56.347
1 78.231
2 89.999
3 68.002
4 55.128

5. Write a program that opens the file called Readings.txt. The program must read the contents of
the file and produce a report that looks like this to the screen:
There are XXX readings in the file. The average reading is YYY.YYY.
6. Report breakdown:
• XXX – number of int double pairs
• YYY.YYY – average doubles value
• ZZZ.ZZZ – highest doubles value
• AAA.AAA – lowest doubles value
• BBB.BBB – median doubles value

7. Restriction: Only use C style arrays to store your doubles
8. C++ mandatory reminder: Don’t put all your code in main.cpp. Separate out the logic.
• One example is to place the random number generation and file export code into.
exporter.cpp/.hpp
• then place the file input code and statistical analysis into, statistics.cpp/.hpp
• finally, main will call code in each of the other files to tie the program together
9. Do NOT submit this Lab via D2L/The Learning Hub, submit it via GitHub

This lab will be marked out of 10. For full marks this week, you must:
1. (2 points) Commit and push to GitHub after each non-trivial change to your code
2. (3 points) Successfully write and test a program that creates a Readings.txt file exactly as
described in the Requirements
3. (3 points) Successfully write and test a program that opens and consumes the Readings.txt file
exactly as described in the Requirements

4. (2 points) Write code that is commented and formatted correctly using good variable names,
efficient design choices, atomic functions, thorough tests.

### 3 Hints

How do I achieve exactly three decimal places
Getting exactly three decimal places for the doubles output will be tricky. Try combining two of the