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
Studentka2010 [4]
2 years ago
7

Write a program second.cpp that takes in a sequence of integers, and prints the second largest number and the second smallest nu

mber. 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 .
Computers and Technology
1 answer:
sergey [27]2 years ago
4 0

Answer:

The program is as follows:

#include <iostream>

#include <vector>

using namespace std;

int main(){

   int n;

   cout<<"Elements: ";

   cin>>n;

   vector <int>vectnum;

   int numInp;

   for (int i = 1; i <= n; i++){        cin>>numInp;        vectnum.push_back(numInp);    }

   int big, secbig;

   big = vectnum.at(0);      secbig = vectnum.at(1);

   if(vectnum.at(0)<vectnum.at(1)){     big = vectnum.at(1);  secbig = vectnum.at(0);   }

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

     if (vectnum.at(i) > big) {

        secbig = big;;

        big = vectnum.at(i);

     }

     else if (vectnum.at(i) > secbig && vectnum.at(i) != big) {

        secbig = vectnum.at(i);

     }

  }

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

  int small, secsmall;

  small = vectnum.at(1);       secsmall = vectnum.at(0);

  if(vectnum.at(0)<vectnum.at(1)){ small = vectnum.at(0);  secsmall = vectnum.at(1);   }

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

     if(small>vectnum.at(i)) {  

        secsmall = small;

        small = vectnum.at(i);      }

     else if(vectnum.at(i) < secsmall){

        secsmall = vectnum.at(i);      }   }

  cout<<"Second Smallest: "<<secsmall;

  return 0;

}

Explanation:

See attachment for explanation

Download cpp
You might be interested in
•Should other states wait to see if the high-speed rail system works well before starting their own plans for similar systems?
solmaris [256]
Other states should see how well the system works and also understand how much money it requires for the state to build a high-speed rail system.
7 0
3 years ago
If not cleared out, log files can eventually consume a large amount of data, sometimes filling a drive to its capacity. If the l
OLEGan [10]

Answer:

<u>/var</u>

Explanation:

The /var subdirectory contains files to which the system writes data during the course of its operation. Hence, since it serves as a system directory, it would prevent log files from consuming a large amount of data.

7 0
2 years ago
Read 2 more answers
Universal Containers has a requirement to integrate Salesforce with an external system to control record access. What option sho
Inessa05 [86]

Answer:

C. Use the SOAP API to maintain the related SObject_share records

8 0
3 years ago
If anyone plays pokemon go put your code below.
Cerrena [4.2K]
Yeah my pokémon is not my mom hung bye
4 0
2 years ago
Read 2 more answers
On a Linux system it is considered bad manners to create files and folders in the _______________ directory.
guapka [62]

Answer:

Root

Explanation:

Linux is an open source operating system which receives command from the user and communicates with the hardware, and in Linux the root directory is the top level directory that contains all other directory, it is not recommended to create files and folders in  the root directory because the commands the user enters may change files that the operation system may depend on for usage.

5 0
3 years ago
Other questions:
  • Which wildcat character will return a single character when using the find dialog box
    14·1 answer
  • What Event is called when an Object collides with an non-trigger collider?
    13·1 answer
  • What happens if you give false information on your driver license application?
    12·1 answer
  • Drag the tiles to the correct boxes to complete the pairs.
    13·1 answer
  • Given a constant named size with a value of 5, which statement can you use to define and initialize an array of doubles named ga
    12·1 answer
  • What is the function for displaying differences between two or more scenarios side by side?
    11·2 answers
  • Pick one of the following scenarios and
    6·1 answer
  • How will you maintain electrical tools and equipment?
    12·2 answers
  • What is ‘situational awareness” in game design?please answer in a full sentence!
    10·1 answer
  • While working in a group of two the members are not getting along. You bring the two members together so they can discuss this i
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!