Questions: 11 448

Answers by our Experts: 10 707

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Write a loop that sets newScores to oldScores shifted once left, with element 0 copied to the end. Ex: If oldScores = {10, 20, 30, 40}, then newScores = {20, 30, 40, 10}.


Note: These activities may test code with different test values. This activity will perform two tests, both with a 4-element array (int oldScores[4]). See "How to Use zyBooks".


If the submitted code tries to access an invalid array element, such as newScores[9] for a 4-element array, the test may generate strange results. Or the test may crash and report "Program end never reached".


#include <iostream>

using namespace std;

int main() {

  const int SCORES_SIZE = 4;

  int oldScores[SCORES_SIZE];

  int newScores[SCORES_SIZE];

  int i;


  for (i = 0; i < SCORES_SIZE; ++i) {

   cin >> oldScores[i];

  }

  /* Your solution goes here */

  for (i = 0; i < SCORES_SIZE; ++i) {

   cout << newScores[i] << " ";

  }

  cout << endl;

  return 0;

}


Write a loop that subtracts 1 from each element in lowerScores. If the element was already 0 or negative, assign 0 to the element. Ex: lowerScores = {5, 0, 2, -3} becomes {4, 0, 1, 0}.


int main() {

  const int SCORES_SIZE = 4;

  int lowerScores[SCORES_SIZE];

  int i;


  for (i = 0; i < SCORES_SIZE; ++i) {

   cin >> lowerScores[i];

  }


  /* Your solution goes here */


  for (i = 0; i < SCORES_SIZE; ++i) {

   cout << lowerScores[i] << " ";

  }

  cout << endl;


  return 0;

}


Multiply each element in origList with the corresponding value in offsetAmount. Print each product followed by a semicolon (no spaces).


Ex: If origList = {4, 5, 10, 12} and offsetAmount = {2, 4, 7, 3}, print:

8;20;70;36;


#include <iostream>

#include <string.h>

using namespace std;


int main() {

  const int NUM_VALS = 4;

  int origList[NUM_VALS];

  int offsetAmount[NUM_VALS];

  int i;


  cin >> origList[0];

  cin >> origList[1];

  cin >> origList[2];

  cin >> origList[3];


  cin >> offsetAmount[0];

  cin >> offsetAmount[1];

  cin >> offsetAmount[2];

  cin >> offsetAmount[3];


  /* Your code goes here */


  cout << endl;


  return 0;

}


Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a comma and space. Ex: If hourlyTemp = {90, 92, 94, 95}, print:

90, 92, 94, 95

Your code's output should end with the last element, without a subsequent comma, space, or newline.


#include <iostream>

using namespace std;


int main() {

  const int NUM_VALS = 4;

  int hourlyTemp[NUM_VALS];

  int i;


  for (i = 0; i < NUM_VALS; ++i) {

   cin >> hourlyTemp[i];

  }


  /* Your solution goes here */


  cout << endl;


  return 0;

}


Array testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full credit is 100, so anything over 100 is extra credit. Ex: If testGrades = {101, 83, 107, 90}, then sumExtra = 8, because 1 + 0 + 7 + 0 is 8.


#include <iostream>

using namespace std;


int main() {

  const int NUM_VALS = 4;

  int testGrades[NUM_VALS];

  int i;

  int sumExtra = -9999; // Assign sumExtra with 0 before your for loop


  for (i = 0; i < NUM_VALS; ++i) {

   cin >> testGrades[i];

  }


  /* Your solution goes here */


  cout << "sumExtra: " << sumExtra << endl;

  return 0;

}


Write a for loop to populate array userGuesses with NUM_GUESSES integers. Read integers using cin. Ex: If NUM_GUESSES is 3 and user enters 9 5 2, then userGuesses is {9, 5, 2}.


#include <iostream>

using namespace std;


int main() {

  const int NUM_GUESSES = 3;

  int userGuesses[NUM_GUESSES];

  int i;


  /* Your solution goes here */


  for (i = 0; i < NUM_GUESSES; ++i) {

   cout << userGuesses[i] << " ";

  }


  return 0;

}


Assign numMatches with the number of elements in userValues that equal matchValue. userValues has NUM_VALS elements. Ex: If userValues is {2, 1, 2, 2} and matchValue is 2 , then numMatches should be 3.


Your code will be tested with the following values:

matchValue: 2, userValues: {2, 1, 2, 2} (as in the example program above)

matchValue: 0, userValues: {0, 0, 0, 0}

matchValue: 10, userValues: {20, 50, 70, 100}


#include <iostream>

using namespace std;


int main() {

  const int NUM_VALS = 4;

  int userValues[NUM_VALS];

  int i;

  int matchValue;

  int numMatches = -99; // Assign numMatches with 0 before your for loop


  cin >> matchValue;

  for (i = 0; i < NUM_VALS; ++i) {

   cin >> userValues[i];

  }


  /* Your solution goes here */


  cout << "matchValue: " << matchValue << ", numMatches: " << numMatches << endl;


  return 0;

}


Write three statements to print the first three elements of array runTimes. Follow each statement with a newline. Ex: If runTime = {800, 775, 790, 805, 808}, print:

800 
775 
790


#include <iostream>

using namespace std;


int main() {

  const int NUM_ELEMENTS = 5;

  int runTimes[NUM_ELEMENTS];

  int i;


  for (i = 0; i < NUM_ELEMENTS; ++i) {

   cin >> runTimes[i];

  }


  int main(){

 int runTime [5]= {800, 775, 790, 805, 808};

 

 for(int i=0; i<3; i++){

 

 cout<<runTime[i]<<endl;

 

}

}/* Your solution goes here */


  return 0;

}


Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print:

7 9 11 10 
10 11 9 7 


#include <iostream>

using namespace std;


int main() {

  const int NUM_VALS = 4;

  int courseGrades[NUM_VALS];

  int i;


  for (i = 0; i < NUM_VALS; ++i) {

   cin >> courseGrades[i];

  }


  /* Your solution goes here */


  return 0;

}


Make a loopable menu with the following options:

-Programs 1

-Programs 2

-Exit


The first menu must contain the following programs:

  1. Print the letter "W" with the symbol "*" starting in coordinates 1,1
  2. Print the letters "XX" with the symbol "*" starting in coordinate 1,1
  3. Same program as point 4 (printing squares) but without filling the inside with *'s
  4. Exit

The second menu must contain the following programs:

  1. Ask two different numbers, print the multiplication tables ranging from those numbers, for example if the numbers given are 2 and 4, print the multiplication tables for 2, 3 and 4.
  2. Ask a number and sum the consecutive numbers until the number asked, for example if the number given is 3, the program should print the result of 1+2+3
  3. Print 4 squares with the symbol "*" which have a size of 10, 5. Print them in the following coordinates. Square 1: 5,5 Square 2: 5,15 Square 3: 30,5 Square 4: 30,15, this program must contain loops.
LATEST TUTORIALS
APPROVED BY CLIENTS