1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anna11 [10]
3 years ago
7

Write a loop that sets each vector element to the sum of itself and the next element, except for the last element which stays th

e same. Be careful not to index beyond the last element. Ex:Initial scores: 10, 20, 30, 40Scores after the loop: 30, 50, 70, 40The 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. Sample program:#include #include using namespace std;int main() { const int SCORES_SIZE = 4; vector bonusScores(SCORES_SIZE); int i = 0; bonusScores.at(0) = 10; bonusScores.at(1) = 20; bonusScores.at(2) = 30; bonusScores.at(3) = 40; for (i = 0; i < SCORES_SIZE; ++i) { cout << bonusScores.at(i) << " "; } cout << endl; return 0;}
Computers and Technology
1 answer:
Gekata [30.6K]3 years ago
6 0

Answer:

Add the following lines of code to the already existing code segment

<em>for (i = 0; i < SCORES_SIZE-1; ++i) { </em>

<em>        bonusScores.at(i) = bonusScores.at(i) + bonusScores.at(i+1);</em>

<em>  }</em>

Explanation:

To do the task in the question, we have to iterate through the vector from the first element i.e. element at index 0 to the second to the last element; i.e. element at last index - 1

We then add each element in this iteration with the next.

This iterates through the vector from 0 to SCORES_SIZE - 1

<em>for (i = 0; i < SCORES_SIZE-1; ++i) { </em>

<em>This adds each vector element with the next</em>

<em>        bonusScores.at(i) = bonusScores.at(i) + bonusScores.at(i+1);</em>

<em>  }</em>

The above should be added before

<em>for (i = 0; i < SCORES_SIZE; ++i) { </em>

<em>        cout << bonusScores.at(i) << " "; </em>

<em>}</em>

<em />

<em>Also, I've made other modifications to the program.</em>

  • <em>Proper import of header files</em>
  • <em>Proper declaration of vector bonusScores</em>

<em />

<em>See attachment for complete source code</em>

Download cpp
You might be interested in
What's a pfp? I keep seeing it on scratch
HACTEHA [7]
A pfp is a Profile-Picture can I pls have brainliest
3 0
3 years ago
Read 2 more answers
David is selling his art work. He wants to figure out how much he should charge for each painting to make a 20 percent profit. H
VMariaS [17]

Answer:

create a spreadsheet that totals the cost and calculates 120 percent of the total cost

8 0
3 years ago
3. Of the following pieces of information in a document, for which would you most likely insert a mail merge field? A. First nam
lara [203]
I would suggest the answer would be both A and D, mail merge is used to specify different field for different recipients. 
8 0
4 years ago
Read 2 more answers
5. What is the number one cause of accidents in the classroom, office, and home?
sp2606 [1]

Answer:

Lack of safety in technology and structures.

4 0
3 years ago
Hardware is defined as the physical parts of a computer
ddd [48]
Indeed, this is to be true as software is to programs and applications(apps) hardware is to physical computers such as hard drive, SSD, motherboard, ram, graphics card, ect...
8 0
3 years ago
Other questions:
  • The pseudo-class selectors for links let you use CSS to change the formatting for all but one of the following. Which one is it?
    12·1 answer
  • What web page has html file that exists on web server?
    10·1 answer
  • If the force of gravity _ then the weight of an object will _
    8·2 answers
  • The ____ of a variable is the location in memory where it’s value is stored. A. Value B. Address C. Data type D. Number
    8·1 answer
  • Select all reasons it is important to perform equipment maintenance
    8·1 answer
  • Ram is also called __________________________________________________
    11·1 answer
  • Why the car floated before it started to sink? Explain.​
    8·1 answer
  • Which option is used in Access to locate and retrieve data that may be present in multiple database tables within the database?
    10·2 answers
  • No links it’s just a normal question about iPhones.
    13·1 answer
  • you're troubleshooting an ip addressing issue, and you issue a command to view the system's tcp/ip configuration. the command yo
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!