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
Write a program that uses the function isPalindrome given in Example 6-6 (Palindrome). Test your program on the following string
Artist 52 [7]

Answer:

#include <bits/stdc++.h>

using namespace std;

bool isPalindrome(string str)

{

   char a,b;

int length = str.length();

for (int i = 0; i < length / 2; i++)

{

   a=tolower(str[i]);//Converting both first characters to lowercase..

   b=tolower(str[length-1-i]);

   if (b != a )

return false;

}

return true;

   

}

int main() {

   string t1;

   cin>>t1;

   if(isPalindrome(t1))

   cout<<"The string is Palindrome"<<endl;

   else

   cout<<"The string is not Palindrome"<<endl;

return 0;

}

Output:-

Enter the string

madam

The string is Palindrome

Enter the string

abba

The string is Palindrome

Enter the string

22

The string is Palindrome

Enter the string

67876

The string is Palindrome

Enter the string

444244

The string is not Palindrome

Explanation:

To ignore the cases of uppercase and lower case i have converted every character to lowercase then checking each character.You can convert to uppercase also that will also work.

6 0
3 years ago
Explain the ten characteristics of a digital computers​
Paul [167]

Answer:

The major characteristics of computers are the following:

Speed : A powerful computer is capable of executing about 3 million calculations per second.

Accuracy : A computer's accuracy is consistently high; if there are errors, they are due to errors in instructions given by the programmer.

Reliability : The output generated by the computer is very reliable as long as the data is reliable.

Memory/Storage Capacity : The computer can store large volumes of data and makes the retrieval of data an easy task.

Versatility: The computer can accomplish many different things. It can accept information through various input-output devices, perform arithmetic and logic operations, generate a variety of outputs in a variety of forms, etc.

Automation: Once the instructions are fed into computer it works automatically without any human intervention.

Diligence: A computer will never fail to perform its task due to distraction or laziness.

Convenience: Computers are usually easy to access, and allow people to find information easily that without a computer would be very difficult.

Flexibility: Computers can be used for entertainment, for business, by people who hold different ideals or who have varied goals. Almost anyone can use a computer, and computers can be used to assist with almost any goal.

<em>I hope it helps you!!!!</em>

6 0
3 years ago
A startup is developing a new web browser with a focus on accessibility for visually impaired users. The startup founder is cons
gavmur [86]

Answer:

A license that allows developers to change and share the source

code of the licensed software

Explanation:

i learned this, btw brainly stop removing my answers

7 0
2 years ago
Write a function called st_dev. St_dev should have one #parameter, a filename. The file will contain one integer on #each line.
kodGreya [7K]

Answer:

  1. import statistics
  2. def st_dev(file_name):
  3.    with open(file_name) as file:
  4.        data = file.readlines()
  5.        numList = []
  6.        for x in data:
  7.            numList.append(int(x))
  8.        
  9.        return statistics.pstdev(numList)
  10. print(st_dev("text1.txt"))

Explanation:

The solution code is written using Python.

To ease the calculation task, we can import Python statistics module to use the pstdev method to calculate the population standard deviation of a list of numbers (Line 1).

Next, create a st_dev function that take single argument file_name (Line 3). In the function, it will open the input file and read the data line by line (Line 4-5). Create a for loop to traverse through each line of the data which is an integer and append it to numList (Line 7-8). We can pass the numList to pstdev method (Line 10) and return the resulting standard deviation value as output.

We test the function by passing a file which hold a list of integer values in each line (Line 12).

8

9

12

11

21

15

16

10

7

13

And the output we shall get is 4.019950248448356

6 0
3 years ago
You have been assigned to design the database for a new soccer club. Indicate the most appropriate sequence of activities by lab
lara [203]

Answer:

The solution of this question is given below in the explanation section.

Explanation:

To design a database for a new soccer club, the following sequence of activities will be carried out.

_____8_____Create the application programs.

_____4_____ Create a description of each system process.

_____9_____ Test the system. Load the database.

____7______ Normalize the conceptual model.

___1_______ Interview the soccer club president.

___6_______ Create a conceptual model using ER diagrams.

___2_______ Interview the soccer club director of coaching.

____7______ Create the file (table) structures.

____3______ Obtain a general description of the soccer club operations.

____5______ Draw a data flow diagram and system flowcharts.

The correct orders of activities the to design a soccer club database is given below:

  1. Interview the soccer club president.
  2. Interview the soccer club director of coaching.
  3. Obtain a general description of the soccer club operations.
  4. Create a description of each system process.
  5. Draw a data flow diagram and system flowcharts.
  6. Create a conceptual model using ER diagrams.
  7. Create the file (table) structures.
  8. Normalize the conceptual model.
  9. Create the application program
  10. Test the system. Load the database.
7 0
3 years ago
Other questions:
  • Explain why much of social media marketing is trial and error.
    11·1 answer
  • Why should you delete files from your computer? (multiple answers can be chosen)
    5·2 answers
  • • Write a program to find the maximum, minimum, and average score of players. The input to the program is a file containing play
    9·1 answer
  • You are configuring a switch that has three hosts attached to FastEthernet 0/2 through 0/4. All three hosts are part of a public
    10·1 answer
  • What is the maximum upload speed you can get on an isdl internet connection?
    9·1 answer
  • .The __________ comes in handy when I'm using Microsoft Word to type an essay with a specific word number requirement
    6·1 answer
  • What kind of software consists of programs designed to make users more productive and/or assist them with personal tasks?
    10·1 answer
  • Describe how computer are used in ticket counter?​
    10·1 answer
  • Which HTML tag is formatted correctly?
    7·1 answer
  • what uses gps tracking to track vehicles? group of answer choices edge matching. cartography. automatic vehicle location. geogra
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!