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
If a database was being used to track sales, a customer who buys a lot of items would be a good example of how two tables could
3241004551 [841]

Answer:True

Explanation:

7 0
2 years ago
Edhesive assignment 7 calendar
ikadub [295]

Answer:

def leap_year(y):

 if y % 4 == 0:

     return 1

 else:

     return 0

def number_of_days(m,y):

 if m == 2:

     return 28 + leap_year(y)

 elif m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m ==10 or m == 12:

     return 31

 elif m == 4 or m == 6 or m == 9 or m == 11:

     return 30

def days(m,d):

 if m == 1:

     return 0 + d

 if m == 2:

     return 31 + d

 if m == 3:

     return 59 + d

 if m == 4:

     return 90 + d

 if m == 5:

     return 120 + d

 if m == 6:

     return 151 + d

 if m == 7:

     return 181 + d

 if m == 8:

     return 212 + d

 if m == 9:

     return 243 + d

 if m == 10:

     return 273 + d

 if m == 11:

     return 304 + d

 if m == 12:

     return 334 + d

def days_left(d,m,y):

 if days(m,d) <= 60:

     return 365 - days(m,d) + leap_year(y)

 else:

     return 365 - days(m,d)

print("Please enter a date")

day=int(input("Day: "))

month=int(input("Month: "))

year=int(input("Year: "))

choice=int(input("Menu:\n1) Calculate the number of days in the given month.\n2) Calculate the number of days left in the given year.\n"))

if choice == 1:

 print(number_of_days(month, year))

if choice == 2:

 print(days_left(day,month,year))

Explanation:

Hoped this helped

5 0
2 years ago
The force that pulls away from a curve is known as
77julia77 [94]

The correct answer is centrifugal force.

The force that pulls out from the center on a body that is in a circular motion is called centrifugal force. This force increases as the speed of motion increases. It is centrifugal force that results in a strong outward pull on your vehicle traveling around a corner.

7 0
3 years ago
What is sytem software?
schepotkina [342]

Answer:

system software is the set of computer programs that controls and manage the operations of computer hardware.

7 0
1 year ago
____ is designed for short-distance connections and has only a few lambdas, with a greater space between lambdas. Group of answe
givi [52]

Answer:

The answer is Coarse wavelength division multiplexing (CWDM)

Explanation:

CWDM is the wavelength designed for short- distance connections  and has only a few lambdas. It is mostly used nowadays as a type of wavelength technologies deployed in cities and inner access ways. It is inexpensive and thus a cost effective wavelength  division multiplexing. Cost effective lasers can be used in CWDM due to the spacing of about 20nm between its wavelengths.

4 0
3 years ago
Read 2 more answers
Other questions:
  • PLEASE HELP PROGRAMMING WILL GIVE BRAINLIEST
    7·1 answer
  • When you see ##### in a cell, you should A. increase the cell width. B. increase the cell height. C. decrease the cell width. D.
    14·1 answer
  • Does group policy management matter without a server environment?
    7·1 answer
  • While in slide show mode, if you are not careful you can close the application by clicking the x on the menu bar
    12·2 answers
  • What was one complication caused by the tsunami that struck japan in 2011?
    15·1 answer
  • 6.   If you enter 234.567 into a cell that is formatted to display 1 decimal place, what is the value stored in the cell?
    15·2 answers
  • Which of the following is true? Group of answer choices worst case time of Heapsort is better than worst cast time of Quicksort
    10·1 answer
  • If you sort a portion of an Excel sheet and you get an error message such as #DIV/0, what is a likely cause of the error message
    9·1 answer
  • Winners announced tomorrow when I check results ngl I gtg to sleep soon I should see a lot of people tomorrow ^^
    8·1 answer
  • With _________, users will receive recommendations for items liked by similar users.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!