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
Type the correct answer in the box. Spell all words correctly.
faltersainse [42]

The resource allocation section of the test plan contains the information regarding the features to be tested in the test plan.

<h3>What is resource allocation?</h3>

The distribution and disbursement of the total disposable resources within an organization towards the different functions and processes in an organization is referred to as resource allocation.

The main functionality of a resource allocation section in a test plan is to portray the features of the test that will be conducted by the team of experts.

Hence, the functions of resource allocation in a test plan are as aforementioned.

Learn more about resource allocation here:

brainly.com/question/17837067

#SPJ1

5 0
2 years ago
What is a cyber crime?<br><br>help
algol [13]

Answer:

cyber crime, also called computer crime, the use of a computer as an instrument to further illegal ends, such as committing fraud, trafficking in child p0®n0graphy and intellectual property, stealing identities, or violating privacy. Cyber crime, especially through the Internet, has grown in importance as the computer has become central to commerce, entertainment, and government.

3 0
2 years ago
Read 2 more answers
Create a Card class that represents a playing card. It should have an int instance variable named rank and a char variable named
Helen [10]

Answer:

Explanation:

The following code is written in Java. It creates the Card class and then uses it to create a full house and print out the rank and suit of every card in that hand.

class Card {

   int rank;

   char suit;

   public Card(int rank, char suit) {

       this.rank = rank;

       this.suit = suit;

   }

   public int getRank() {

       return rank;

   }

   public char getSuit() {

       return suit;

   }

}

class CardTester {

   public static void main(String[] args) {

       Card card1 = new Card(3, '♥');

       Card card2 = new Card(3, '♠');

       Card card3 = new Card(3, '♦');

       Card card4 = new Card(2, '♦');

       Card card5 = new Card(2, '♣');

       System.out.println("Card 1: " + card1.getRank() + " of " + card1.getSuit());

       System.out.println("Card 2: " + card2.getRank() + " of " + card2.getSuit());

       System.out.println("Card 3: " + card3.getRank() + " of " + card3.getSuit());

       System.out.println("Card 4: " + card4.getRank() + " of " + card4.getSuit());

       System.out.println("Card 5: " + card5.getRank() + " of " + card5.getSuit());

   }

}

3 0
3 years ago
Write a program that lets the user enter the name of a team and then displays the number of times that team has won the World Se
xz_007 [3.2K]

Answer:

see explaination

Explanation:

import java.io.*;

import java.util.Scanner;

public class Winners {

public static void main(String args[]) throws IOException {

Scanner sc = new Scanner(new File("WorldSeriesWinners.txt"));

String commands[] = new String[100000];

int c = 0;

while (sc.hasNextLine()) {

String input = sc.nextLine();

System.out.println(input);

if (input.isEmpty())

continue;

commands[c++] = input;

}

sc.close();

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter the name of a team: ");

String name = keyboard.nextLine();

int count = 0;

for (int i = 0; i < c; i++) {

if (commands[i] != null) {

if (commands[i].equals(name)) {

++count;

}

}

}

if(count!=0)

System.out.println(name + " has won the World Series in the time period from 1903 through 2018 " +count + " number of times" );

else

System.out.println("Team with name "+name+ " does not exists");

}

}

5 0
3 years ago
What engine component is shown in the above Figure?
astra-53 [7]

send attached file with it


5 0
3 years ago
Read 2 more answers
Other questions:
  • The OSI model is currently the most widely implemented network model used to develop and build networks of any size, including t
    8·1 answer
  • Where are the worksheet tabs located
    7·1 answer
  • Difference between positional and non positional number​
    12·1 answer
  • What are the benefits of using an ordered list vs. an unordered list? What are the costs?
    10·1 answer
  • Discuss what repetitions structures are, and how they differ from the vectorization approaches we have previously studied in the
    10·1 answer
  • Importance of computer​
    15·1 answer
  • Draw AND, OR, XOR and XNOR gates with truth table and logic gates.<br><br>.​
    11·1 answer
  • When is 1600 plus 25 and 1700 minus 35 the same thing?​
    10·1 answer
  • What is 2+2 I need to know hurry
    12·2 answers
  • Glenda is searching airline schedules on HolApp, a mobile Web application. While browsing the application, a banner appears on t
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!