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
patriot [66]
3 years ago
5

9.1.3: Printing vector elements with a for loop. Write a for loop to print all NUM_VALS elements of vector courseGrades, followi

ng each with a space (including the last). Print forwards, then backwards. End with newline. Ex: If courseGrades
Computers and Technology
1 answer:
svlad2 [7]3 years ago
8 0

Answer:

The program to this question as follows:

Program:

#include <iostream> //defining header file

#include <vector> //defining header file

using namespace std;

int main() //defining main method

{

//defining integer variable NUM_VALS and i.    

int NUM_VALS = 4,i;//assign value in NUM_VALS variable

vector<int> courseGrades(NUM_VALS); //defining vector array

cout<<"Input values: "; //print message

for(i=0;i<NUM_VALS;i++) //loop for input value

{

//input value in verctor array    

cin>>courseGrades[i]; //input from user-end

}

for (i = 0; i < NUM_VALS; i++) //loop to print value

{

cout<<courseGrades[i]<< " ";//print value

}

cout << endl;//for new line

for (i = NUM_VALS-1;i >= 0;i--)//loop to print value in reverse order

{

//print value in reverse order

cout << courseGrades[i] << " "; //print value

}

cout << endl; //for new line

return 0;

}

Output:

Input values: 2

3

5

6

2 3 5 6  

6 5 3 2  

Explanation:

In the above-given code two integer variable "NUM_VALS and i" is declared, in which variable "NUM_VALS" assigns a value, that is 4, in the next step, a vector array "courseGrades" is defined, in which we take input from the user end.

  • In the next step two for loop is declared, in the first loop we simply print the value of the "courseGrades".
  • The second loop is also used to print the "courseGrades" value but, in the reverse order.
You might be interested in
How do you make the "Colorize" feature in GIMP consistent if you cannot connect the different places? Brainliest if you also exp
Brums [2.3K]

Ah, that's easy. You have to select certain parts by using the Free Select tool. Use colorize. Then select the next part and use colorize, but choose the latest used PRESET color to be consistent.

To cut out parts of the image, duplicate your layer without colorization and colorize the top layer. If you have already colorized, put the duplicate as the top layer and click Base Image on the edit history for your original, which is the bottom layer. Use Free Select then click Scissor Select and press the delete button on your keyboard to remove an area, then switch from top layer to bottom layer and use colorize.

6 0
3 years ago
Read 2 more answers
Write common ICT tools​
Naddika [18.5K]
  • computers
  • laptops
  • printers
  • scanners
  • software programs
  • data projectors
  • and interactive teaching box.

4 0
2 years ago
OSHA requires training for employees on the hazards to which they will be exposed.
Sedaia [141]

A, OSHA does require training for employees on the hazards to which they will be exposed.


3 0
3 years ago
Read 2 more answers
A keyboard, mouse, and microphone are examples of ________.
kykrilka [37]

Answer:

A keyboard, mouse, and microphone all are examples of <u>peripheral devices.</u>

Explanation:

hope this helps

5 0
2 years ago
Read 2 more answers
Question 2Write a MIPS assembly implementation of the following C/C++ code. Assume small, unsigned integer arithmetic (no range
Licemer1 [7]

Answer:

Please kindly check explainations for the code.

Explanation:

lw $t1, Num1

lw $t2, Num2

lw $t3, Num3

blt $t1, $t2, if

beq $t1, $t2, elseif

else:

add $t0, $t3, 5

sw $t0, Result

endif:

#.....other statements after if-elseif-else

if:

sw $t1, Result

b endif

elseif:

ble $t2, $t3, if2

or $t0, $t1, $t3

sw $t0, Result

b endif

if2:

and $t0, $t2, $t3

sw $t0, Result

b endif

Go to attachment for the onscreen code.

4 0
3 years ago
Other questions:
  • Which of the following is NOT an ethical way of getting to the top of a web search?
    5·1 answer
  • Write a program that asks the user to input four numbers (one at a time). After the four numbers have been supplied, it should t
    6·1 answer
  • To easily add an organizational chart to a document, users should select _____. SmartArt Text Boxes Shapes Clip Art
    8·2 answers
  • I NEED HELP NOW PLEASE!!!!!!
    6·2 answers
  • To say the internet has helped democratize knowledge means that
    11·1 answer
  • What aspect of web design is Gloria following when she uses the same color scheme throughout a web page?
    12·1 answer
  • What was the ENIAC computer and how was it used/what for?
    9·1 answer
  • What are three requirements of information technology a. Accuracyb. _______________________________c. __________________________
    13·1 answer
  • Of the measures of feasibility in the accompanying figure, ____ considers points such as "Does the proposed platform have suffic
    8·1 answer
  • Describe the importance of human interaction in a computing system.
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!