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