Concept explainers
Write a sorting function that is similar to Display 7.12 in Chapter 7 except that it has an argument for a vector of ints rather than an array. This function will not need a parameter like numberUsed as in Display 7.12, since a vector can determine the number used with the member function size(). This sort function will have only this one parameter, which will be of a vector type. Use the selection sort
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
Electric Circuits. (11th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
- Write a function numberOfOccurences() which takes an integer reference array of size 10 and a search value as parameters and returns the number of occurrences of the value inside the array. Test your function. Initialize an array that contains the following numbers: 4, 7, 2, 8, 8, 1, 4, 8, 9, 1. Then test it with search values 1, 8 and 6. Your program output should look like the following: [4 7 2 8 8 1 4 8 9 1 ]1 occurs 2 times in the array.8 occurs 3 times in the array.6 occurs 0 times in the array. C++ Nothing too advanced pleasearrow_forwardModify from the code below, add an additional input from the use input to get how many random integers to create. Use a vector<int> instead of an int array to store the random integers. Function prototypes: void showValues(const vector<int>&); void fillVector(vector<int>&, int, int); int maximum(const vector<int>&); int minimum(const vector<int>&); double average(const vector<int>&); bool searchValue(const vector<int>&, int); Code: #include <iostream>#include <iomanip>#include <cstdlib>#include <ctime>using namespace std; // Function prototypevoid showValues(const int[], int); void fillArray(int[], int, int, int); int maximum(const int[], int); int minimum(const int[], int); double average(const int[], int); int main(){const int ARRAY_SIZE = 10;int numbers[ARRAY_SIZE];srand(time(0));int low = 0, high = 1;cout << "**This program will generate 10 random integers between [low] and…arrow_forwardUsing JavaScriptDefine a function getMonth which accepts number from 1 to 12 as an argument and return the descriptive name of the month. For example: getMonth(1) should return January while getMonth(12) returns December, finally getMonth(-1) returns null. Use array or object to define a list of names for the month and refrain from using if statement to check the argument if it's 1, 2, etc.arrow_forward
- You are working for a university to maintain a list of grades and some related statistics for a student. Class and Data members: Create a class called Student that stores a student’s grades (integers) in a vector (do not use an array). The class should have data members that store a student’s name and the course for which the grades are earned. Constructor(s): The class should have a 2-argument constructor that receives the student’s name and course as parameters and sets the appropriate data members to these values. Member Functions: The class should have functions as follows: Member functions to set and get the student’s name and course variables. A member function that adds a single grade to the vector. Only positive grades are allowed. Call this function AddGrade. A member function to sort the vector in ascending order. A member function to compute the average (x̄) of the grades in the vector. The formula for calculating an average is x̄ = ∑xi / n where xi is the value of each…arrow_forwardYou are working for a university to maintain a list of grades and some related statistics for a student. Class and Data members: Create a class called Student that stores a student’s grades (integers) in a vector (do not use an array). The class should have data members that store a student’s name and course for which the grades are earned. Constructor(s): The class should have a 2-argument constructor that receives the student’s name and course as parameters and sets the appropriate data members to these values. Member Functions: The class should have functions as follows: Member functions to set and get the student’s name and course variables. A member function that adds a single grade to the vector. Only positive grades are allowed. Call this function AddGrade A member function to sort the vector in ascending order. A member function to compute the average (x̄) of the grades in the vector. The formula for calculating an average is x̄ = ∑xi / n where xi is the value of each…arrow_forwardCreate a function that returns the frequency distribution of an array. This function should return an object, where the keys are the unique elements and the values are the frequency in which those elements occur. Examples get Frequencies (["A", "B", "A", "A", "A"]) → { A: 4, B: 1 } get Frequencies ([1, 2, 3, 3, 2]) → { "1": 1, "2": 2, "3": 2 } get Frequencies ([true, false, true, false, false]) { true: 2, fal →arrow_forward
- Using C++ Implement the ordered version of removeElement in the window below. Your function should validate inputs and remove the element in the given position by moving all of the other elements down. // removeElement preserves the order of the remaining elements in the array.// @param: char array that is ordered in some way.// @param: int numElems is the number of elements// @param: int position of the element being removed// @returns true if the element is removed, false otherwise.// be careful to use reference parameters where necessary!arrow_forwardCould you correct the errorarrow_forwardImplement a sort function using a vector. * Ask the user to enter numbers to be sorted. Add them to the vector. The user will signal the end of input by giving you a negative number. Because this is a vector, you don’t need to pass the number of entries in the vector. Then, print out the vector in order. An example run of the program is shown below:arrow_forward
- C++arrow_forwardin c++, use parallel arrays , and srand(time(NULL)) to randomize the two cards dealt at the start Create a Blackjack (21) game. Your version of the game will imagine only a SINGLE suit of cards, so 13 unique cards, {2,3,4,5,6,7,8,9,10,J,Q,K,A}. Upon starting, you will be given two cards from the set, non-repeating. Your program MUST then tell you the odds of receiving a beneficial card (that would put your value at 21 or less), and the odds of receiving a detrimental card (that would put your value over 21). Recall that the J, Q, and K cards are worth ‘10’ points, the A card can be worth either ‘1’ or ‘11’ points, and the other cards are worth their numerical values.arrow_forwardWrite a program that declares/intializes two arrays as described in main() and has two functions. main() - The size of both arrays is 5. The first array has elements of type double. The values are for distance measurements. Choose a descriptive name for this array.The second array will have the unit of measure. Choose a descriptive name for this array. Initialize the first 4 elements using an initialization list with the values "mi", "mi", "km", "km". Assign a new value to the first element of the second array: "km"Assign a value to the last element of the second array: "mi" Use a loop with statement that ask the user to type in all of the values for the temperatures and assign them to the first array. Function calls in main() -- you might want to write the definitions first (or at least read about them) before coming back to main() to write the calls. call the function that prints the measurements along with the unit of measure.Call the function that can count the number of…arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT