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
just olya [345]
3 years ago
12

Can somebody explain me what this code does in a few or one sentence?#include #include using namespace std;int main () { const i

nt NUM_ELEMENTS = 8; vector numbers(NUM_ELEMENTS); int i = 0; int tmpValue = 0; cout << "Enter " << NUM_ELEMENTS << " integer values..." << endl; for (i = 0; i < NUM_ELEMENTS; ++i) { cout << "Enter Value#" << i+1 << ": "; cin >> numbers.at(i); } for (i = 0; i < (NUM_ELEMENTS /2); ++i) { tmpValue = numbers.at(i); numbers.at(i) = numbers.at(NUM_ELEMENTS - 1 - i); numbers.at(NUM_ELEMENTS - 1 - i) = tmpValue; } system ("pause"); return 0;}
Computers and Technology
1 answer:
goblinko [34]3 years ago
4 0

Answer:

The program declares and array of 8 elements and swap the position of the 1st element with the 8th; the 2nd with the 7th, the 3rd with the 6th and the 4th with the 5th element

Explanation:

First, I'll arrange the code line by line, then I'll start my explanation from the variable declaration at line 4

#include

using namespace std;

int main () {

const int NUM_ELEMENTS = 8;

vector numbers(NUM_ELEMENTS);

int i = 0;

int tmpValue = 0;

cout << "Enter " << NUM_ELEMENTS << " integer values..." << endl;

for (i = 0; i < NUM_ELEMENTS; ++i)

{

cout << "Enter Value#" << i+1 << ": "; cin >> numbers.at(i);

}

for (i = 0; i < (NUM_ELEMENTS /2); ++i)

{

tmpValue = numbers.at(i); numbers.at(i) = numbers.at(NUM_ELEMENTS - 1 - i);

numbers.at(NUM_ELEMENTS - 1 - i) = tmpValue;

}

system ("pause");

return 0;

}

Line 4: This line declares an instant constant variable NUM_ELEMENTS with a constant value of 8. Meaning that the value cannot be changed during program execution.

Line 5: This line declares a vector array that can change in size. Here, it was declared with size 8.

Line 6 & 7: These lines declares integers variables i and tmpValue with an initialised value of 0, each.

Line 8: This line prints the following string; Enter 8 integer values...

Line 9 to 12: These lines represent an iteration which starts from 0 to 7.

Side Note: When an array is being declared, the index starts from 0 and ends at 1 less that the array size.

So, during this iteration, it accepts inputs into the array from index 0 to 7 i.e. from the first element till the last

Line 13 to 17: This is also an iterative statement. But what this iteration does is that, it swaps elements of the array (as stated in the answer section)

The iteration starts from 0 and ends at a value less than NUM_ELEMENTS/2

Note that NUM_ELEMENTS = 2

So,we can conclude that the iteration starts from 0 till a value less that 8/2

Iteration: 0 till a value less that 4

So, that's 0 to 3 (the iteration is done on array element at index 0,1,2 and 3).

When iteration is at 0, the following is done

tmpValue = number at index 0 i.e. a temporary value is used to store the number at index 0 of the array

Number at 0 = number at (8-1-0)

i.e. number at 0 = number at (7)

Number at 7 is then equal to tmpValue

Swap Completed.

The same is done for index 1,2 and 3.

You might be interested in
In the context of an expert system, a _____ works with the knowledge base management system to ensure that the knowledge base is
defon

Answer:

Knowledge Acquisition Facility.

Explanation:

The power and effectiveness of the Expert System  is equal to the quality of the knowledge it contains. The  knowledge has to deal with high complexity and apply the best judgement. collection of expert knowledge is very important and involves the collecting information about a field usually from  an expert. This information is stored in a computer program stored as a knowledge base.

Knowledge is always updating so it also very important to keep it up to date and it is done by Knowledge Acquisition Facility.

3 0
3 years ago
What are the steps for inserting an internal link?
julia-pushkina [17]

Answer:

=

Worksheet

Ctrl + Enter

Explanation:

4 0
2 years ago
Read 2 more answers
What are the uses of DVD Ram​
Verdich [7]

Answer:

Like ordinary random access memory (RAM), it can be repeatedly read, written to, and erased. Intended mostly for removable computer storage, DVD-RAM provides the capabilities of Rewriteable CD (CD-RW) - users can run programs from the discs, copy files to them and rewrite or delete them.

4 0
2 years ago
Read 2 more answers
Portraits should not ever include any objects other than the person. <br>True <br>False
KonstantinChe [14]

Answer:

False

Explanation:

Be safe and make good choices!!

8 0
3 years ago
When you write contracts, should you list many definitions at the start of the document?
aev [14]

Answer:

You can.

Explanation:

If you want you can, but usually as you cover topics you should list the definitions for each topic then instead of all at the beginning you do not want it to seem like it is a lot.  

4 0
2 years ago
Other questions:
  • Easy question how the internet has impacted y’all life
    13·1 answer
  • The read/write heads of a hard disk gently rest on the hard disk platters in order to read and write the data.
    13·1 answer
  • ​Case-Based Critical Thinking Questions​Case 9-1Melissa, a computer science engineering student, is learning the basics of progr
    11·1 answer
  • How many bits would be needed to count all of the students in class today there is 20 students
    6·1 answer
  • 2) [13 points] You’ve been hired by Banker Bisons to write a C++ console application that determines the number of months to rep
    8·1 answer
  • Supports traditional transactional processing for day-to-day front-office operations or systems that deal directly with the cust
    11·1 answer
  • Pls help I will give points
    7·1 answer
  • What's the difference between cross-site scripting and cross-site request forgery? How do you protect against cross-site request
    15·1 answer
  • Which of the following guidelines about the subject line of e-mail messages is most appropriate?
    15·2 answers
  • What is a best practice when approaching an automation effort?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!