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]
1 year 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]1 year 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
3.34 LAB: Mad Lib - loops in C++
Ganezh [65]

Answer:

A Program was written to carry out some set activities. below is the code program in C++ in the explanation section

Explanation:

Solution

CODE

#include <iostream>

using namespace std;

int main() {

string name; // variables

int number;

cin >> name >> number; // taking user input

while(number != 0)

{

// printing output

cout << "Eating " << number << " " << name << " a day keeps the doctor away." << endl;

// taking user input again

cin >> name >> number;

}

}

Note: Kindly find an attached copy of the compiled program output to this question.

7 0
2 years ago
In this lab, you use the pseudocode in figure below to add code to a partially created Python program. When completed, college a
Elza [17]

Answer:

Python code is given below with appropriate comments

Explanation:

#Prompt the user to enter the test score and class rank.

testScore = input()

classRank = input()

#Convert test score and class rank to the integer values.

testScore = int(testScore)

classRank = int(classRank)

#If the test score is greater than or equal to 90.

if(testScore >= 90):

   #If the class rank is greater than or equal to 25,

   #then print accept message.

   if(classRank >= 25):

       print("Accept")

   

   #Otherwise, display reject message.

   else:

       print("Reject")

#Otherwise,

else:

   #If the test score is greater than or equal to 80.

   if(testScore >= 80):

       #If class rank is greater than or equal to 50,

       #then display accept message.

       if(classRank >= 50):

           print("Accept")

       

       #Otherwise, display reject message.

       else:

           print("Reject")

   

   #Otherwise,

   else:

       #If the test score is greater than or equal to

       #70.

       if(testScore >= 70):

           #If the class rank is greater than or equal

           #to 75, then display accept message.

           if(classRank >= 75):

               print("Accept")

           

           #Otherwise, display reject message.

           else:

               print("Reject")

       

       #Otherwise, display reject message.

       else:

           print("Reject")

4 0
2 years ago
Which phrase best describes a scenario in Excel 2016?
Airida [17]

Answer:

what are the phrases?

Explanation:

6 0
2 years ago
Get user input as a boolean and store it in the variable tallEnough. Also, get user input as a boolean and store it in the varia
frozen [14]

Answer:

I will code in JAVA.

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

 

boolean tallEnough;

boolean oldEnough;

Scanner input = new Scanner(System.in);

tallEnough = input.nextBoolean();<em> //wait the input for tallEnough</em>

oldEnough = input.nextBoolean(); <em>//wait the input for OldEnough</em>

   if(tallEnough && oldEnough){

   System.out.print(true);

   } else {

   System.out.print(false);

   }

}

}

Explanation:

First, to accept user inputs you have to import the class Scanner. Then declare both variables before allowing the user to set input values for both boolean variables.

In the if-else statement checks if both variables are true, then prints true. Another case prints always false.

8 0
2 years ago
What makes you normally visit the site-graphics, layout, or content? Why?​
Vinvika [58]

Answer:

robux

Explanation:

robux

8 0
1 year ago
Read 2 more answers
Other questions:
  • 3. Of the following pieces of information in a document, for which would you most likely insert a mail merge field? A. First nam
    13·2 answers
  • Two technicians are discussing lung protection in the shop. Technician A says that respiratory-protection devices can prevent yo
    5·2 answers
  • A(n) ______close to a cover letter leads to more interviews because you are contacting the employer. a. passive b. lengthy c. ac
    11·2 answers
  • All the employees of Delta Corporation are unable to access the files stored in the server. What do you think is the reason behi
    14·1 answer
  • When trying to improve performance of a slow system, you notice in Task Manager that the superfetch service is using a high perc
    11·1 answer
  • "online privacy alliance (opa) is an organization of companies dedicated to protecting online privacy. members of opa agree to c
    15·1 answer
  • In a ____________________ attack, the attacker sends a large number of connection or information requests to disrupt a target fr
    14·1 answer
  • ANSWER AS SOON AS POSSIBLE: When I try to join roblox adopt me it says: "Roblox Datastore servers are currently down. Please rej
    10·2 answers
  • Cloud storage refers to the storage of data on ______.a. your mobile device.b. your desktop computer.c. an external drive.d. a s
    7·1 answer
  • When should a developer begin thinking about scalability? 1 during the design phase 2during testing 3when traffic increases by 2
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!