تم الحل ✓
categoryبرمجة وتطوير البرمجيات
schoolبكالوريوس
event_available2026-07-15
السؤال
Transcribed Image Text:
Program 1 (easy):
Write a program that gets from input exactly 50 integers, storing them in an array. Then print the largest,
smallest, sum and (floating-point) average of the entries. After this, print the numbers in the entered order,
then in the reverse order (print in 5 rows of 10 numbers each, use setw() to align), with reasonable text before
each group to describe what you're printing. Then (only after finding largest and smallest, sum and average,
and printing the array twice) sort the array (using a simple sorting algorithm, such as from from chapter 8 in
the book), and print the entries in ascending sorted order. You may assume the entries will each be less than
1000 and greater than -1000. Test with at least two different series.
Program 2 (slightly trickier):
Write a program that gets no more than for 50 integers, stopping at either the 50th integer or the first non-
positive entry (<=0), storing them in consecutive elements an array. Afterward, either print the largest,
smallest, sum and (floating-point) average of the entries, if these exist; otherwise a message that there are no
statistics. After this (again, only if you have data), print the numbers in the entered order, then in the reverse
order (print in up to 5 rows of at most 10 numbers each, using setw () to align), with reasonable text before
each group to describe what you are printing. When printing, the last row might not have 10 elements. Then,
if you have data, (again, only after finding largest and smallest, sum and average, and printing the array
twice) sort the array and print the entries in ascending sorted order. You may assume the entries before the
stop sentinel will each be less than 1000. Test with several different series, including a series with zero
entries, series with less than 50 entries and a series with 50 entries. Do not count, store in the array, or
otherwise process the sentinel at all.
Program 3 (slightly trickier again):
Write another similar program, but stop taking entries only at the first value less than or equal to 0 (the
sentinel). The user may enter more than or fewer than 50 entries. Ignore any entries greater than 0 after the
50th entry, but continue taking entries until the user enters a value less than or equal to 0. Don't count the
extra entries or try to store them in your array. Process only those values before the stop sentinel or in the
first 50 values if you don't see the sentinel before the 50th entry. When printing, the last row might not have
10 elements. Otherwise, you need to do the same things with the data set in the same sequence as before. The
entries you process must all be positive (greater than 0) and you may assume they will be less than 1000.
Test (at least) with a series of zero entries, less than 50 entries, exactly 50 entries, and more than 50 entries.
This is slightly trickier than #2, but not much - think clearly about how to design the (single!) loop for your
input!
Turn in the three programs with their tests.
Hints: you may use input and output redirection on the command line:
program <input file > outputfile
to get the data into and out of the programs. You may also prompt for the file names (hold them in C-strings
or C++ string objects) and do direct file I/O in the programs. In either case, name the input and output
files in a way that shows their relationship clearly. You may also just accept values from the keyboard and
capture the CMD shell text to turn in, but I think this is the (REALLY) hard way to do this... Think the
problems through (design them!) before you code them!
check_circle الجواب — حل مفصل خطوة بخطوة
hourglass_top
🔒
الحل الكامل متاح للمشتركين
اشترك في أرشيف الأسئلة لعرض هذا الحل وآلاف الحلول المفصلة خطوة بخطوة من معلمين معتمدين.