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
An ideal line length would include how many characters? A. 6570 B. 100 C. 100125 D. 4055
pav-90 [236]

B 100

Hop this helps

Please mark me as brainliest

5 0
3 years ago
How does the use of the computer impact businesses
Andre45 [30]
Computers can help organize the workplace and it can also help communications between work members. This is the vague explanation of how it impacts businesses. However, different businesses have different uses for computers and other technologies.
7 0
2 years ago
Explain the steps users can take to maintain an operating system
Mars2501 [29]

First is it to always clean out all the junk that is left behind by the operating system and the browsers. You can easily do this using the Disk Cleanup utility included on the windows systems. You can clean up the registry. However, you should be very careful with the registry. Any wrong move might mess up everything


Search and destroy viruses and malware on your PC by installing an anti-virus security program and setting up an automated maintenance schedule.


Defragment main and partitioned drives to keep your computer running smoothly.


Uninstall software programs and personal files like pictures, movies and music that are no longer in use to free up more space. The more the space, the faster the PC will go. You can also run the msconfig command in the RUN command prompt to uncheck start up programs that you do not use

4 0
3 years ago
which tag does not display the text in the browser window and makes the sources code mode readable ?​
maxonik [38]

Answer:

HTML comments are not displayed in the browser, but they can help document ... You can add comments to your HTML source by using the following syntax: <! ... you can comment out HTML lines of code, one at a time, to search for errors: ... Use the HTML comment tag to make a comment out of the "This is a comment" text.

Explanation:

Gimme brainliest right now.

3 0
3 years ago
Hw to gain more knowledge ​
LenaWriter [7]

Answer:

Read Books, Search the Internet, etc...

Explanation:

6 0
3 years ago
Other questions:
  • Social networking sites like Office Online, PayPal, and Dropbox are used to develop social and business contacts.
    6·2 answers
  • The four functions of a computer are
    5·1 answer
  • Universal Containers is implementing a community of High-Volume Community users. Community users should be able to see records a
    12·1 answer
  • Sulfur content is measured in
    11·1 answer
  • 2. Integer plot function (find a smart way to code big integers) Write a program BigInt(n) that displays an arbitrary positive i
    8·1 answer
  • Using C, Write a program that reads a series of strings from standard input and prints only those strings beginning with the let
    8·1 answer
  • GRAND THEFT AUTO 5 LOLLL
    15·2 answers
  • What is the difference between php and html?​
    13·2 answers
  • Radio spectrum is the part of the complete range of electromagnetic waves that is used for radio communication from
    14·1 answer
  • Briefly describe the working of computer processing system?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!