Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1 : Write a program with multiple functions that reads an array of type int and prints the number of occurrences of the numbers

Exercise 1: Write a program with multiple functions that reads an array of type int and prints the
number of occurrences of the numbers in an array. You might assume that there are fewer than
10 entries in an array. The description of the functions are:
One function to collect up to 10 numbers. The number of entries, elements, in an array is
entered by the user and each number is also collected from the keyboard. The numbers
must be between 1 and 9. If a user enters a number that is not between 1 and 9, the
collecting process will stop. Save the numbers in an array.
One function to count how many times the number each distinct number in the array is
repeating. The count is saved in the new array.
One function to prompt the result as:
Number Number of occurrences
10
23
31
40
50
60
72
81
93
Exercise 2: Sum of the value in each row and colum of a 3-by-3 matrix (2D array).
For exercise 2, student will create a program that will sum value in each row and column of a 2-
dimension array. The program will:
o Set the size of an array as a global constant variable with value of 3.
o define function randColorRange(). Function randColorRange() is used to randomly
generate a value between 0 and 255 and return the value as an integer.
o Define function populate_matrix(). Function populate_matrix() is used to
populate the 3-by-3 matrix. It means that each cell of the 3 rows and 3 columns will be
populated with one random number. This random number is obtained by using function
randColorRange().
o define function printColorRange(). Function printColorRange() is used to print the
value in each cell of the 3-by-3 array.
o define function sumRowCol(). Function sumRowCol() is used to sum the values in each
row and column of the 3-by-3 array.
o Define function prompt_sumRowCol(). The function is used to print the result of the
sums as:
Sum in column 1=____
Sum in column 2=____
Sum in column 3=____
Sum in row 1=
____
Sum in row 2=
____
Sum in row 3=
____
The main() function should only be used to call each function.

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

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions