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
Why is it important to understand the basic ways in which pictures and video are stored in the computer?
nalin [4]

Answer:

This is important to understand the basic ways to store pictures and video in a computer because both of them consume a relatively large storage spaces in a the computer compared with normal text files.

Explanation:

Nowadays, many computers shipped with a SSD drive (Solid State Drive) with only around 256 - 512 Gb. With this capacity, the storage spaces left to store the pictures and video are very limited after installation of the essential software.

One common way to store pictures and video is to save them at an external hard drive. Another option is the cloud storage service such as Google Drive, Google Photo etc. These storage mediums obviate the need to store those media files into the local computer machine.

6 0
3 years ago
Meryll is thinking of creating a painting of a historical site. She has seen a similar painting put up online by another artist.
san4es73 [151]
I believe its c, the third option 
3 0
3 years ago
Question very important cause after my school is over at 5 'oclock I will be playing rocket league if anyone wants to play just
jarptica [38.1K]

Answer:

So can u tell me wut is ur question...It is not understandable

6 0
2 years ago
) The _____ method of a radio button returns true if that button is on.
Lostsunrise [7]

Answer:

isSelected()

Explanation:

The isSelected() method of a radio button returns true if that button is on and false otherwise. This method is defined in the class javax.swing.AbstractButton. JRadioButton class inherits from AbstractButton and thus has access to this method. An application code can invoke this method on the radio button instance to determine th ecurrent state and alter the control flow accordingly.

4 0
3 years ago
Which of these are branches of anthropology?
Lesechka [4]

The answer to "Which of these are branches of anthropology" is C... All of the above.

6 0
3 years ago
Read 2 more answers
Other questions:
  • Discussion group may have a___________ who monitors the postings and enforces the sides rules​
    13·1 answer
  • Why are listening and speaking part of the Common Core and ELD Standards? Why is this particularly important for our ELD student
    14·1 answer
  • At the beginning of this month, the balance of Reed's checking account was $692.35. So far this month, he has received a paychec
    13·2 answers
  • Design and implement your own simple class to represent any household item of your choice (toaster, fan, hair dryer, piano ...)
    11·1 answer
  • Consider the following protocol for concurrency control. The database system assigns each transaction a unique and strictly incr
    6·1 answer
  • Which path needs to be followed to change the currency settings of Windows Operating System?
    14·1 answer
  • What types of information should have their sources cited to avoid plagiarism? List at least 3
    10·1 answer
  • The Internet was first used by which of the following institutions?
    7·1 answer
  • (100 points) why does file explorer look like this and how do I fix it? I'm not good with computers, and I kinda need help
    13·1 answer
  • What does Iamo mean? i keep on hearing it and idk what it means
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!