answer.
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
nlexa [21]
2 years ago
13

Given a sorted list of integers, output the middle integer. A negative number indicates the end of the input (the negative numbe

r is not a part of the sorted list). Assume the number of integers is always odd.
Ex: If the input is: 2 3 4 8 11 -1
the output is:
Middle item: 4
The maximum number of inputs for any test case should not exceed 9. If exceeded, output "Too many numbers". Hint: First read the data into a vector. Then, based on the number of items, find the middle item. 276452.1593070
(Must include vector library to use vectors)
Computers and Technology
1 answer:
7nadin3 [17]2 years ago
5 0

Answer:

If the input is: 2 3 4 8 11 -1

the output is:

Middle item: 4

To explain the given is as follows,

Explanation:

Code:-

#include <iostream>

#include <vector>

using namespace std;

int main()

{

   std::vector<int> v;

   int temp, i=0;

   cout <<"Enter the sorted elements "<<endl;

   while(1){

        cout<<"Enter ["<<i<<"]element"<<endl;//Accept elements in a vector

        cin >> temp;

        i++;

        if(temp>0)

          v.push_back(temp);

        else       //If negative number is inputed assume end of input

          break;

   }

   cout<<"Size of a vector is:"<<v.size()<<endl; //Find size of vector

   

 

   if (v.size() % 2 == 0){

       cout <<"NUMBER OF ELEMENTS SHOULD BE ODD";

   }

   else if(v.size()>9){

       cout<<"Too many numbers.";

   }

   else{

       cout<<"Median = " << v[v.size()/2]<<endl; //Find median  

   }

       

}

Output:

You might be interested in
If productCost and productPrice are numeric variables, and productName is a string variable, which of the following statements a
VLD [36.1K]
<h2>Question: </h2>

a. productCost = 100

b. productPrice = productCost

c. productPrice = productName

d. productPrice = “24.95”

e. 15.67 = productCost

f. productCost = $1, 345.52

g. product Cost = productPrice − 10

h. productName = “mouse pad”

i. productCost + 20 = productPrice

j. productName = 3-inch nails

k. productName = 43

l. productName = “44”

m.“99” = productName

Answer:

(a) valid

(b) valid

(c) invalid

(d) valid

(e) invalid

(f) invalid

(g) invalid

(h) valid

(i) invalid

(j) invalid

(k) invalid

(l) valid

(m) invalid

Explanation:

(a) valid. Since productCost is a numerical variable, a value of 100 can be assigned to it.

(b) valid. Both productCost and productPrice are numerical variables and as such value of one can be stored in the other.

(c) invalid. productName is a string variable and cannot be directly assigned to productPrice which is a numeric variable.

(d) valid. productPrice is a numeric variable and 24.95 can be assigned to it.

(e) invalid. 15.67 is not a variable name and as such cannot have values assigned to it.

(f) invalid. $ and , are not numeric digits and as such cannot be assigned to productCost which is numeric.

(g) invalid. There should be no space between product and Cost. It should be productCost and not product Cost.

(h) valid. "mouse pad" is a string literal and can be assigned to productName which is a string variable.

(i) invalid. productCost + 20 is not a variable .

(j) invalid. 3-inch nails should be in quotes for it to be assignable to productName.

(k) invalid. 43 is a numeric literal and cannot be directly assigned to productName which is a string variable. In other words, 43 should be in quotes for it to be assignable to productName.

(l) valid. 44 (in quotes) is a string literal and can be assigned to productName which is a string variable.

(m) invalid. "99" is not a variable name and cannot hold or be assigned any value.

7 0
2 years ago
Write a function that takes a string like 'one five two' and returns the corresponding integer (in this case, 152). A function j
Lelu [443]

Answer:

see explaination

Explanation:

def words2number(s):

words = s.split()

numbers = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']

result = ""

for word in words:

if word in numbers:

result += str(numbers.index(word))

return result

4 0
2 years ago
Read 2 more answers
Based on virtualization technologies, how many types can we classify them? Please give a brief statement on each of them?
geniusboy [140]

Answer:

Software and Hardware virtualization.

