Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a complete C + + program that does the following: Declares an array of integers with capacity 2 0 . Passes the array to

Write a complete C++ program that does the following:
Declares an array of integers with capacity 20.
Passes the array to a f
unction called fillWithDistinctNums that takes a 1D array and an integer capacity as input. The f
unction fills the
array with random integers between 1 and 20(inclusive) BUT each number must be different than all previous entries in the array. In
other words, no number can appear more than once in the array.
Generate the entries as random numbers and repeatedly make new numbers until a legal entry is found
HINT: You
will need to use a while loop inside the for loop. For each new number generated, you
will check all previous entries in
the array to see if the new number is a duplicate of a previous number already in the array.
Passes the filled array to a f
unction called printArray that takes the 1D array and its capacity as input and prints all elements in the
array separated by a space.
Example main f
unction that uses fillWithDistinctNums:
int main(){
int nums[20];
fillWithDistinctNums(nums,20);
printArray(nums,20);
return 0;
}

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

Students also viewed these Databases questions