EBK PROBLEM SOLVING WITH C++
9th Edition
ISBN: 9780133834505
Author: SAVITCH
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 8.3, Problem 19STE
Is the following
#include <iostream>
#include <
using namespace std;
int main( )
{
vector<int> v(10);
int i;
for (i =0; i < v.size( ); i++)
v[i] = i;
vector<int> copy;
copy = v;
v[0] = 42;
for (i = 0; i < copy.size( ); i++)
cour << copy[i] << “ ”;
cour << endl;
return 0;
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In c++ iv read from a text file containing integers
Example
11,1
22, 3
12, 4
And stored each colum in a vector
vectorx and vectory
How can i make a class for x integers and class for y integers
I will use this classes to compare these x and y integers
Is the following program legal? If so, what is the output? #include <iostream> #include <vector> using namespace std; int main( ) { vector<int> v(10); int i; for (i = 0; i < v.size( ); i++) v[i] = i; vector<int> copy; copy = v; v[0] = 42; for (i = 0; i < copy.size( ); i++) cout << copy[i] << " "; cout << endl; return 0; }
The following questions are related, using C++
a. Write a function template that receives a vector and prints the element of the vector. The return type must be void.
b. Write a function template that receives a vector and returns the smallest element in the vector.
c. Write a main program in which you populate a vector of three students (a mix of Student and GradStudent objects), call the function template in problem 5(a) to print the vector. Then call the function in 5(b) and display the smallest object.
Chapter 8 Solutions
EBK PROBLEM SOLVING WITH C++
Ch. 8.1 - Prob. 1STECh. 8.1 - What C string will be stored in singingString...Ch. 8.1 - What (if anything) is wrong with the following...Ch. 8.1 - Suppose the function strlen (which returns the...Ch. 8.1 - Prob. 5STECh. 8.1 - How many characters are in each of the following...Ch. 8.1 - Prob. 7STECh. 8.1 - Given the following declaration and initialization...Ch. 8.1 - Given the declaration of a C-string variable,...Ch. 8.1 - Write code using a library function to copy the...
Ch. 8.1 - What string will be output when this code is run?...Ch. 8.1 - Prob. 12STECh. 8.1 - Consider the following code (and assume it is...Ch. 8.1 - Consider the following code (and assume it is...Ch. 8.2 - Consider the following code (and assume that it is...Ch. 8.2 - Prob. 16STECh. 8.2 - Consider the following code: string s1, s2...Ch. 8.2 - What is the output produced by the following code?...Ch. 8.3 - Is the following program legal? If so, what is the...Ch. 8.3 - What is the difference between the size and the...Ch. 8 - Create a C-string variable that contains a name,...Ch. 8 - Prob. 2PCh. 8 - Write a program that inputs a first and last name,...Ch. 8 - Write a function named firstLast2 that takes as...Ch. 8 - Write a function named swapFrontBack that takes as...Ch. 8 - Prob. 6PCh. 8 - Write a program that inputs two string variables,...Ch. 8 - Solution to Programming Project 8.1 Write a...Ch. 8 - Write a program that will read in a line of text...Ch. 8 - Give the function definition for the function with...Ch. 8 - Write a program that reads a persons name in the...Ch. 8 - Write a program that reads in a line of text and...Ch. 8 - Write a program that reads in a line of text and...Ch. 8 - Write a program that can be used to train the user...Ch. 8 - Write a sorting function that is similar to...Ch. 8 - Redo Programming Project 6 from Chapter 7, but...Ch. 8 - Redo Programming Project 5 from Chapter 7, but...Ch. 8 - Prob. 11PPCh. 8 - Write a program that inputs a time from the...Ch. 8 - Solution to Programming Project 8.14 Given the...Ch. 8 - Write a function that determines if two strings...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Open the Chap3\ Error2\ Error2 project from the student sample programs folder. The application has an error. F...
Starting Out With Visual Basic (8th Edition)
Grade point average (GPA) in a 4-point scale is calculated by using the following formula:
Write a program t...
Absolute Java (6th Edition)
You hear someone make the following comment: A blueprint is a design for a house. A carpenter can use the bluep...
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Look at the following assignment statements: value1 = 99 value2 = 45.9 value3 = 7.0 value4 = 7 value5 = abc Aft...
Starting Out with Python (3rd Edition)
Write for statements that print the following sequences of values: 1, 2, 3, 4, 5, 6, 7 3, 8, 13, 18, 23 20, 14,...
C How to Program (8th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Question 1 a)Write a small piece of code that defines a vector of integers V with 100 elements and then initializes it so that element V[i] contains the square of i. You only need to write the definitions and the for loop. b)Write a small program that reads from the standard input one line at a time until the end of file. Every line contains a single integer number (use atoi to extract the number). The program prints the sum of all these numbers. You do not need to write any functions. A simple main program is enough. Please write it in C, I need it in 20 minsarrow_forwardQuestion 1. Analysis. 1. Consider the below Array: M1array [4] = {30,40,50,60} Pass the whole array into a M1avg function, explain your answer? Answer: 2. Array1[2] = {2.5,3.5}; Array2[2] = {4.5,5.5}; Write a C program to swap elements between Array 1 and Array 2? Explain your answer Answer: 3. Analyze the below code and correct the error? Explain your answer #include <stdio.h> int main(void) { int Array1 [3] = {3,6,9}; printf("%d",Array1 [3]); return 0; } 4. Array1[2] = {50,1}; Write a C program to add 5 for each element in Array 1? Explain your answer Answer: 5. Consider the below Array: M1array [4] = {3,4,5,6} Pass the second element of M1array into a M1avg function, explain your answer? Answer:arrow_forwardWrite a C++ program that does the following steps: stores 16 integer random numbers in a vector container V. The random numbers range in value (0 – 199). One can generate such numbers by invoking the random number generation function, rand( ) and using the % (mod)operator Prior to using the rand( ) function, initialize the random number generator with the srand(17) Print the entire vector after filling the vector container V Create a function Total(vector iterator, Size) that returns the total sum of the vector V Count the number of values exceeding 85 and print the result Remove all numbers from the vector V that are divisible by 3 Print the entire modified reduced vector after the removal step Create a set S(descending order) from the modified vector V Print Set S Remove the first number in S that is divisible by 4 Print modified Set Sarrow_forward
- Create a function append(v, a, n) that adds to the end of vector v a copy of all the elements of array a. For example, if v contains 1,2, 3, and a contains 4, 5, 6, then v will end up containing 1, 2, 3, 4, 5,6. The argument n is the size of the array. The argument v is a vector ofintegers and a is an array of integers. Write a test driver.arrow_forwardImplement the following function without using any additional data structure, and without sorting the input vectors. /* Given two vectors of integers, check if the two vectors contain same set of values: e.g., V1=[3,4,10,4,10,11] and V2=[3,3,4, 11, 10] stores same set int: {3, 4, 10, 11}. Note that duplicates are removed when considering set */ @param list1, list2: two vectors of integers@pre: list1, list2 have been initialized@post: return true if list1 and list2 stores same values (in same or different order); return false, if not. */ bool SameSet (const vector<int> & list1, const vector<int> & list2) {//for each value in list1, check if it appears in list2, if not, return false //for each value in list2, check if the value appears in list1, if not return false //return true}arrow_forwardAnalysis. (-) 1. Consider the below Array: M1array [4] = {3,5,7,9} Pass the whole array into a M1avg function, explain your answer? (-) Answer: 2. Array1[2] = {15,35}; Array2[2] = {42,54}; Write a C program to swap elements between Array1 and Array2? Explain your answer (-) Answer: 3. Analyze the below code and correct the error? Explain your answer #include <stdio.h> int main(void) { int Array1 [4] = {2,5,8,11}; printf("%d",Array1 [4]); return 0; } -) 4. Array1[2] = {5,10}; Write a C program to add 5 for each element in Array1? Explain your answer (-) Answer: 5. Consider the below Array: M1array [4] =…arrow_forward
- Every data structure that we use in computer science has its weaknesses and strengthsHaving a full understanding of each will help make us better programmers!For this experiment, let's work with STL vectors and STL dequesFull requirements descriptions are found in the source code file Part 1Work with inserting elements at the front of a vector and a deque (30%) Part 2Work with inserting elements at the back of a vector and a deque (30%) Part 3Work with inserting elements in the middle, and removing elements from, a vector and a deque (40%) Please make sure to put your code specifically where it is asked for, and no where elseDo not modify any of the code you already see in the template file This C++ source code file is required to complete this problemarrow_forwardCan you help me write a C++ program to do the following: Create a function append(v, a, n) that adds to the end of vector v a copy of all the elements of array a. For example, if v contains 1, 2, 3, and a contains 4, 5, 6, then v will end up containing 1, 2, 3, 4, 5,6. The argument n is the size of the array. The argument v is a vector ofintegers and a is an array of integers. Write a test driverarrow_forwardPlease explain Wavio Sequencing more clearly for me please there's a picture of the decription and also comment on the code below to know what each line is doing. It is in C++ #include <iostream>#include <vector>#include <algorithm>using namespace std; // LIS[i] stores the maximum length of S's LIS ending at i.void doLIS(const vector<size_t> &S, vector<size_t> &LIS){ vector<size_t> L(S.size()); size_t lisCount = 0; for (size_t i = 0; i < S.size(); ++i) { size_t pos = lower_bound(L.begin(), L.begin() + lisCount, S[i]) - L.begin(); L[pos] = S[i]; if (pos == lisCount) ++lisCount; LIS[i] = pos + 1; }} int main(){ size_t N; while (cin >> N) { vector<size_t> S(N); for (int i = 0; i < N; ++i) cin >> S[i]; vector<size_t> LIS(N), LDS(N); doLIS(S, LIS); reverse(S.begin(), S.end());…arrow_forward
- Define a function named GetWordFrequency that takes a vector of strings and a search word as parameters. Function GetWordFrequency() then returns the number of occurrences of the search word in the vector parameter (case insensitive). Then, write a main program that reads a list of words into a vector, calls function GetWordFrequency() repeatedly, and outputs the words in the vector with their frequencies. The input begins with an integer indicating the number of words that follow. Ex: If the input is: 5 hey Hi Mark hi mark the output is: hey 1 Hi 2 Mark 2 hi 2 mark 2 Hint: Use tolower() to set the first letter of each word to lowercase before comparing. The program must define and use the following function:int GetWordFrequency(vector<string> wordsList, string currWord) write code in c++arrow_forwardDefine a function named GetWordFrequency that takes a vector of strings and a search word as parameters. Function GetWordFrequency() then returns the number of occurrences of the search word in the vector parameter (case insensitive). Then, write a main program that reads a list of words into a vector, calls function GetWordFrequency() repeatedly, and outputs the words in the vector with their frequencies. The input begins with an integer indicating the number of words that follow. Ex: If the input is: 5 hey Hi Mark hi mark the output is: hey 1 Hi 2 Mark 2 hi 2 mark 2 Hint: Use tolower() to set the first letter of each word to lowercase before comparing. The program must define and use the following function:int GetWordFrequency(vector<string> wordsList, string currWord)arrow_forwardConsider the following function main:Int main(){int inStock[10][4];int alpha [20];int beta[20];int gamma[4]= {11,13,15,17};int delta [10] = {3,5,2,6,10,9,7,11,1,8};} a) Write the definition of the function setZero that initializes any one-dimentional array of type int to 0.b) Write the definition of the function inputArray that prompts the user to input 20 numbers and stores the numbers into alpha.c) Write the definition of the function doubleArray that initializes the elements of beta to two times the corresponding elements of alpha. Make sure that you prevent the function from modifying the elements of alpha.d) Write the definition of the function copyGamma that sets the elements of the first row of inStock to gamma and the remaining rows of inStock to three times the previous row of inStock. Make sure that you prevent the function from modifying the elements of gamma.e) Write the definitions of the function copyAlphaBeta that stores alpha into the first five rows of inStock and beta…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
9.1: What is an Array? - Processing Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=NptnmWvkbTw;License: Standard Youtube License