We use cookies to give you the best experience possible. By continuing we’ll assume you’re on board with our cookie policy

# Chapter 6 C++ Challenge Problems

#include
using namespace std;

int main() {
int runTimes;

// Populate array
runTimes = 800;
runTimes = 775;
runTimes = 790;
runTimes = 805;
runTimes = 808;

cout

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

We will write a custom essay sample on Chapter 6 C++ Challenge Problems specifically for you
for only \$16.38 \$13.9/page

Order now

Note: These activities may test code with different test values. This activity will perform two tests, the first with a 5-element array (int runTimes), the second with a 4-element array (int runTimes). See How to Use zyBooks.

Also note: If the submitted code tries to access an invalid array element, such as runTime for a 5-element array, the test may generate strange results. Or the test may crash and report “Program end never reached”, in which case the system doesn’t print the test case that caused the reported message.

INCOMPLETE

#include
using namespace std;

int main() {
const int NUM_VALS = 4;
int i = 0;
int sumExtra = -9999; // Assign sumExtra with 0 before your for loop

sumExtra = 0;

for (i = 0; i = 101) {
}
}

cout

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
using namespace std;

int main() {
const int NUM_VALS = 4;
int hourlyTemp;
int i = 0;

hourlyTemp = 90;
hourlyTemp = 92;
hourlyTemp = 94;
hourlyTemp = 95;

for (i = 0; i

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
Note that the last element is not followed by a comma, space, or newline.
#include
using namespace std;

int main() {
const int NUM_VALS = 4;
int userValues;
int i = 0;
int matchValue = 0;
int numMatches = 0; // Assign numMatches with 0 before your for loop

userValues = 2;
userValues = 2;
userValues = 1;
userValues = 2;

matchValue = 2;
numMatches = 0;

for (i = 0; i

Set numMatches to the number of elements in userValues (having NUM_VALS elements) that equal matchValue. Ex: If matchValue = 2 and userValues = {2, 2, 1, 2}, then numMatches = 3.
#include
using namespace std;

int main() {
const int NUM_ELEMENTS = 8; // Number of elements
int userVals; // User values
int i = 0; // Loop index

// Prompt user to input values
cout > userVals;
}

for (i = 0; i

Complete the following program to double each number in the array.
#include
#include
using namespace std;

int main() {
const int SCORES_SIZE = 4;
vector lowerScores(SCORES_SIZE);
int i = 0;

lowerScores.at(0) = 5;
lowerScores.at(1) = 0;
lowerScores.at(2) = 2;
lowerScores.at(3) = -3;

for (i = 0; i 0) {
–lowerScores;
}
else {
lowerScores = 0;
}
}

for (i = 0; i

Write a loop that subtracts 1 from each element in lowerScores if the original element was greater than 0, and otherwise just assigns the element with 0. Ex: lowerScores = {5, 0, 2, -3} becomes {4, 0, 1, 0}.
#include
using namespace std;

int main() {
const int SCORES_SIZE = 4;
int oldScores;
int newScores;
int i = 0;

oldScores = 10;
oldScores = 20;
oldScores = 30;
oldScores = 40;

for (i = 0; i

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, the first with a 4-element array (newScores = {10, 20, 30, 40}), the second with a 1-element array (newScores = {199}). See How to Use zyBooks.

Also note: If the submitted code tries to access an invalid array element, such as newScores for a 4-element array, the test may generate strange results. Or the test may crash and report “Program end never reached”, in which case the system doesn’t print the test case that caused the reported message.

#include
using namespace std;

int main() {
const int NUM_POINTS = 4;
int dataPoints;
int minVal = 0;
int i = 0;

dataPoints = 2;
dataPoints = 12;
dataPoints = 9;
dataPoints = 20;

minVal = 10;

for (i = 0; i

Double any element’s value that is less than minVal. Ex: If minVal = 10, then dataPoints = {2, 12, 9, 20} becomes {4, 12, 18, 20}.
#include
using namespace std;

int main () {
const int NUM_ELEMENTS = 14; // Number of elements
double letterWeights; // Weights in ounces
int postageCosts; // Costs in cents (usps.com 2013)
double userLetterWeight = 0.0; // Letter weight
bool foundWeight = false; // Found weight specified by user
int i = 0; // Loop index

// Populate letter weight/postage cost arrays
letterWeights = 1; postageCosts = 46; ++i;
letterWeights = 2; postageCosts = 66; ++i;
letterWeights = 3; postageCosts = 86; ++i;
letterWeights = 3.5; postageCosts = 106; ++i;
letterWeights = 4; postageCosts = 152; ++i;
letterWeights = 5; postageCosts = 172; ++i;
letterWeights = 6; postageCosts = 192; ++i;
letterWeights = 7; postageCosts = 212; ++i;
letterWeights = 8; postageCosts = 232; ++i;
letterWeights = 9; postageCosts = 252; ++i;
letterWeights = 10; postageCosts = 272; ++i;
letterWeights = 11; postageCosts = 292; ++i;
letterWeights = 12; postageCosts = 312; ++i;
letterWeights = 13; postageCosts = 332; ++i;

// Prompt user to enter letter weight
cout > userLetterWeight;

// Postage costs is based on smallest letter weight greater than
// or equal to mailing letter weight
foundWeight = false;

for (i = 0; (i

Improve the program by also outputting “The next higher weight is ___ with a cost of ___ cents”.
#include
using namespace std;

int main() {
const int NUM_VALS = 4;
int origList;
int offsetAmount;
int i = 0;

origList = 40;
origList = 50;
origList = 60;
origList = 70;

offsetAmount = 5;
offsetAmount = 7;
offsetAmount = 3;
offsetAmount = 0;

for (i = 0; i

Add each element in origList with the corresponding value in offsetAmount. Print each sum followed by a space. Ex: If origList = {40, 50, 60, 70} and offsetAmount = {5, 7, 3, 0}, print:
45 57 63 70
#include
using namespace std;

int main() {
const int SIZE_LIST = 4;
int keysList;
int itemsList;
int i = 0;

keysList = 42;
keysList = 105;
keysList = 101;
keysList = 100;

itemsList = 10;
itemsList = 20;
itemsList = 30;
itemsList = 40;

for (i 100) {
cout

For any element in keysList with a value greater than 100, print the corresponding value in itemsList, followed by a space. Ex: If keysList = {42, 105, 101, 100} and itemsList = {10, 20, 30, 40}, print:
20 30
Since keysList and keysList have values greater than 100, the value of itemsList and itemsList are printed.
#include
#include
using namespace std;

int main() {
vector runTimes(5);

// Populate vector
runTimes.at(0) = 800;
runTimes.at(1) = 775;
runTimes.at(2) = 790;
runTimes.at(3) = 805;
runTimes.at(4) = 808;

cout

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

Note: These activities may test code with different test values. This activity will perform two tests, the first with a 5-element vector (vector runTimes(5)), the second with a 4-element vector (vector runTimes(4)). See How to Use zyBooks.

Also note: If the submitted code tries to access an invalid vector element, such as runTime.at(9) for a 5-element vector, the test may generate strange results. Or the test may crash and report “Program end never reached”, in which case the system doesn’t print the test case that caused the reported message.

#include
#include
using namespace std;

int main() {
const int NUM_VALS = 4;
int i = 0;

for (i = 0; i = 0; i–) {
cout

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

Hint: Use two for loops. Second loop starts with i = NUM_VALS – 1.

Note: These activities may test code with different test values. This activity will perform two tests, the first with a 4-element vector (vector courseGrades(4)), the second with a 2-element vector (vector courseGrades(2)). See How to Use zyBooks.

Also note: If the submitted code tries to access an invalid vector element, such as courseGrades.at(9) for a 4-element vector, the test may generate strange results. Or the test may crash and report “Program end never reached”, in which case the system doesn’t print the test case that caused the reported message.

#include
using namespace std;

struct PatientData {
int heightInches;
int weightPounds;
};

int main() {
PatientData lunaLovegood;

lunaLovegood.heightInches = 63;
lunaLovegood.weightPounds = 115;

cout

Declare a struct named PatientData that contains two integer data members named heightInches and weightPounds. Sample output for the given program:
Patient data: 63 in, 115 lbs
#include
using namespace std;

struct InventoryTag {
int itemID;
int quantityRemaining;
};

int main() {
InventoryTag redSweater;

cout

Write a statement to print the data members of InventoryTag. End with newline. Ex: if itemID is 314 and quantityRemaining is 500, print:
Inventory ID: 314, Qty: 500

Sara from Artscolumbia

Hi there, would you like to get such an essay? How about receiving a customized one?
Check it out goo.gl/Crty7Tt

Chapter 6 C++ Challenge Problems
Artscolumbia
Artscolumbia
#include using namespace std; int main() { int runTimes[5]; // Populate array runTimes[0] = 800; runTimes[1] = 775; runTimes[2] = 790; runTimes[3] = 805; runTimes[4] = 808; cout << runTimes[0] << endl << runTimes[1] << endl << runTimes[2] << endl; return 0; }
Write three statements to print t
2018-10-20 00:31:20
\$ 13.900 2018-12-31
artscolumbia.org
In stock
Rated /5 based on customer reviews