Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

6. Here are 4 files: numbers1.txt , numbers2.txt and numbers3.txt and numbers4.txt . The first two contains a header line telling you how many data

6. Here are 4 files: numbers1.txt , numbers2.txt and numbers3.txt and numbers4.txt . The first two contains a "header" line telling you how many data items follow. (The first one is very small, so you can easily verify you are getting the right results; the second is larger, too large to verify by hand.) The second pair are like the first two, except they are just a list of numbers (no "header", i.e., no count at the top).

a.Write a program that can calculate the average, min and max of the numbers in the first 2 files. It should read the first value (# of points), allocate an array the correct size, read the data into that array, then analyze the array and print the count, average, min & max of the array.

a.Use a function to read the data, a second function to find the average, and a third function to find the min & max. Read the count and allocate the array itself in the (...) routine (...) routine will have to pass back both the count and the pointer after it allocates the array.

b.I recommend that you print out the first few elements and the last few elements of the data file when you read them in to make sure you get all the values. Some print statements in the various routines would also be helpful while writing/testing to make sure things are working properly.

c.Make sure you delete the dynamic array properly and set your pointer back to NULL.

Modify your program to work with an array of filenames, and read and print the statistics for each file in the list. You can use an array of strings for the filenames: string filenames[] = {"numbers1.txt", "numbers2.txt"};

c.Write a modified version of the program from part a. that can work with the files numbers3.txt and The only difference is that the file doesn't tell you the size upfront. Your program will have to read the file twice once to count how many values there are, and then (after allocating an array), read in the data and get the min, max and average.

a.Use a function (filename) that reads the file and counts the number of values.

b.Note: if you're not careful, you can end up reading and counting the last element twice! Make sure you don't do that...remember, is your friend here...

You can use an array of strings for the filenames: string filenames[] = {"numbers3.txt", "numbers4.txt"};

numbers1.txt 5

0.6584 0.4907 0.8009 0.9209 0.1227 

numbers2.txt

100 0.6586 0.3846 0.4242 0.0112 0.8436 0.5168 0.1788 0.8928 0.1873 0.1028 0.3814 0.2861 0.4140 0.8359 0.4081 0.0883 0.2221 0.1202 0.6439 0.9184 0.7060 0.0387 0.0478 0.4748 0.5952 0.0356 0.0935 0.3628 0.1593 0.1353 0.6460 0.9259 0.7315 0.0014 0.8023 0.4504 0.1959 0.4978 0.8705 0.0927 0.2421 0.2144 0.9471 0.7074 0.4388 0.9107 0.8313 0.3972 0.3291 0.9885 0.4689 0.7887 0.6331 0.9285 0.0664 0.2858 0.8726 0.6144 0.7742 0.4244 0.1807 0.3594 0.7822 0.0160 0.3048 0.1838 0.9963 0.6201 0.3480 0.6696 0.5898 0.0534 0.2794 0.0626 0.7458 0.9797 0.6402 0.2789 0.7918 0.4829 0.8573 0.3744 0.8515 0.6129 0.7993 0.1410 0.6169 0.4777 0.2654 0.3925 0.1797 0.9534 0.3515 0.1373 0.2590 0.5262 0.8967 0.5786 0.5796 0.9753 

numbers3.txt

0.6587 0.0946 0.2470 0.9736 0.7696 0.3633 0.7904 0.7180 0.0182 0.2538 

numbers4.txt

0.6588 0.3307 0.0923 0.7707 0.8266 0.0856 0.5901 0.2587 0.5662 0.1436 0.8865 0.8686 0.3430 0.8731 0.0120 0.9793 0.3566 0.3511 0.1464 0.9237 0.2305 0.6419 0.7171 0.3879 0.9802 0.8434 0.8524 0.9803 0.6393 0.1710 0.9556 0.7918 0.6051 0.4253 0.8847 0.2974 0.1751 0.1901 0.6016 0.0529 0.6532 0.6909 0.6270 0.3081 0.9844 0.0913 0.7804 0.9384 0.5104 0.0808 0.4637 0.1207 0.7664 0.1757 0.8443 0.2810 0.4681 0.5441 0.0504 0.2413 0.3203 0.4950 0.2709 0.5870 0.9040 0.0031 0.9806 0.3421 0.7810 0.8820 0.6110 0.5777 0.5918 0.4771 0.6382 0.9131 0.8696 0.7814 0.6373 0.5891 0.6919 0.1354 0.3276 0.2666 0.8467 0.0274 0.7036 0.2401 0.2492 0.0497 0.1755 0.1430 0.8819 0.5356 0.9924 0.9056 0.2592 0.8239 0.6592 0.4372 0.3992 0.7785 0.9229 0.4604 0.7436 0.4442 0.3306 0.7299 0.5410 0.2965 0.8120 0.9367 0.6246 0.9924 0.6948 0.2888 0.5946 0.9179 0.3516 0.7335 0.6317 0.7017 0.6118 0.7904 0.8157 0.8506 0.6783 0.3412 0.3074 0.3373 0.5280 0.2740 0.6918 0.2992 0.3041 0.3716 0.8320 0.0446 0.2283 0.8051 0.6274 0.3045 0.8478 0.2471 0.3591 0.8741 0.1698 0.8507 0.9717 0.5391 0.1541 0.7754 0.7072 0.9070 0.3792 0.8400 0.1867 0.5889 0.1523 0.8331 0.2234 0.2612 0.8041 0.6179 0.3373 0.4647 0.3963 0.3560 0.7369 0.2827 0.4297 0.3351 0.3868 0.0790 0.0090 0.8626 0.2649 0.0000 0.6278 0.9614 0.6589 0.9136 0.5878 0.9059 0.9191 0.5276 0.1577 0.0641 0.5367 0.5814 0.0401 0.3747 0.6924 0.5495 0.6036 0.5485 0.6035 0.0843 0.7249 0.9070 0.7063 0.6156 0.5080 0.2265 0.4235 0.3792 0.4684 0.5095 0.9370 0.5267 0.9792 0.6033 0.4888 0.9496 0.2659 0.2492 0.0191 0.4682 0.4594 0.1840 0.8174 0.2051 0.8201 0.8615 0.7371 0.2059 0.7935 0.9230 0.2111 0.6422 0.2651 0.0267 0.2366 0.2076 0.4245 0.9873 0.6739 0.4704 0.2711 0.8266 0.9413 0.8225 0.4302 0.8097 0.1124 0.5928 0.6481 0.1508 0.7231 0.8831 0.5020 0.4352 0.3359 0.8441 0.4119 0.7372 0.6741 0.8087 0.5038 0.8104 0.9070 0.8843 0.7849 0.9730 0.9305 0.5505 0.5111 0.2630 0.8931 0.1373 0.4432 0.8164 0.1316 0.6408 0.1194 0.9835 0.6316 0.9561 0.5249 0.3313 0.1764 0.4484 0.4166 0.1489 0.9874 0.5722 0.5663 0.0751 0.0402 0.0365 0.7163 0.9608 0.4102 0.4177 0.5507 0.9265 0.0336 0.8749 0.2448 0.4612 0.6280 0.6056 0.0160 0.7277 0.1214 0.6448 0.4698 0.0216 0.3909 0.1478 0.8785 0.5933 0.0555 0.3265 

Name your programs read_nums.cpp (part b) and read_nums_nh.cpp (part c)

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

Step: 3

blur-text-image

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

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions

Question

List and define three types of data transmission controls.

Answered: 1 week ago