Write a program that gets a list of integers from input, and outputs the integers in ascending order (lowest to highest). The first integer indicates how many numbers are in the list. Assume that the list will always contain less than 20 integers.Ex: If the input is:5 10 4 39 12 2the output is:2 4 10 12 39For coding simplicity, follow every output value by a space, including the last one.Your program must define and call the following function. When the SortVector function is complete, the vector passed in as the parameter should be sorted.void SortVector(vector<int>& myVec)#include <iostream>#include <vector>using namespace std;/* Define your function here */int main() {/* Type your code here */return 0;}Please help me with this problem using c++.

Question
Asked Nov 26, 2019
36 views

Write a program that gets a list of integers from input, and outputs the integers in ascending order (lowest to highest). The first integer indicates how many numbers are in the list. Assume that the list will always contain less than 20 integers.

Ex: If the input is:

5 10 4 39 12 2

the output is:

2 4 10 12 39

For coding simplicity, follow every output value by a space, including the last one.

Your program must define and call the following function. When the SortVector function is complete, the vector passed in as the parameter should be sorted.
void SortVector(vector<int>& myVec)

#include <iostream>
#include <vector>
using namespace std;

/* Define your function here */

int main() {
/* Type your code here */

return 0;
}

Please help me with this problem using c++.

check_circle

Expert Answer

star
star
star
star
star
1 Rating
Step 1

Program:

#include<iostream>

#include<vector>

 

using namespace std;

 

void SortVector(vector<int>& myVec)

{

  int n = myVec.size();

  int i, j;

 

  for (i = 0; i < n-1; i++)   

    for (j = 0; j < n-i-1; j++)

      if (myVec[j] > myVec[j+1])

      {

        int temp = myVec[j];

        myVec[j] = myVec[j+1];

        myVec[j+1] = temp;

      }

}

 

int main()

{

  int i, num, value;

 

  cout << "Ente...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: You will write 4 classes for Program 5.  Assignment:The BankAccount class models an account of a cus...

A: Java Program:Filename :- BankAccount.java// Import the required packageimport java.util.Date;// Clas...

question_answer

Q: How do I start creating a program to shuffle and deal a deck of cards?  The program should consist o...

A: Program:Filename: Game.java package deckOfCards;import java.util.Scanner;public class Game {public s...

question_answer

Q: I have the following code:   #include &lt;iostream&gt; #include &lt;cstdlib&gt;   using namespace st...

A: program to find that a number entered by the user is a Fibonacci number or not.This program executes...

question_answer

Q: Write a program in python for a (very) rudimentary shooter "game". You are the only shooter and you ...

A: Source Code# import the required modulesimport randomimport time#Definition of the function shoot()d...

question_answer

Q: 1. Why do we need data structures? Provide an example of each.2. Discuss a mathematical model and im...

A:  Data structure:Data structure is defined as a collection of data values, operations that are perfor...

question_answer

Q: Write a C++ program that computes a student’s grade for an assignment as a percentage given the stud...

A: Instructions for the given program:For the given program, there should exist a file with the name “R...

question_answer

Q: ABC Accounting Company is a company that manages the financials for various small companies on a nat...

A: 1) To prevent remote employees from being hacked, the following steps can be taken:A Virtual private...

question_answer

Q: Describe five components of code, indicating their role in programming. Identify the specific code t...

A: The given HTML code provide the below screenshot.

question_answer

Q: Based on the given block data below, answer the following questions. Hint: First do Google search fo...

A: Q1. (Layer 4) Protocol is:Based on the above input data block result, the Protocol used in layer 4 (...