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
9. Government and corporate officials concerned about security threats do not bring their own cell phones or laptops when travel
tatuchka [14]

Answer:

True

Explanation:

It is known as Don-Not-Carry rules are implemmented to avoid

-Unauthorized full disk copies (it have been made while the laptop owner was out of the hotel room on overseas travel)

-Laptops steals

- Monitoring by third parties of wireless using.

3 0
3 years ago
Use the variables k and total to write a while loop that computes the sum of the squares of the first 50 counting numbers, and a
pshichka [43]
Int   k=0.total=0;
while(k++<50)
    total+=k*k;
    

5 0
3 years ago
The network of satellites monitoring continental movement is referred to as
Nostrana [21]

The network of satellites monitoring continental movement is referred to as GPS. The answer is letter A. GPS or Global Positioning System revolves the earth twice a day in a precise orbit and transmit information signal back to earth. It uses trilateration to calculate the user’s location.

6 0
3 years ago
Question 2 Unsaved Which of these is NOT an example of an emerging technology? Question 2 options: Sixth Sense Close Range Drone
alexandr1967 [171]

The answer is <em>B.) Close Range Drones</em>

I just took the test

3 0
3 years ago
Which of the following rules should be used to keep the appropriate distance between your vehicle and the vehicle in front of yo
S_A_V [24]
I would say two car length rule. I am not sure what the official license rule is or if it has been changed, but originally the rule was 3 seconds usually depending on how fast the car is going. The faster you are going, the longer it takes to stop. So two-car length rule would probably be the best choice. Definitely not A.
8 0
3 years ago
Read 2 more answers
Other questions:
  • Steps needed to deposit cash on cash deposit machine
    6·1 answer
  • Suppose a retailer who has no technology expertise wishes to set up an online presence for his business. He ________. a. ​can us
    6·1 answer
  • Design and implement your own simple class to represent any household item of your choice (toaster, fan, hair dryer, piano ...)
    11·1 answer
  • [Java] Using the comparable interface
    13·1 answer
  • What are the prime factorizations of 52 and 77? a. b.
    5·1 answer
  • The 8-bit ____ field is used by source network hosts and forwarding routers to distinguished classes or priorities in ipv6 packe
    11·1 answer
  • Complete the function favoriteFlower(). Note that the program will not run as is because the function is incomplete. The purpose
    15·1 answer
  • If you do not clean your hardware on a regular basis, which of these is most likely to be a problem?
    11·1 answer
  • What are the difference among the whole note, half note and quarter note ? (this is music)
    12·2 answers
  • Memory containing hardwired instructions that the computer uses when it boots up, before the system loads. In PCs the instructio
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!