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
Which option is used in Access to locate and retrieve data that may be present in multiple database tables within the database?
rosijanka [135]

Answer:

subroutines

Explanation:

subroutines is used in access to locate and retrieve data

5 0
3 years ago
in a particular factory, a team leader is an hourly paid production worker who leads a small team. in addition to hourly pay, te
malfutka [58]

Facilitate team development for successful project completion. Through coaching and mentoring, provide teammates with technical leadership.

Establishing best practices and habits will help the team maintain high standards for the quality of its software. Identify and promote the team's potential development and improvement areas.

#include<iostream>

using namespace std;

/*C++ Function to print leaders in an array */

void printLeaders(int arr[], int size)

{

  for (int i = 0; i < size; i++)

   {

       int j;

       for (j = i+1; j < size; j++)

       {

           if (arr[i] <=arr[j])

               break;

       }  

       if (j == size) // the loop didn't break

           cout << arr[i] << " ";

 }

}

/* Driver program to test above function */

int main()

{

   int arr[] = {16, 17, 4, 3, 5, 2};

   int n = sizeof(arr)/sizeof(arr[0]);

   printLeaders(arr, n);

   return 0;

}

Learn more about Development here-

brainly.com/question/28011228

#SPJ4

7 0
1 year ago
Opposite word of reassembling​
Marysya12 [62]
<h3>OPPOSITE WORDS OF REASSEMBLING</h3>

  • disperse
  • disband
  • separate
8 0
3 years ago
Read 2 more answers
Why did some people not like the arrival of machines?
Ahat [919]
People are concerned about losing their jobs. The industrial revolution introduced machines that removed the need for humans to be involved in highly repetitive tasks.
3 0
3 years ago
What is the name of the unique identifier assigned to any personal computer that is connected to the internet?
Stolb23 [73]
There is no truly unique identifier assigned to a PC. Any appearance of a unique ID is merely an illusion. The closest thing there is to a unique identifier is a MAC address, which is actually assigned to a network adapter (Ethernet port, wireless radio, etc.) and is usually unique but can be faked
7 0
3 years ago
Other questions:
  • Which of the following was the first commercial software package to incorporate WYSIWYG as a feature?
    15·1 answer
  • A ____ is text and graphics that print at the bottom of every page.
    12·1 answer
  • Of the following common metals which has the highest conductivity rating?
    7·2 answers
  • 1. If you are 15% years old, you are old enough to obtain
    10·2 answers
  • 5. Drawing Conclusions If you were a person in
    10·1 answer
  • While performing disk and file maintenance on the company file server, you determine a user in the accounting department has bee
    13·2 answers
  • Which element can be changed using the Print pane? Check all that apply.
    9·2 answers
  • This Is My Humor 0w0
    10·1 answer
  • Which of the following describes why graphical interfaces quickly became popular after their introduction to the mass market?
    5·1 answer
  • Read the following statements and select the
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!