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

Illustrate the use of pointers in swapping two numbers.

Write 2 swap functions, for swapping two integers.

void swap(int,int);

void swap(int*,int*);


1.     Write a C++ statement that updates the value of newNum variable by adding the value of the named variable SECRET (assign any value to this variable). Then, write a C++ statement that outputs the value of newNum with an appropriate message.


TotalValue (value ), value2) //returns total of the 2 values

Write a function using C+* statements called Toto/P/oduction) which takes five integer artay's (amay), arrayz

array3, array4, arrayS) and an integer as the size of the arroyd as parameters. The arrayi to array4 Hold

quantity of the four (4) outlets over A days The funstion cakulates the total of each day using the

Tota/Value (value 1, value2) function and store in the array


Create a program that will Ask a user to enter a number. If the number is between 0 and 4, write the word blue. If the number is between 5 and 10, write the word red. if the number is between 11 and 14, write the word green. If it is any other number, write that it is not a correct color option.if else statement

Create a program that will Ask a user to enter a number. If the number is between 0 and 4, write the word blue. If the number is between 5 and 10, write the word red. if the number is between 11 and 14, write the word green. If it is any other number, write that it is not a correct color option.If else statement in C++

Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and the minimum value to minMiles.


Ex: If the input is:


-10 20 30 40


the output is:

Min miles: -10
Max miles: 40


#include <iostream>

using namespace std;


int main() {

  const int NUM_ROWS = 2;

  const int NUM_COLS = 2;

  int milesTracker[NUM_ROWS][NUM_COLS];

  int i;

  int j;

  int maxMiles = 0; // Assign with first element in milesTracker before loop

  int minMiles = 0; // Assign with first element in milesTracker before loop

  int value;


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

   for (j = 0; j < NUM_COLS; j++){

     cin >> value;

     milesTracker[i][j] = value;

   }

  }


  /* Your solution goes here */


  cout << "Min miles: " << minMiles << endl;

  cout << "Max miles: " << maxMiles << endl;


  return 0;

}


Write a function SwapArrayEnds() that swaps the first and last elements of the function's array parameter. Ex: sortArray = {10, 20, 30, 40} becomes {40, 20, 30, 10}.


#include <iostream>

using namespace std;


/* Your solution goes here */


int main() {

  const int SORT_ARR_SIZE = 4;

  int sortArray[SORT_ARR_SIZE];

  int i;

  int userNum;


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

   cin >> userNum;

   sortArray[i] = userNum;

  }


  SwapArrayEnds(sortArray, SORT_ARR_SIZE);


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

   cout << sortArray[i] << " ";

  }

  cout << endl;


  return 0;

}


Type the output for the given program when the input is

1

7

10

9

6


#include <iostream>

using namespace std;


int FindScore(const int scoreVals[], int numVals) {

int i;

int returnVal = scoreVals[0];


for (i = 1; i < numVals; ++i) {

if (scoreVals[i] < returnVal) {

returnVal = scoreVals[i];

}

}


return returnVal;

}


int main() {

const int NUM_SCORES = 5;

int quizScores[NUM_SCORES];

int i;

int returnScore;


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

cin >> quizScores[i];

}


returnScore = FindScore(quizScores, NUM_SCORES);

cout << returnScore << endl;


return 0;

}


Double any element's value that is less than controlValue. Ex: If controlValue = 10, then dataPoints = {2, 12, 9, 20} becomes {4, 12, 18, 20}.

#include <iostream>

using namespace std;


int main() {

  const int NUM_POINTS = 4;

  int dataPoints[NUM_POINTS];

  int controlValue;

  int i;


  cin >> controlValue;


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

   cin >> dataPoints[i];

  }


  /* Your solution goes here */


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

   cout << dataPoints[i] << " " ;

  }

  cout << endl;


  return 0;

}


Write a loop that sets each array element to the sum of itself and the next element, except for the last element which stays the same. Be careful not to index beyond the last element. Ex:

Initial scores:        10, 20, 30, 40
Scores after the loop: 30, 50, 70, 40

The first element is 30 or 10 + 20, the second element is 50 or 20 + 30, and the third element is 70 or 30 + 40. The last element remains the same.

#include <iostream>

using namespace std;


int main() {

  const int SCORES_SIZE = 4;

  int bonusScores[SCORES_SIZE];

  int i;


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

   cin >> bonusScores[i];

  }


  /* Your solution goes here */


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

   cout << bonusScores[i] << " ";

  }

  cout << endl;


  return 0;

}


LATEST TUTORIALS
APPROVED BY CLIENTS