Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The contents of an int array are provided below. You can create and initialize an array with those contents by using an array initialization list,

The contents of an int array are provided below. You can create and initialize an array with those contents by using an array initialization list, as follows: int x[ ] = {120, 80, 72, 143, 123, 124, 125, 3000, 2999, 3000, 82, 876, 986, 345, 1990, 2367, 98, 2, 444, 993, 635, 283, 544, 923, 18, 543, 777, 234, 549, 864, 39, 97, 986, 986, 1, 2999, 473, 776, 9, 23, 397, 15, 822, 1927, 1438, 1937, 1956, 7, 29, -1}; Every element of this array is an int between 0 and 3000, except for the last element, which is -1. Note that you may NOT assume that this is the only array that will be processed by your program. Another set of values may be provided. Since we did not provide a size declarator in the array declaration, nor do we know how many elements are in the array until we process it, that last -1 can be used as a sentinel value for our array processing. It is not considered part of the data set in the array and should not be included in the following calculations. Write a C program that scans through the array contents (everything except the -1) and determines the following statistics on it: 1) the number of elements 2) the average of the elements 3) the minimum and maximum values 4) the second to last minimum and second to last maximum values (if the min or max values are duplicated, use the duplicated value not the next unique value) Your program should analyze the array, determine the above statistics, and print out the results in the following format (example output only). Total number: 700 Average: 2462.9 Min element: 15 Min2 element: 21 Max element: 2984 Max2 element: 2976 The average should be printed as a floating point value with one decimal position. All numbers should be right justified as indicated. Min2 refers to the second-to-smallest minimum element, and Max2 refers to the second-to-largest maximum element. CS1324 page: 2 Note that it is not necessary to create an output file for this project. Printing the results to the console will be sufficient. Note: The easiest way to find the Min2 and Max2 values is to sort the array. The Min, Min2, Max2, and Max elements are then x[0], x[1], x[n-2], and x[n-1] when there are n elements in the array. Run the program again, but this time change the array to be int x[ ] = { 2454, 2559, 22, 2066, 1557, 52, 1688, 748, 1978, 23, 2634, 2434, 2902, 1670, 686, 2223, 2058, 2459, 803, 796, 2200, 545, 2206, 1208, 557, 732, 1896, 105, 1298, 2438, 1192, 390, 2387, 728, 1851, 2928, 583, 2438, 2641, 2013, 1034, 2862, 1177, 1279, 439, 2050, 2848, 2293, 2482, 692, 2222, 305, 1485, 394, 2673, 2610, 2465, 1154, 2214, 1530, 2687, 1487, 1141, 2187, 1743, 668, 1941, 813, 1257, 2560, 1432, 1099, 547, 2499, 2144, 1479, 1723, 305, 210, 451, 2421, 1053, 546, 2929, 2318, 1447, 895, 877, 945, 1193, 1744, 274, 1642, 2814, 2631, 74, 314, 1731, 965, 2363, 1315, 171, 1910, 2726, 317, 2638, 2151, 1073, 56, 250, 357, 1295, 2266, 2021, 2063, 302, 2227, 2705, 2527, 146, 1479, 2297, 1565, 1984, 1411, 2099, 1205, 2685, 1860, 1991, 2290, 2432, 381, 1591, 1162, 1214, 2040, 2702, 508, 1317, 2863, 270, 2488, 2258, 2682, 333, 1454, 2271, 395, 2112, 1161, 151, 585, 1171, 2221, 756, 1594, 2271, 647, 2019, 1181, 2613, 444, 2326, 431, 83, 2893, 1947, 1219, 2212, 2457, 915, 1919, 460, 1811, 2605, 2533, 2517, 1862, 1131, 1360, 251, 2310, 2462, 1984, 1311, 1881, 2438, 911, 1290, 2125, 1604, 508, 256, 1884, 332, 2560, 551, 582, 2445, 328, 2640, 1397, 1555, 2658, 1021, 615, 430, 723, 1588, 591, 1628, 2776, 579, 2189, 1245, 1131, 1004, 479, 1790, 201, 1131, 48, 104, 2114, 2062, 297, 721, 1217, 1308, 1253, 2756, 2341, 2553, 1961, -1}; Did you have to change more than the initialization statement? CS1324 page: 3 Grading Rubric Not initializing the array with the correct data (both times), -50 points Including the -1 sentinel in calculations, -20 points Not correctly printing the total number of points, average, min/max, min2/max2, -10 points each Printing average with more/less than one decimal place, -5 points Turning in a program without judiciously selected comments sprinkled throughout, -5 points

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 Processing Fundamentals Design And Implementation

Authors: David M. Kroenke

5th Edition

B000CSIH5A, 978-0023668814

More Books

Students also viewed these Databases questions

Question

6. Describe why communication is vital to everyone

Answered: 1 week ago