Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Download the following file from the Gaddis textbook Chapter 5 source code folder => random.txt This file contains a long list of random numbers. Using

Download the following file from the Gaddis textbook Chapter 5 source code folder => random.txt

This file contains a long list of random numbers. Using your IDE-compiler create a new project and add this file to your project. Next write a program that opens the file, reads all the numbers from the file, and calculates the following:

A) The number of numbers in the file

B) The sum of all the numbers in the file (a running total)

C) The mean (average) of all the numbers in the file

Your program should ask the user for the name of the file to process (see Chapter #5 section 5.12 in the Gaddis text titled "Letting the User Specify a Filename" on pgs 300-301) and should display the number of numbers found in the file, the sum of the numbers, and the mean (average) of the numbers.

File and Data validation: Appropriate validation methods should be used to ensure that the file stream is not in fail state. In other words you will need to include validation routines to check the following (1) whether the data file opened successfully and (2) the data read from the file matches the variable (datatype) into which the value will be stored. Failure to do so will mean that your program may run but will not produce correct output. Here are some source code hints that you may find helpful in implementing the validation routines.

Here us a sample test run of the file processing program using the sample data file given above.

To process data enter the filename: radman.txt File note found. Enter the correct filename: random.txt 42 468 335 501 170 725 479 359 963 465 706 146 282 828 962 492 996 943 828 437 392 605 903 154 293 383 422 717 719 896 448 727 772 539 870 913 668 300 36 895 704 812 323 334 674 665 142 712 254 869 548 645 663 758 38 860 724 742 530 779 317 36 191 843 289 107 41 943 265 649 447 806 891 730 371 351 7 102 394 549 630 624 85 955 757 841 967 377 932 309 945 440 627 324 538 539 119 83 930 542 834 116 640 659 705 931 978 307 674 387 22 746 925 73 271 830 778 574 98 513 987 291 162 637 356 768 656 575 32 53 351 151 942 725 967 431 108 192 8 338 458 288 754 384 946 910 210 759 222 589 423 947 507 31 414 169 901 592 763 656 411 360 625 538 549 484 596 42 603 351 292 837 375 21 597 22 349 200 669 485 282 735 54 1000 419 939 901 789 128 468 729 894 649 484 808 422 311 618 814 515 Data in random.txt has been successfully read and processed...... Number of numbers: 200 Sum of the numbers: 105527 Average of the numbers: 527.635 Process returned 0 (0x0) execution time : 20.785 s Press any key to continue. 

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

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions

Question

1. How does Kiwi Experience maintain a continual customer focus?

Answered: 1 week ago