Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Programming Problem. Please note the following: 1. Please go through ALL directions carefully. 2. This is a C++ programming problem, so please use C++

C++ Programming Problem. Please note the following:

1. Please go through ALL directions carefully.

2. This is a C++ programming problem, so please use C++ language, not C, Java, etc. Also note the following knowledge of C++ cannot be used in this problem (I have not learned these yet): Vector, Pointer, Class, String, IO_Stream. However, you CAN use the following knowledge: Loops, Iomanip (if possible, but not likely in this problem), Array, Function, Passing Array, Cmath. Const.

3. I will provide you with some sample solutions to the problem so you can test your codes with. So please check your codes with these solutions till your code solution matches with the provided solutions before you post your answer. It would be the best if you can upload the screenshot of your own outputs.

4. I will provide you the work that I have so far so you can start with my work to save you time. Consider it a template, and please use MY TEMPLATE and keep every variable, and comment the same. The BOLDENED parts in my work are the parts I am stuck on and have no clue how to code or just do not know how to fix them. However, if you find something wrong with anything, feel free to change anything. When you post your answer, every variable, comment of mine so far should be the exact same as I provide before.

5. The problem might be long for you to read, so I appreciate your time and effort.

Here is the problem:

Write a program called array.cpp which prompts and reads a list of positive numbers (ints) into an array, prints the array, finds the minimum value in the array, subtracts the minimum value to each array number and then prints the minimum number and the modified array. The input list is terminated by a 0. The program should have a function read_list() for reading in a list of values, a function print_array which prints each array element, a function find_min() for finding minimum number in the array, and a function array_subtract() which subtracts a number from each element of the array.

1. All functions should be written AFTER the main procedure.

2. A function prototype should be written for each function and placed BEFORE the main procedure.

3. Each function should have a comment explaining what it does.

4. Each function parameter should have a comment explaining the parameter.

5. Declare a constant in the main function that stores the array size of 25. Do not declare this constant globally.

6. Implement the following functions as described below to receive full credit. Determine when to use the const specifier (see the lecture notes). The const specifier is used when a functions parameter will not be changed in the implementation of the function.

7. Write a function read_list() which prompts for the list of positive numbers terminated by 0. Read the positive integers into an array which stores integers. The number of elements in the input list may be less than 25. Stop reading when either the input number is the sentinel value 0 or when 25 numbers have been read into the array. An invalid number, i.e. a negative number, entered will be ignored. The function takes three parameters, the array holding integers, the number of elements stored in the array (which is defined as pass by reference), and maximum size of the array (use the constant defined in step 5). Define the first two parameters so that they are modifiable. The function does not return any value.

8. Write a procedure print_array() which displays the values that were inserted into the array as a comma separated list and ending with a period. For example, if the user entered five integers (not including the sentinel) then only five array values are displayed (not 25). The procedure should take two parameters, the array holding integers, and the number of elements in the array. Define both parameters so that they are not modifiable. The function does not return any value.

9. Write a function find_min() which returns the minimum value found in an array of numbers. The function takes two parameters, the array holding integers, and the number of elements in the array. Define both parameters so that they are not modifiable.

10. Write a procedure array_subtract() which subtracts number x to every element of an array. For instance, if the array contains (5, 3, 1) and x equals 2, then the procedure changes the array to (3, 1, -1). The procedure takes three parameters, the number x, the array, and the number of elements in the array. Define the array so that it is modifiable. The function does not return any value.

11. In the main program, use the following algorithm:

a. Call the function read_list() to prompt and read the input list of values terminated by the sentinel value.

b. Call the procedure print_array() to display the array values.

c. Call the function find_min() to search for the smallest value in the array.

d. Call the procedure array_subtract() to subtract the minimum value to each element of the array. Pass the minimum value computed in the previous step as the number x.

e. Call the procedure print_array() to display the array values after it was modified in the previous step.

Here is my work so far:

#include #include using namespace std;

// Function prototypes // Function read_list has 3 parameters: array holding integers, number of elements and maximum size of array void read_list (int array [], int & numElements, const int ARRAY_SIZE);

// Function print_array has 2 parameters: array holding integers and constant number of elements void print_array (int array [], int numElements);

// Function find_min has 2 parameters: array holding integers and constant number of elements int find_min (int array [], int numElements);

// Function array_subtract has 3 parameters: determinant x for subtracting each element, array holding integers and constant number of elements void array_subtract (int array [], int numElements, int x);

int main () { // Declare variables const int ARRAY_SIZE(25); // Constant array size of 25 elements int array [ARRAY_SIZE]; // Define maximum elements in array int numElements; // Number of elements in array int x; // Variable to subtract elements in array

// Function read_list read_list (array, numElements, ARRAY_SIZE); cout

// Function print_array print_array (array, ARRAY_SIZE);

// Function find_min cout

// Function array_subtract array_subtract (array, ARRAY_SIZE, x); print_array (array, ARRAY_SIZE); cout

// Function definitions void read_list (int array [], int & numElements, const int ARRAY_SIZE) { // Declare variables int n; // Variable to read in positive integers int index(0); cout > n; while (index 0) { array[index] = n; } index++; cin >> n; }

// Store last value of index to lastValue variable (NOT SURE THESE CODES ARE CORRECT) int lastValue = array[index - 1]; for (; index

void print_array (int array [], int ARRAY_SIZE) (I ALWAYS END UP PRINTING ALL 25 NUMBERS, WHICH IS FALSE ACCORDING TO THE SAMPLE SOLUTIONS. ALSO NOTICE THE DOT AFTER THE LAST NUMBER. I UNDERSTAND THE COMMAS SEPARATING ALL NUMBERS BUT CANNOT ADD A DOT AFTER THE LAST NUMBER. ) { int index = 1; int n(0); cout

int find_min (int array [], int ARRAY_SIZE) { int min = array[0]; for (int index = 1; index

void array_subtract (int array [], int ARRAY_SIZE, int x) (I HAVE NO IDEA HOW TO GET THE NEW VALUES AFTER SUBTRACTION. CONSULT SAMPLE SOLUTION PLEASE) { for (int index = 0; index

Sample Solution 1:

image text in transcribed

Sample solution 2:

image text in transcribed

I will give you feedback as soon as possible considering the clarity of your work, as well as the correctness. Thanks for the time.

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_2

Step: 3

blur-text-image_3

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

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

Ask your instructor to comment on your resume.

Answered: 1 week ago

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago