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
True/false operating systems of mobile devices can support full-scale software programs like Microsoft word or excel
Anestetic [448]
This statement is false.
7 0
4 years ago
Why was chess considered to be one of the most difficult games for computers to play well?​
telo118 [61]

Answer:

In a general sense, the answer to that is Go. The main reason for that is because the size of the board and the fact that it is empty to begin with gives the game a much more complex opening to the game. But if you were to make things equal in board size then chess is the obvious more difficult game to master.

Explanation:

6 0
3 years ago
Read 2 more answers
The ________ of the operating system enables users to communicate with the computer system. modem window network adapter card us
Marysya12 [62]

Well Formatted Question:

The _______ of the operating system enables users to communicate with the computer system.  

a) modem

b) window

c) network adapter card

d) user interface

Answer:

(d) user interface.

Explanation:

A user interface acts as a middleman between the user of a computer and the operating system of that computer. With the user interface, a user can easily communicate with the computer system including the applications running on it.

The user interface can either be text-based or graphics-based.

With text-based user interface, the user enters commands (using keyboards) in form of texts basically on the command line and then the operating system executes these commands.

With the graphical user interface, users interact with the computer using graphics-like control items such as buttons and menus to give instructions to the computer.

6 0
4 years ago
Which of the following team members are involved in transporting goods directly to customers?
olganol [36]

Answer:

Dave is a regular shopper at Colric Inc., an online company that sells T-shirts. He placed an order for five T-shirts, however when the order arrived, Dave discovered the T-shirts were defective. He returned the order and requested replacements from Colric. This scenario shows an exception to which aspect of a supply chain?

3 0
3 years ago
Write a function called is_even that takes one parameter and returns a boolean value. It should return True if the argument is e
Nikitich [7]

def is_even_number(n):

   return True if n % 2 == 0 else False

while True:

   number = int(input("Enter a number: "))

   if number == 0:

       break

   else:

       if is_even_number(number):

           print("Even")

       else:

           print("Odd")

I wrote my code in python 3.8. I hope this helps.

6 0
3 years ago
Other questions:
  • The main file type used when saving a powerpoint presentation is the?
    10·1 answer
  • A sentinel value ________ and signals that there are no more values to be entered:____
    14·1 answer
  • What are some objects in your home that demonstrate electrical energy to radiant energy to thermal energy
    10·2 answers
  • Please I need this answer now.<br>this is the fill in the blanks​
    14·1 answer
  • You receive an e-mail that seems to come from your bank. Clicking on a link in the message takes you to a website that seems to
    8·2 answers
  • ​Suppose your computer network was compromised in a large scale virus attack last Thursday. Most of the data files got corrupted
    8·1 answer
  • Fill in the blank with the correct response.
    5·2 answers
  • How do you code a website?
    10·1 answer
  • Why does this happen to me?
    14·1 answer
  • State three reasons why users attach speakers to their computer​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!