Explanation:

Virtualization is a process or the ability of a system to run multiple operating systems and virtually using all the physical resources, as though they are individual systems.

Hardware virtualization allows for hardware components like the storage, CPU, memory etc to be virtually used by multiple virtual machines. Software virtualization uses software managers to run individual guest operating systems on virtual machines.

6 0
2 years ago
Find the sum of the squares of the integers from 1 to MySquare, where MySquare is input by the user. Be sure to check that the u
SashulF [63]

Answer:

b

Explanation:

hbjh

7 0
2 years ago
Suppose a host has a 1-MB file that is to be sent to another host. The file takes 1 second of CPU time to compress 50%, or 2 sec
kozerog [31]

Answer: bandwidth = 0.10 MB/s

Explanation:

Given

Total Time = Compression Time + Transmission Time

Transmission Time = RTT + (1 / Bandwidth) xTransferSize

Transmission Time = RTT + (0.50 MB / Bandwidth)

Transfer Size = 0.50 MB

Total Time = Compression Time + RTT + (0.50 MB /Bandwidth)

Total Time = 1 s + RTT + (0.50 MB / Bandwidth)

Compression Time = 1 sec

Situation B:

Total Time = Compression Time + Transmission Time

Transmission Time = RTT + (1 / Bandwidth) xTransferSize

Transmission Time = RTT + (0.40 MB / Bandwidth)

Transfer Size = 0.40 MB

Total Time = Compression Time + RTT + (0.40 MB /Bandwidth)

Total Time = 2 s + RTT + (0.40 MB / Bandwidth)

Compression Time = 2 sec

Setting the total times equal:

1 s + RTT + (0.50 MB / Bandwidth) = 2 s + RTT + (0.40 MB /Bandwidth)

As the equation is simplified, the RTT term drops out(which will be discussed later):

1 s + (0.50 MB / Bandwidth) = 2 s + (0.40 MB /Bandwidth)

Like terms are collected:

(0.50 MB / Bandwidth) - (0.40 MB / Bandwidth) = 2 s - 1s

0.10 MB / Bandwidth = 1 s

Algebra is applied:

0.10 MB / 1 s = Bandwidth

Simplify:

0.10 MB/s = Bandwidth

The bandwidth, at which the two total times are equivalent, is 0.10 MB/s, or 800 kbps.

(2) . Assume the RTT for the network connection is 200 ms.

For situtation 1:  

Total Time = Compression Time + RTT + (1/Bandwidth) xTransferSize

Total Time = 1 sec + 0.200 sec + (1 / 0.10 MB/s) x 0.50 MB

Total Time = 1.2 sec + 5 sec

Total Time = 6.2 sec

For situation 2:

Total Time = Compression Time + RTT + (1/Bandwidth) xTransferSize

Total Time = 2 sec + 0.200 sec + (1 / 0.10 MB/s) x 0.40 MB

Total Time = 2.2 sec + 4 sec

Total Time = 6.2 sec

Thus, latency is not a factor.

5 0
2 years ago
Other questions:
  • Fill in the blank; "As well as their traditional role of computing data, computers are also extensively used for..."
    14·1 answer
  • A data center that is fully automated to the extend that they can run and manage themselves while being monitored remotely are s
    11·1 answer
  • Why is it important for a Support Agent to understand and follow their company’s standardized case lifecycle roadmap? (Select 2)
    12·1 answer
  • Define a function pyramid_volume with parameters base_length, base_width, and pyramid_height, that returns the volume of a pyram
    12·1 answer
  • Given six memory partitions of 300 KB, 600 KB, 350 KB, 200 KB, 750 KB, and 125 KB (in order), how would the first-fit, best-fit,
    11·1 answer
  • Collaboration online increases students' motivation by
    5·2 answers
  • Flesh out the body of the print_seconds function so that it prints the total amount of seconds given the hours, minutes, and sec
    7·1 answer
  • JAVA
    7·1 answer
  • Which of these are characteristics of a Python data type? Check all that apply.
    11·1 answer
  • Which group contains the command to manually conduct a spell check ?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!