I have this pracitce problem and I cant figure out how to do the 2-4 sections. IN C++ please... I've marked in the code where I need help which I'll include at the bottom of the question. Thanks   The scaffold code below tracks monthly precipitation in Denver, Colorado. It accepts four inputs: (1) an integer index representing the month for which a value is to be updated, (2) the new value for that month's precipitation amount, (3) an integer index representing the first month to be considered when calculating total precipitation over multiple months, and (4) an integer index representing the last month to be considered when calculating total precipitation over multiple months. Complete the following tasks: (1) Modify the function VectorSum so that it returns the sum of all elements in theVector with indices between startIndex and endIndex inclusive. (In this context, "inclusive" means that the elements at startIndex and at endIndex are both included in the sum calculation.) (2) Create a function UpdateVector that accepts three parameters: (a) a vector object that is passed by reference, (b) the index of the vector element to be updated, (c) the new value to be placed in the updated element. The function should replace the current value in the index to be updated with the new value. (3) Modify the scaffold code so that the user-provided values for correctionMonth and newPrecipitationAmount are used to update the vector monthlyPrecipitationInDenver. (i.e. the value currently stored in element correctionMonth should be changed to equal the value of newPrecipitationAmount.) You must call your UpdateVector function to do this. (4) Use a cout statement to print the sum of all vector elements with indices between startIndex and endIndex inclusive. You must call the VectorSum function to do this. Sample Input 3 6.0 0 11 Sample Output 37.8   CODE #include <iostream>#include <vector>using namespace std; double VectorSum(vector<double> theVector, unsigned int startIndex, unsigned int endIndex) {double sum = 0;unsigned int i = 0;//TODO: Calculate the sum of all elements in theVector with indices between startIndex and endIndex inclusivefor (i=0; i < theVector.size() ; i++){sum = sum + theVector.at(i);}return sum;} int main() {// create the vector//void UpdateVector (vector<double> monthlyPrecipitationInDenver;monthlyPrecipitationInDenver.push_back(1.0);monthlyPrecipitationInDenver.push_back(1.0);monthlyPrecipitationInDenver.push_back(3.0);monthlyPrecipitationInDenver.push_back(4.3);monthlyPrecipitationInDenver.push_back(6.2);monthlyPrecipitationInDenver.push_back(3.8);monthlyPrecipitationInDenver.push_back(4.5);monthlyPrecipitationInDenver.push_back(4.2);monthlyPrecipitationInDenver.push_back(2.9);monthlyPrecipitationInDenver.push_back(1.9);monthlyPrecipitationInDenver.push_back(2.1);monthlyPrecipitationInDenver.push_back(1.2);int correctionMonth;double newPrecipitationAmount;cin >> correctionMonth >> newPrecipitationAmount;//TODO: replace the vector value at index correctionMonth with the value for newPrecipitationAmountint startIndex;int endIndex;cin >> startIndex >> endIndex;//TODO: output the sum of all elements in monthlyPrecipitationInDenver with indices between startIndex and endIndex inclusive.return 0;}

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

I have this pracitce problem and I cant figure out how to do the 2-4 sections. IN C++ please... I've marked in the code where I need help which I'll include at the bottom of the question. Thanks

 

The scaffold code below tracks monthly precipitation in Denver, Colorado. It accepts four inputs: (1) an integer index representing the month for which a value is to be updated, (2) the new value for that month's precipitation amount, (3) an integer index representing the first month to be considered when calculating total precipitation over multiple months, and (4) an integer index representing the last month to be considered when calculating total precipitation over multiple months. Complete the following tasks:

(1) Modify the function VectorSum so that it returns the sum of all elements in theVector with indices between startIndex and endIndex inclusive. (In this context, "inclusive" means that the elements at startIndex and at endIndex are both included in the sum calculation.) (2) Create a function UpdateVector that accepts three parameters: (a) a vector object that is passed by reference, (b) the index of the vector element to be updated, (c) the new value to be placed in the updated element. The function should replace the current value in the index to be updated with the new value. (3) Modify the scaffold code so that the user-provided values for correctionMonth and newPrecipitationAmount are used to update the vector monthlyPrecipitationInDenver. (i.e. the value currently stored in element correctionMonth should be changed to equal the value of newPrecipitationAmount.) You must call your UpdateVector function to do this. (4) Use a cout statement to print the sum of all vector elements with indices between startIndex and endIndex inclusive. You must call the VectorSum function to do this.

Sample Input

3 6.0 0 11

Sample Output

37.8

 

CODE

#include <iostream>
#include <vector>
using namespace std;

double VectorSum(vector<double> theVector, unsigned int startIndex, unsigned int endIndex) {
double sum = 0;
unsigned int i = 0;

//TODO: Calculate the sum of all elements in theVector with indices between startIndex and endIndex inclusive
for (i=0; i < theVector.size() ; i++){
sum = sum + theVector.at(i);
}

return sum;

}

int main() {
// create the vector
//void UpdateVector (
vector<double> monthlyPrecipitationInDenver;
monthlyPrecipitationInDenver.push_back(1.0);
monthlyPrecipitationInDenver.push_back(1.0);
monthlyPrecipitationInDenver.push_back(3.0);
monthlyPrecipitationInDenver.push_back(4.3);
monthlyPrecipitationInDenver.push_back(6.2);
monthlyPrecipitationInDenver.push_back(3.8);
monthlyPrecipitationInDenver.push_back(4.5);
monthlyPrecipitationInDenver.push_back(4.2);
monthlyPrecipitationInDenver.push_back(2.9);
monthlyPrecipitationInDenver.push_back(1.9);
monthlyPrecipitationInDenver.push_back(2.1);
monthlyPrecipitationInDenver.push_back(1.2);

int correctionMonth;
double newPrecipitationAmount;
cin >> correctionMonth >> newPrecipitationAmount;

//TODO: replace the vector value at index correctionMonth with the value for newPrecipitationAmount

int startIndex;
int endIndex;
cin >> startIndex >> endIndex;

//TODO: output the sum of all elements in monthlyPrecipitationInDenver with indices between startIndex and endIndex inclusive.

return 0;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Returning value from Function
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
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education