Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Array copying/shift
    primarykey
    data
    text
    <p>We had a project that asked us to Write a program that allows a user to enter a series of numbers "read numbers into an array for further processing, user signals that they are finished by entering a negative number (negative not used in calculations), after all numbers have been read in do the following, sum up the #'s entered, count the #'s entered, find min/max # entered, compute average, then output them on the screen. So the working version of this that I made looks like so</p> <pre><code>/* Reads data into array. paramater a = the array to fill paramater a_capacity = maximum size paramater a_size = filled with size of a after reading input. */ void read_data(double a[], int a_capacity, int&amp; a_size) { a_size = 0; bool computation = true; while (computation) { double x; cin &gt;&gt; x; if (x &lt; 0) computation = false; else if (a_size == a_capacity) { cout &lt;&lt; "Extra data ignored\n"; computation = false; } else { a[a_size] = x; a_size++; } } } /* computes the maximum value in array paramater a = the array Paramater a_size = the number of values in a */ double largest_value(const double a[], int a_size) { if(a_size &lt; 0) return 0; double maximum = a[0]; for(int i = 1; i &lt; a_size; i++) if (a[i] &gt; maximum) maximum = a[i]; return maximum; } /* computes the minimum value in array */ double smallest_value(const double a[], int a_size) { if(a_size &lt; 0) return 0; double minimum = a[0]; for(int i = 1; i &lt; a_size; i++) if (a[i] &lt; minimum) minimum = a[i]; return minimum; } //computes the sum of the numbers entered double sum_value(const double a [], int a_size) { if (a_size &lt; 0) return 0; double sum = 0; for(int i = 0; i &lt; a_size; i++) sum = sum + a[i]; return sum; } //keeps running count of numbers entered double count_value(const double a[], int a_size) { if (a_size &lt; 0) return 0; int count = 0; for(int i = 1; i &lt;= a_size; i++) count = i; return count; } int _tmain(int argc, _TCHAR* argv[]) { const int INPUT_CAPACITY = 100; double user_input[INPUT_CAPACITY]; int input_size = 0; double average = 0; cout &lt;&lt; "Enter numbers. Input negative to quit.:\n"; read_data(user_input, INPUT_CAPACITY, input_size); double max_output = largest_value(user_input, input_size); cout &lt;&lt; "The maximum value entered was " &lt;&lt; max_output &lt;&lt; "\n"; double min_output = smallest_value(user_input, input_size); cout &lt;&lt; "The lowest value entered was " &lt;&lt; min_output &lt;&lt; "\n"; double sum_output = sum_value(user_input, input_size); cout &lt;&lt; "The sum of the value's entered is " &lt;&lt; sum_output &lt;&lt; "\n"; double count_output = count_value(user_input, input_size); cout &lt;&lt; "You entered " &lt;&lt; count_output &lt;&lt; " numbers." &lt;&lt; "\n"; cout &lt;&lt; "The average of your numbers is " &lt;&lt; sum_output / count_output &lt;&lt; "\n"; string str; getline(cin,str); getline(cin,str); return 0; } </code></pre> <p>That went fine, the problem I am having now is part 2. Where we are to "copy the array to another and shift an array by N elements". I'm not sure where to begin on either of these. I've looked up a few resources on copying array's but I was not sure how to implement them in the current code I have finished, especially when it comes to shifting. If anyone has any thoughts, ideas, or resources that can help me on the right path it would be greatly appreciated. I should point out as well, that I am a beginner (and this is a beginners class) so this assignment might not be the 'optimal' way things could be done, but instead incorporates what we have learned if that makes sense. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload