List of all available Websheets
Viewing cpp/arraypassing/extra-credit by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | <p>Write a function that will take in an array of student <tt><strong>scores</strong></tt> along with the <tt><strong>size</tt></strong> of the array and a <tt><strong>ec</strong></tt> array of the same size that indicates whether the corresponding student (whose score at location i in the <tt>scores</tt> array) did an extra credit assignment. If so, <strong> add 10 points</strong> to the corresponding student's score.</p> <p>For example: if <tt>size</tt> is 4 and the <tt>scores</tt> array contains:</p> <pre>{ 80, 83, 91, 75 }</pre> <p>And the <tt>ec</tt> array contains: </p> <pre>{ false, true, true, true }</pre> <p>Then update the <tt>scores</tt> array to be: </p> <pre>{ 80, 93, 101, 85 }</pre> |
Remarks Comments, history, license, etc. | Copied from problem cpp/arraypassing/grade-histogram (author: redekopp@usc.edu) Copied from problem cpp/arrays/reverse (author: redekopp@usc.edu) Copied from problem cpp/cs103/hw-arrays/reverse_copy (author: redekopp@usc.edu) |
Engine | |
Template / Reference solution |
using namespace std; void addExtraCredit(int scores[], int size, bool ec[]) { \[ REDACTED ]\ } int main() { int scores[50]; bool extracredit[50]; bool didec; int n = 0, num; // Get all the scores and bools cin >> num >> didec; while(num != -1){ scores[n] = num; extracredit[n] = didec; n++; // Get the next set of inputs cin >> num >> didec; } // Call the addExtraCredit function addExtraCredit(scores, n, extracredit); // Output the updated scores for(int i=0; i < n; i++){ cout << scores[i] << " "; } cout << endl; return 0; } |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [ {"stdin": "100 1 90 0 80 1 70 1 60 0 -1"}, {"stdin": "80 0 81 0 82 0 83 0 -1"}, {"stdin": "90 1 100 1 95 1 92 0 -1"} ] |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.