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
Help me i'll brainiest if its right
Dominik [7]

Answer:

Your response is correct.

I hope this helped at all.

4 0
2 years ago
Read 2 more answers
Vannevar bush imagined a desktop computing machine that would allow people to access data stored in various information centers
Bas_tet [7]
I'm pretty sure it is A) Memex.
5 0
3 years ago
The Internet began when a large company wanted to sell products online
aalyn [17]
No!The internet began in the 1950s when the US government was trying to use connected computers to compete with the Soviet Union's Sputnik. Hope this helps :)
6 0
2 years ago
Why might you need to convert a file to another file type
Alex17521 [72]
This depends on what program you're using. Some programs can only read certain files exclusive to that program, such as .psd files can usually only be read in Photoshop or other adobe programs. Many fields of work (Journalism, the Arts, Design, etc.) ask for .psd files to be converted to either .png, .jpg, or .tiff so that it can be seen on many other platforms.

For images especially, files are more compatible either on a program or printed. for example, .png files are good for storing color data from computer to computer, but if you print a .png file, the quality is poor. hence it's recommended to save files you want to print for designs as .jpeg, because .jpeg can more easily be printed and will then be presented at a high quality.

Sometimes color quality changes depending on CMYK as well but that's a whole other ball of wax.
8 0
3 years ago
You have 5 salespersons who work out of your office and who frequently leave their laptops laying on their desk in their cubicle
kati45 [8]

There are different ways to ensure safety of devices. The best protection to implement to address your concerns is to use cable locks to chain the laptops to the desks.

  • The use of laptop locks is as good as when compared to bicycle chain locks. One can do this by looking for a big, immovable object, such as one's desk, and thereafter you wrap the metal cable around it and then insert the lock into your laptop's lock slot.

With this, your computer becomes theft-proof.

Thia will give you piece of mind as you will not be restless anymore.

Learn more about Laptop security from

brainly.com/question/24956493

3 0
2 years ago
Other questions:
  • Sam wanted to open a file that he saved yesterday. Which component inside the computer stores this file? the hard drive the fax
    13·2 answers
  • Prior to the development of e-commerce, web sites primarily delivered static html pages. true
    11·1 answer
  • Which of the following illustrates the proper declaration of a variable and data type to hold a whole number?
    13·1 answer
  • Which of the following branches of government is NOT involved in Discretionary Fiscal Policy?
    8·1 answer
  • A thin red border indicates the active cell. (True or False)
    12·1 answer
  • How did you generate a random number for the user to guess?
    9·1 answer
  • As marketing manager, you need to have ( blank) skills and (blank) skills.
    11·1 answer
  • Differentiate between perfect and imperfect market​
    14·1 answer
  • Which statement about analog and digital images is true?.
    15·1 answer
  • Task 2
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!