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
Leni [432]
4 years ago
10

Assume that the vector arr has been declared. In addition, assume that VECTOR_SIZE has been defined to be an integer that equals

the number of elements in arr. Write a statement that assigns the next to last element of the vector to the variable x (x has already been declared).
Computers and Technology
1 answer:
Ksivusya [100]4 years ago
6 0

Answer:

x=arr[VECTOR_SIZE-2];

Explanation:

We have the vector named arr ,VECTOR_SIZE and integer x.To assign the value of next to last element of the array to the variable x which will be stored on the index VECTOR_SIZE-2 we have to use assignment operator(=) for doing that.  Assignment operator assigns the value of the right of the operator to the variable on left of the operator.

You might be interested in
Write a C++ program that overloads a function named LinearSearch that searches an array of data of either integer data type, flo
frutty [35]

Explanation:

#include <iostream>

#include <vector>

#include <iomanip>

using namespace std;

/*

Overloading means equal function name with different call prototype each.

It's a useful tool that lets you think once and write similar role code twice or more times keeping equal function name.

Please look at lines 12-14: they are overloaded call prototype versions of LinearSearch with identical mission (to know if a value is present in a set)

*/

//#define GENERICS

#ifndef GENERICS                                                                // Conditional compilation statement

bool LinearSearch(vector<int>   ,int);

bool LinearSearch(vector<float> ,float);

bool LinearSearch(vector<double>,double);

#else                                                                           // Conditional compilation statement (uncomment line 10 statement)

template <typename genType>

bool LinearSearch(vector<genType> v, genType value);                            // LinearSearch (generic type parameters version)

#endif

int main(int argc, char *argv[]) {                                              // Test code follows:    

vector<int> vInt    {1,                     -2,     3,          -4,     5};     // Test data (int)

vector<float> vFlo  {1.23456f,              -2.35f, 3.1416f,    -4.7f,  5.55f}; // Test data (float)

vector<double> vDou {1.234567890123456789,  -2.35,  3.1415927,  -4.7,   5.55};  // Test data (double)

cout <<3 << "        is " << (LinearSearch(vInt,3)      ?"":"not ") << "in: {";for(auto x:vInt) cout << setw(11) << x;cout << "}\n";

cout <<3.1416f<< "   is " << (LinearSearch(vFlo,3.1416f)?"":"not ") << "in: {";for(auto x:vFlo) cout << setw(11) << x;cout << "}\n";

cout <<3.14   << " is " << (LinearSearch(vDou,3.1416) ?"":"not ") << "in: {";for(auto x:vDou) cout << /*setprecision(9)<<*/setw(11) << x;cout << "}\n";

return 0;

}

#ifndef GENERICS

// Overloaded function code follows:

bool LinearSearch(vector<int> v, int value) {                                   // LinearSearch (integer parameters version)

bool found = false;                                                             // Until now we haven't found the value we are searching for,

for(auto x:v) found = found || x == value;                                      // but if it is here found becomes true.

return(found);

}

bool LinearSearch(vector<float> v, float value) {                               // LinearSearch (float parameters version)

bool found = false;

for(auto x:v) found = found || x == value;

return(found);

}

bool LinearSearch(vector<double> v, double value) {                             // LinearSearch (double float parameters version)

bool found = false;

for(auto x:v) found = found || x == value;

return(found);

}

/*

So far, so good. It works! But, despite there was little effort involved, redundant code remains.

Is there any solution? Yes! It's called generic programming.

*/

#else

/*

Consider the following code:

   - Template statement at first accepts a generic type as a parameter (genType)

   - genType is used for both parameters (array and value to search)

   - Template statements located after generic version of LinearSearch instructs compiler to generate each type version

Conclusions:    

   - Compared with overloaded versions generic code is more elegant and avoids completely redundancy

   - It enhances overloading while keeping its advantages

*/

template <typename genType>

bool LinearSearch(vector<genType> v, genType value) {   // LinearSearch (generic type parameters version)

bool found = false;                                     // Until now we haven't found the value we are searching for,

for(auto x:v) found = found || x == value;              // but if it is here found becomes true.

return(found);

}

template bool LinearSearch(vector<int>   ,int);

template bool LinearSearch(vector<float> ,float);

template bool LinearSearch(vector<double>,double);

#endif

Download cpp
3 0
3 years ago
What is the best way to set up the spreadsheet? List each expense in a row. List each income source in a column. List each expen
VLD [36.1K]

Answer:

is b

Explanation:

8 0
3 years ago
Read 2 more answers
PLS HELP ME!! WILL GIVE BRAINLIEST
Doss [256]
B i think sorry if I’m wrong
5 0
3 years ago
Read 2 more answers
The formula for calculating the amount of interest charged on a loan is:
Marianna [84]

The Python statement that correctly performs the interest calculation is:

  • interest = (principal interest) time.

<h3>What is a Python statement?</h3>

This is known to be a statement  that is said to an instruction that a Python is said to often decode or interpreter and it is also one that it can execute.

Therefore, The Python statement that correctly performs the interest calculation is:

  • interest = (principal interest) time.

Learn more about Python statement from

brainly.com/question/14986545

#SPJ1

6 0
2 years ago
Kandi recently started working at new job and must become familiar with her computer. If she would like to view what software ha
Kamila [148]

i think its D. All Programs

3 0
3 years ago
Other questions:
  • The ____ problem-solving cycle involves inputting code to an assembler, translating it to machine language, loading it into a Vo
    10·1 answer
  • If the object instance is created in a user program, then the object instance can access both the public and private members of
    9·1 answer
  • Program for bit stuffing...?
    9·1 answer
  • 1. The acronym AUDIENCE serves to remind you of what to consider when analyzing an audience. The U for understanding. How does t
    15·1 answer
  • Which tasks can be completed using the Chart Tools Design tab? Check all that apply.
    9·1 answer
  • Prompt the user for a character and the height of a right triangle. Then, print a triangle of that height using the character en
    11·1 answer
  • Sam plans to use this image in artwork for a brochure about airplanes. Which principles of page layout is Sam planning to use in
    11·1 answer
  • What is netiquettes?. Mention any 4 netiquettes. (for class 6)​
    5·1 answer
  • How does our behavior change when we know we're being watched?
    14·1 answer
  • A.m. client appears at the top of every page
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!