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
Which one is correct?
VashaNatasha [74]

The top right answer

8 0
2 years ago
Read 2 more answers
Digital art is created by using
enyata [817]

Answer:

D. Computers

Explanation:

Digital art is when you make art on electronic devices.

8 0
2 years ago
6. What is the difference between portrait and landscape orientation? What are the advantages of
vlabodo [156]

Answer:

PORTRAIT ORIENTATION IS VERTICAL AND LANDSCAPE ORIENTATION IS HORIZONTAL

Explanation:

PORTRAIT SETTING CAN BE USED TO DESCRIBE MEANINGS OF LETTERS IN A WORD LANDSCAPE CAN BE USED TO DIFFERENTIATE  BETWEEN WORDS MEANINGS                                                                                                                                            

3 0
3 years ago
What are the benefits of using an ordered list vs. an unordered list? What are the costs?
Rashid [163]

Answer:

The main benefit of the ordered list is that you can apply Binary Search( O( n log n) ) to search the elements. Instead of an unordered list, you need to go through the entire list to do the search( O(n) ).

The main cost of the ordered list is that every time you insert into a sorted list, you need to do comparisons to find where to place the element( O( n log n) ). But, every time you insert into an unsorted, you don't need to find where to place the element in the list ( O(1) ). Another cost for an ordered list is where you need to delete an element, you have an extra cost rearranging the list to maintain the order.

6 0
2 years ago
If an occupation is projected to decline by 7% over the next 10 years, how would you rate the job outlook?
Helen [10]
Steady sounds like the best answer but that’s tough
5 0
2 years ago
Other questions:
  • You've decided to use a subnet mask of 255.255.192.0 with your 172.17.0.0 network to create four separate subnets. The network I
    13·1 answer
  • The cost of large ground based telescopes has remained the same since the 1800's costing the equivalent of about a billion dolla
    9·1 answer
  • Technologies designed to replace operating systems and services when they fail are called what?
    15·1 answer
  • As the network engineer, you are asked to design an IP subnet plan that calls for three subnets. The largest subnet needs a mini
    14·1 answer
  • You have created a new dhcp scope with address range 192.168.1.1 to 192.168.1.254. you have five servers configured with static
    9·1 answer
  • The function of the __________ is to on transmission assemble data into a frame, on reception disassemble frame and perform addr
    8·1 answer
  • Qwertyuiopasdfghjklzxcvbnm??
    14·2 answers
  • Which class members should be declared as public?
    12·1 answer
  • Do OBS mic filters apply everywhere? Such as discord and other apps similar. Or is it just on streaming?
    15·1 answer
  • Consider the following implementation of a search method:
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!