Vector, random numbers and reverse copy. In this assignment, the student will write several C++ functions,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Vector, random numbers and reverse copy. In this assignment, the student will write several C++ functions, to support a program that generates random integers, store them in a STL vector, and reverse copy the contents to another vector, then print them out. You are provided a main() function and a makefile for this assignment for your local testing. (Note that not all assignments will provide main() and makefile. You may be expected to write your own main() and makefile in some cases.) This assignment will be submitted via the autograder. You will implement the required functions in the file solutions.cc, and submit that file to the autograder. You should feel free to create whatever files you want to test things locally, including writing your own simple programs to test small parts on their own, but your submission should only include the required code. Specifications You need to implement the following functions: 1. void gen_rnd_nums (vector < int>& v, int seed, int range_limit, int vec_size); This function generates vec_size integers and puts them in the vector v. Do not assume the vector has been pre-allocated enough space. Do not assume the vector passed in was empty. So you need to clear the contents first, and then use push_back() to add the generated numbers. Or you can resize the vector before you assign values. Because this is an early assignment for the semester, you are not required to use iterators to work with the vector (but you can do so if you prefer). You will generate random integers in the range of [ LOW = 1, HIGH = range_limit ]. You need to initialize the random number generator by calling the function srand () with the provided seed value. You only need to seed the random number generator once. You can then generate random integers by calling the function rand() multiple times. The function rand() gives a random number between 0 and RAND_MAX (a very large number defined by the system), inclusive. You need to figure out how to get a random number in the range of [1, range_limit] inclusive. Hint: use modulus. 2. int reverse_copy(vector < int>& v1, vector < int>& v2); Check the size of the two vectors and return -1 if not the same. Then copy the contents of v1 into v2, in reserve order. 3. void print_vec (const vector & v, int items_per_row, int item_width); This function displays the contents of vector v on stdout, printing exactly items_per_row on a single line, except perhaps the last line. The numbers need to be properly aligned on the output. For each printed number, allocate the width of each element on stdout based on the argument item_width. See std::setw for details. Print a newline after you print the entire vector. (Note that the auto-grader may be strict when comparing the outputs you need to examine the format in addition to the contents.) Vector, random numbers and reverse copy. In this assignment, the student will write several C++ functions, to support a program that generates random integers, store them in a STL vector, and reverse copy the contents to another vector, then print them out. You are provided a main() function and a makefile for this assignment for your local testing. (Note that not all assignments will provide main() and makefile. You may be expected to write your own main() and makefile in some cases.) This assignment will be submitted via the autograder. You will implement the required functions in the file solutions.cc, and submit that file to the autograder. You should feel free to create whatever files you want to test things locally, including writing your own simple programs to test small parts on their own, but your submission should only include the required code. Specifications You need to implement the following functions: 1. void gen_rnd_nums (vector < int>& v, int seed, int range_limit, int vec_size); This function generates vec_size integers and puts them in the vector v. Do not assume the vector has been pre-allocated enough space. Do not assume the vector passed in was empty. So you need to clear the contents first, and then use push_back() to add the generated numbers. Or you can resize the vector before you assign values. Because this is an early assignment for the semester, you are not required to use iterators to work with the vector (but you can do so if you prefer). You will generate random integers in the range of [ LOW = 1, HIGH = range_limit ]. You need to initialize the random number generator by calling the function srand () with the provided seed value. You only need to seed the random number generator once. You can then generate random integers by calling the function rand() multiple times. The function rand() gives a random number between 0 and RAND_MAX (a very large number defined by the system), inclusive. You need to figure out how to get a random number in the range of [1, range_limit] inclusive. Hint: use modulus. 2. int reverse_copy(vector < int>& v1, vector < int>& v2); Check the size of the two vectors and return -1 if not the same. Then copy the contents of v1 into v2, in reserve order. 3. void print_vec (const vector & v, int items_per_row, int item_width); This function displays the contents of vector v on stdout, printing exactly items_per_row on a single line, except perhaps the last line. The numbers need to be properly aligned on the output. For each printed number, allocate the width of each element on stdout based on the argument item_width. See std::setw for details. Print a newline after you print the entire vector. (Note that the auto-grader may be strict when comparing the outputs you need to examine the format in addition to the contents.)
Expert Answer:
Related Book For
Posted Date:
Students also viewed these algorithms questions
-
Python and most Python libraries are free to download or use, though many users use Python through a paid service. Paid services help IT organizations manage the risks associated with the use of...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
Write a C++ program with recursion to print the following pattern for any odd number greater than or equal to 5. Note: the last row must be filled with digits from your ID in case the pattern is...
-
When one material is rubbed against another, electrons jump readily from one to the other but protons do not. Why is this? (Think in atomic terms.)
-
In your audit of Aviary Industries for calendar year 2019, you found a number of matters that you believe represent possible adjustments to the companys books. These matters are described below....
-
The components of a velocity field are given by \(u=x+y\), \(v=x y^{3}+16\), and \(w=0\). Determine the location of any stagnation points \((\mathbf{V}=0)\) in the flow field.
-
The adjusted trial balance for Matthews Corporation at the end of the current year contained the following accounts. Interest Payable .......... $ 9,000 Lease Liability .......... 59,500 Bonds...
-
Write an equation for a rational function with: Vertical asymptotes at x = 1 and x = -3 x-intercepts at x= -6 and x = 6 y-intercept at 7
-
The production manager at a factory manufacturing four types of light fittings (A, B, C and D) on an automated machine is fixing the schedule for the next week on this machine. HEIJUNKA SCHEDULING OF...
-
When preparing for the annual meeting of shareholders and the discussion of Radiation Shields (RS) Inc.s performance in 2011, Shields wondered how to resolve his fellow shareholders concerns that...
-
For the current fiscal year, Purchases were $187,000, Purchase Returns and Allowances were $4,200 and Freight In was $10,500. If the beginning merchandise inventory was $98,000 and the ending...
-
The six-month interest rate (annualized) in Rwanda and Kenya is 11% and 2% respectively. The current exchange rate is Rwanda Francs (RF) 296.10/Ksh.1 and the six-month forward rate is RF...
-
Mariah Lucas is restructuring the budget process at her company, Lucas Lodging, Inc. She envisions a budget process driven by management and lower-level employees, but aligned with the company's...
-
Name and describe three reasons to engage in counseling or therapy from the perspective of the client. How can counseling microskills support or be utilized in counseling, therapy, general...
-
Imagine that there are 100MM people in the labor force. Currently 3.4MM of those people are in-between jobs. Another 1.5MM (of those 100MM) have been unemployed for more than half-a-year (and we...
-
If the orbital motion of an electron results in a magnetic field at the center of the nucleus of the order of 10 gauss, what is the amount of splitting in the case of hyperfine structure of the...
-
A number of years ago the United Food and Commercial Workers Union organized 800 workers of the 1035 employees at one of the Wilson Brothers food operations in Toronto, Ontario. The employees include...
-
The concentration of a drug in the body CP can be modeled by the equation: Cp = DG/Vd (ka/ke ka)(eket eket) where DG is the dosage administered (mg), Vd is the volume of distribution (L), ka is the...
-
A parametric equation is given by x = sin(t)cos(t), y = 1 .5cos(t) Plot the function for < t
-
The stresses fields near a crack tip of a linear elastic isotropic material for mode I loading are given by: For K1 = 300 ksiin plot the stresses (each in a separate figure) in the domain 0 cos|-| |...
-
In March 2015, a Nielsen global online survey "found that consumers are increasingly willing to pay more for socially responsible products." Over 30,000 people in 60 countries were polled about their...
-
Proportion of US adults who own a cell phone. In a survey of 1006 US adults in 2014, 90% said they had a cell phone. Give the correct notation for the quantity described and give its value.
-
One of the many wonderful things about studying statistics is that graduate programs in statistics often pay their graduate students, which means that many graduate students in statistics are able to...
Study smarter with the SolutionInn App