Question: use c++ you must implement the program below. Ground rulers are that you are not allowed to include any additional libraries. Also, to make things
use c++
you must implement the program below. Ground rulers are that you are not allowed to include any additional libraries.
Also, to make things even more fun, you cannot make any new vector or string (if you write something like this std::string x = SOMETHING or if you pass a string or vector to a function by value you are doing something wrong ).
You can write extra functions if you like, and this includes helpers( Hint you are going to want to write extra functions).
//(5 Marks)This function will sort a vector so that the negative number are sorted from smallest to largest, and the positive numbers are sorted from largest to smallest. If v is: //-23 -3 -21 -17 -7 -39 -43 -37 -18 -41 -31 -40 -37 12 7 7 41 12 5 39
//it would look like this when the function is done
//-43 -41 -40 -39 -37 -37 -31 -23 -21 -18 -17 -7 -3 41 39 12 12 7 7 5 //
Note you can assume that v is separated and mid is either the last negative number or the first positive number //
Input v is a separated list of numbers //
Output v with its positive and negative parts sorted
void my_sort(std::vector & v,int mid);
//(5 Marks)This function will separate the vector so all the negative numbers and zero are on the left and the positive numbers are on the right.
If v is: //-37 -3 -21 5 -7 -39 -43 -37 41 7 12 -40 -31 -41 -18 7 -17 12 -23 39
//it leave like this
//-23 -3 -21 -17 -7 -39 -43 -37 -18 -41 -31 -40 -37 12 7 7 41 12 5 39
// Input v is the vector of numbers /
/Output v with all the negative numbers are on the left, and the positive numbers are on the right.
It returns the position of the last negative number or the position of the first positive number
//(1 Mark) What is the running time of your function when n is the length of the vector int sep(std::vector & v);
//(2 Marks)This is a RECURSIVE function that makes a vector of random integers between the number -50 to 50 inclusive.
// Input a vector to be filled and the length of the vector
// Output a random vector void fill_vector(std::vector & v, int len);
//(5 Marks)This function will find all the absolute numbers that are in both the negative and positive parts of a vector and put those numbers into merge_v. If s is:
//-43 -41 -40 -39 -37 -37 -31 -23 -21 -18 -17 -7 -3 41 39 12 12 7 7 5 //then merge_v would be
//41 39 7.
// Input v with all the negative numbers are on the left, and the positive number are on the right.
Mid is the position of the last negative number or the position of the first positive number
// Output merge_v an ordered list of the absolute numbers in v that are in both the negative and positive parts.
//(3 Marks) This is a RECURSIVE function that will print the sum of negative and position numbers
//if v is // -43 -41 -40 -39 -37 -37 -31 -23 -21 -18 -17 -7 -3 41 39 12 12 7 7 5
//then the function would print //Sum of positive numbers is: -357
//Sum of negitive numbers is: 123
//Input v is an int vector
//Output None
void pos_neg_count(const std::vector & v) ;
int main(){
srand(time(0));
int len;
std::cout << "Enter in a length of the vector: " << std::endl;
std::cin >> len;
std::vector v;
fill_vector(v,len);
std::cout << "Original list:" << std::endl;
print_vector(v);
int mid = sep(v);
std::cout << "Separated list:" << std::endl;
print_vector(v);
my_sort(v,mid);
std::cout << "Sorted list:" << std::endl;
print_vector(v);
pos_neg_count(v);
std::vector merge_v;
neg_pos(v,mid,merge_v);
std::cout << "Merged list:" << std::endl;
print_vector(merge_v);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
