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
Naya [18.7K]
3 years ago
15

Second Largest, Second Smallest Write a program second.cpp that takes in a sequence of integers, and prints the second largest n

umber and the second smallest number. Note that in the case of repeated numbers, we really mean the second largest and smallest out of the distinct numbers (as seen in the examples below). You may only use the headers: and . Please have the output formatted exactly like the following examples: (the red is user input) Enter integers (Q to quit): 1 2 1 8 8 9 Q Second largest: 8 Second smallest: 2 Enter integers (Q to quit): -7 -101 0 -2 17 Q Second largest: 0 Second smallest: -7
Computers and Technology
1 answer:
Ulleksa [173]3 years ago
3 0

Answer:

The program in C++ is as follows:

#include <vector>

#include <iostream>

using namespace std;

int main(){

   vector <int> my_num;

   string sentinel;

   int n = 0;

   cout<<"Enter integers (Q to quit): ";

   cin>>sentinel;

   while(sentinel != "Q"){

       my_num.push_back(stoi(sentinel));

       n++;

       cin>>sentinel;    }

      int n1, n2;

      n1 = my_num.at(0);      n2 = my_num.at(1);

      if(my_num.at(0)<my_num.at(1)){     n1 = my_num.at(1);  n2 = my_num.at(0);   }

      for (int i = 2; i< n ; i ++) {

          if (my_num.at(i) > n1) {

              n2 = n1;

              n1 = my_num.at(i);     }

           else if (my_num.at(i) > n2 && my_num.at(i) != n1) {

               n2 = my_num.at(i);     }  }

       cout<<"Second Largest: "<<n2<<endl;

       n1 = my_num.at(1);       n2 = my_num.at(0);

       if(my_num.at(0)<my_num.at(1)){ n1 = my_num.at(0);  n2 = my_num.at(1);   }

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

           if(n1>my_num.at(i)) {  

               n2 = n1;

               n1 = my_num.at(i);            }

           else if(my_num.at(i) < n2){

               n2 = my_num.at(i);     }  }

 cout<<"Second Smallest: "<<n2;

 return 0;

}

Explanation:

See attachment for explanation

Download cpp
You might be interested in
How is a WAN different from a LAN?
RSB [31]

<em>A</em><em> </em><em> </em><em>WAn</em><em> </em><em>(</em><em> </em><em>Wide</em><em> </em><em>Area</em><em> </em><em>Network</em><em> </em><em>)</em><em> </em><em>is</em><em> </em><em>made</em><em> </em><em>up</em><em> </em><em>of</em><em> </em><em>LANS</em><em> </em><em>(</em><em> </em><em>Local</em><em> </em><em>Area</em><em> </em><em>Network</em><em>)</em><em>…</em><em>…</em><em>…</em><em>…</em>

4 0
2 years ago
What variation pairs a new employee with an employee who has been with the company for 20 years?
Eva8 [605]

The variation pairs a new employee with an old employee usually focus on employee accomplishments, and criteria that employee meets or not.

<h3>What are the Appraisal Methods used to evaluate an employee's performance?</h3>

The behavioral method is known to be one of the ways to check an employee's actions within a given job.

Conclusively, There is also the use of Comparative methods that tends to compare one employee with different employees. The use of Results methods are the ones that looks into  employee accomplishments.

Learn more about variation pairs from

brainly.com/question/19262673

4 0
2 years ago
Read 2 more answers
What is a conditional Statement that causes the program to change its course​
Deffense [45]

Answer:

In computer science, conditional statements, conditional expressions and conditional constructs are features of a programming language, which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false.

Explanation:

3 0
3 years ago
. When attempting to minimize memory usage, the most efficient way to do group processing when using the MEANS procedure is to u
MrRissso [65]

Answer:

A. the BY statement.

Explanation:

The BY statement aids the procedure MEANS to develop the tree for the current BY group only, thereby analyze the stats, and clean the tree prior to the start and development of the next BY group.

However, without the BY statement, procedure MEANS develops its AVL tree for both the whole file and all sector estimates crossings established in CLASS.

Hence, in this case, the correct answer is the BY Statement.

8 0
3 years ago
Design and implement a set of classes that define various types of reading material: books, novels, magazines, technical journal
tino4ka555 [31]

Answer:

Following are the code to this question:

please find the attached file.

Explanation:

In this code, four class "novels, magazines, technical journals, and textbooks", is defined, in which it holds their respective default constructor and the get and set method to hold the string and integer value, and in the book class the main method is defined, that creates its object and a switch to for search value and print its value.

6 0
3 years ago
Other questions:
  • Design and write an object-oriented program for managing inventory bins in a warehouse. To do this you will use two classes: Inv
    5·1 answer
  • In three to five sentences, describe how technology helps business professionals to be more efficient. Include examples of hardw
    10·1 answer
  • Which is a real-world example of a procedure?
    11·1 answer
  • Which type of malware can hijack internal windows components and often goes undetected because it is already loaded when the ant
    14·1 answer
  • Whats with the bot spamming customer care numbers...kinda annoying when im trying to help people.
    12·1 answer
  • Anyone can help me please ?
    7·1 answer
  • What types of printed information are useful to obtain from your target employers?
    5·1 answer
  • Why do people make Among Us games on Ro-blox, and thousands of people play them, when Among Us is free on all devises?
    10·1 answer
  • 2. The Warren Commission investigated the assassination of President _______________________ in 1964.
    6·1 answer
  • are you in active recovery from a substance use disorder (addiction)? active recovery is defined as being free from an alcohol o
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!