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
After Lola gave her friend the password to a protected website, her friend was able to remember it only long enough to type it i
Naily [24]

Answer:

Short term memory

Explanation:

Is the capacity an individual has to hold on to a small amount of information for a short period of time without altering it, it is used to remember information like phone numbers, passwords etc. It is also known as primary or active memory.

If short time memories is not rehearsed, they don't last and are easily forgotten, they actually last for about 20-30 seconds.

Aspects of short term memory :

1. Limited capacity : in a short term memory at most 7 items can be stored at a time.

2. Limited capacity : information is short lived and can be lost through distraction and with time.

3. Encoding.

4 0
3 years ago
How are special characters added to a Word document? Check all that apply.
Musya8 [376]

Answer:

by using keystroke codes

by using the character map

by using the Symbols command group

by using the Symbol drop-down arrow

6 0
3 years ago
Read 2 more answers
Yo, my Lenovo laptop keeps showing this screen but I can't sign in, can someone help me?
rusak2 [61]
Break your laptop and get a new one
8 0
3 years ago
Read 2 more answers
WRITE A JAVA PROGRAM TO PRINT THE PATTERN<br> 13579<br> 2468<br> 357<br> 46<br> 5
Inessa05 [86]

Answer:

import java.util.Scanner;

import java.lang.*;

class Main

{

  public static void main(String args[])

  {

     int n;

     //For capturing the value of n

     Scanner scanner = new Scanner(System.in);

     System.out.println("Enter the value of n:");

     //The entered value is stored in the var n

     n = scanner.nextInt();

     int k=1;

     printnum(n,k);  

  }

  public static void printnum(int n,int k)

  {

       if(n%2==0)

       {

       for(int i=k;i<=n-1;i=i+2)

            {

                System.out.print(i);

            }    

        System.out.println("");

       }

       else

        {

       for(int i=k;i<=n-1;i=i+2)

            {

                System.out.print(i);

            }    

        System.out.println("");

        }

      n--;

      if(n<=1)

      {

         System.exit(0);

      }

      else

      {

          printnum(n,k+1);

      }

   }

}

Explanation:

The program is self explanatory.

4 0
3 years ago
It is a good practice to use 3d to plot a single dimensional data in storytelling.
Brums [2.3K]

Answer:

The answer is "Option B".

Explanation:

The 3-dimensional diagrams also known as a 3D graph, it implies to 3D design, which Occasionally receives the 2D data, which effects 3D and It is a terrible form.

  • The whole additional dimension comes to an end but never more than inserting a chart or its readability could be dramatically affected.
  • It uses the 3D to create a single dimension, but the information is not a great training.
6 0
3 years ago
Other questions:
  • 3. If B3=6 and D5=8, what would the following function return? IF(B3&gt;D5, "Closed", D5-B3) *
    10·2 answers
  • Which Of The Following Is A College Major For Which IT Courses Would Most Likely Be Required?
    9·1 answer
  • What do yo need to do for device manager to display nonpresent devices?
    9·1 answer
  • To determine what to study, one should first
    8·1 answer
  • What type of device does a computer turn to first when attempting to make contact with a host with a known IP address on another
    9·2 answers
  • Your mom wants to purchase a computer. She has heard about how the Windows 8 operating system is best-geared for a touch-enabled
    10·2 answers
  • Ex: If the input is: Pat Silly Doe the output is: Doe, P.S.
    9·1 answer
  • ITS MAKING ME TYPE URL CODES NOW!
    6·1 answer
  • A class is a _____, which encapsulates _____ and _____. (Points : 2) programming language construct; attributes; behavior
    7·1 answer
  • Is monitor is a television​
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!