Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 7.1, Problem 7STE
Program Plan Intro
Purpose of given code:
The purpose of given code is assigns the value into array using “for” loop.
Given code:
/*Include the header files*/
#include <iostream>
using namespace std;
//Main method
int main()
{
/*Declaration of variables*/
int sampleArray[10];
//Loop
for(int index=1;index<=10;index++)
/*Multiply the index value into 3 and store to array*/
sampleArray[index]=3*index;
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Question 4: Write a code which copy elements of Array_1 in array_2 in reverse order?
For example:
Array_1
13
12
3
17
array_2
17
3
12
13
2.
int A[3] [4]={{ 4, 6, 7, 9},{ 1, 3, 4, 3},{-5, 6, 7, 2}};
int sum, row, col;
sum
= 0;
for (col=0;col<=3;i++)
sum+=A[0] [col];
what is the value of sum calculated
the number of elements on row 0
the total addition of elements on row 0
the total addition of first 3 elements on row 0
the total addition of all the elements
What is the function of the following code?//code startconst size = 4;const ArrayOfSize = [];for (var i = 0; i < size; i++);{ArrayOfSize.push(i + 1);}ArrayOfSize;//code end
Chapter 7 Solutions
Problem Solving with C++ (10th Edition)
Ch. 7.1 - Prob. 1STECh. 7.1 - In the array declaration double score(5); state...Ch. 7.1 - Identity any errors in the following array...Ch. 7.1 - What is the output of the following code? char...Ch. 7.1 - What is the output of the following code? double a...Ch. 7.1 - What is the output of the following code? int i,...Ch. 7.1 - Prob. 7STECh. 7.1 - Suppose we expect the elements of the array a to...Ch. 7.1 - Prob. 9STECh. 7.1 - Suppose you have the following array declaration...
Ch. 7.2 - Consider the following function definition: void...Ch. 7.2 - Prob. 12STECh. 7.2 - Write a function definition for a function called...Ch. 7.2 - Consider the following function definition: void...Ch. 7.2 - Insert const before any of the following array...Ch. 7.2 - Write a function named outOfOrder that takes as...Ch. 7.3 - Write a program that will read up to ten...Ch. 7.3 - Write a program that will read up to ten letters...Ch. 7.3 - Following is the declaration for an alternative...Ch. 7.4 - Prob. 20STECh. 7.4 - Write code that will fill the array a (declared...Ch. 7.4 - Prob. 22STECh. 7 - Write a function named firstLast2 that takes as...Ch. 7 - Write a function named countNum2s that takes as...Ch. 7 - Write a function named swapFrontBack that takes as...Ch. 7 - The following code creates a small phone book. An...Ch. 7 - There are three versions of this project. Version...Ch. 7 - Hexadecimal numerals are integers written in base...Ch. 7 - Solution to Programming Project 7.3 Write a...Ch. 7 - Prob. 4PPCh. 7 - Write a program that reads in a list of integers...Ch. 7 - Prob. 6PPCh. 7 - An array can be used to store large integers one...Ch. 7 - Write a program that will read a line of text and...Ch. 7 - Write a program to score five-card poker hands...Ch. 7 - Write a program that will allow two users to play...Ch. 7 - Write a program to assign passengers seats in an...Ch. 7 - Prob. 12PPCh. 7 - The mathematician John Horton Conway invented the...Ch. 7 - Redo (or do for the first time) Programming...Ch. 7 - Redo (or do for the first time) Programming...Ch. 7 - A common memory matching game played by young...Ch. 7 - Your swim school has two swimming instructors,...Ch. 7 - Your swim school has two swimming instructors,...Ch. 7 - Prob. 19PPCh. 7 - The Social Security Administration maintains an...
Knowledge Booster
Similar questions
- The index type of an array may be any kind of data. Do you believe this to be true?arrow_forwardExercise: norm loop [**] Modify your implementation of norm to use a loop. Here is pseudocode for what you should do: initialize norm to 0.0 loop through array add to norm the square of the current array component return sqrt of normarrow_forwardIf int abc[5]= {1,2,3,4,5}. What is the value of abc[4]?arrow_forward
- Can enumerators loop across array elements? Why? Why not?arrow_forward#include <stdio.h> int arrC[10] = {0}; int bSearch(int arr[], int l, int h, int key); int *joinArray(int arrA[], int arrB[]) { int j = 0; if ((arrB[0] + arrB[4]) % 5 == 0) { arrB[0] = 0; arrB[4] = 0; } for (int i = 0; i < 5; i++) { arrC[j++] = arrA[i]; if (arrB[i] == 0 || (bSearch(arrA, 0, 5, arrB[i]) != -1)) { continue; } else arrC[j++] = arrB[i]; } for (int i = 0; i < j; i++) { int temp; for (int k = i + 1; k < j; k++) { if (arrC[i] > arrC[k]) { temp = arrC[i]; arrC[i] = arrC[k]; arrC[k] = temp; } } } for (int i = 0; i < j; i++) { printf("%d ", arrC[i]); } return arrC; } int bSearch(int arr[], int l, int h, int key) { if (h >= l) { int mid = l + (h - l) / 2; if…arrow_forwardAnalyze the statements below: double [] templ = {50.0, 69.0, 75.0, 80.0, 55.0}; printArray (temp1); The call to printArray sends the of/to the array temp1.arrow_forward
- In C++arrow_forwardWhat does each line of code mean?arrow_forwardIntSet unionWith(const IntSet& otherIntSet) const; //Unions the current set with the passed set. IntSet::unionWith(const IntSet& otherIntSet){ for (int i = 0; i < otherIntSet.used; ++i) //For each element in the passed set. { add(otherIntSet.data[i]); //Add it to current set. }}arrow_forward
- #include <iostream> using namespace std; const int ROWS = 10; const int COLS = 10; int generateRND(int MIN, int MAX) { return rand() % (MAX - MIN + 1) + MIN; } void initializeArray(int C[][COLS], int min, int max) { for (size_t i = 0; i < ROWS; i++) { for (size_t j = 0; j < COLS; j++) { C[i][j] = generateRND(min, max); } } } void swap(int A[][COLS], int B[][COLS]) { int temp; for (size_t j = 0; j < COLS; j += 2) { for (size_t j = 0 ; j< COLS; j +=) } } void printArray(int C[][COLS]) { for (size_t i = 0; i < ROWS; i++) { for (size_t j = 0; j < COLS; j++) { cout << C[i][j] << " "; } cout << endl; } } int main() { srand((unsigned)time(0)); int A[ROWS][COLS] = { 0 }; int B[ROWS][COLS] = { 0 }; const int MIN = 2; const int MAX = 50; initializeArray(A, 2, 50); } Declares two 10X10 Two-dimensional arrays A and B of type integer. Each array consists of 100 random integers between 2 and 50. 1. Swaps (exchange) the elements of A with…arrow_forward#include <iostream> using namespace std; const int ROWS = 10; const int COLS = 10; int generateRND(int MIN, int MAX) { return rand() % (MAX - MIN + 1) + MIN; } void initializeArray(int C[][COLS], int min, int max) { for (size_t i = 0; i < ROWS; i++) { for (size_t j = 0; j < COLS; j++) { C[i][j] = generateRND(min, max); } } } void swap(int A[][COLS], int B[][COLS]) { int temp; for (size_t j = 0; j < COLS; j += 2) { for (size_t j = 0 ; j< COLS; j +=) } } void printArray(int C[][COLS]) { for (size_t i = 0; i < ROWS; i++) { for (size_t j = 0; j < COLS; j++) { cout << C[i][j] << " "; } cout << endl; } } int main() { srand((unsigned)time(0)); int A[ROWS][COLS] = { 0 }; int B[ROWS][COLS] = { 0 }; const int MIN = 2; const int MAX = 50; initializeArray(A, 2, 50); } Declares two 10X10 Two-dimensional arrays A and B of type integer. Each array consists of 100 random integers between 2 and 50. Swaps (exchange) the elements of odd rows of A…arrow_forwardConsider the following line of code: int[] somearray = new int[30]; Which one of the following options is a valid line of code for displaying the twenty-eighth element of somearray?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- New Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage Learning
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning