Question

In: Computer Science

Pass or Fail (C++) Given a vector, where each element in the vector is a [name,...

Pass or Fail (C++)

Given a vector, where each element in the vector is a [name, grade] pair sort range by name, partition range into pass and fail, preserving alphabetical order within partition. The grades are the number of points earned (600 points earns a passing grade).

std::vector<std::pair<std::string, int>> v {
{"josh", 851},
{"mark", 600},
{"charles", 412},
{"sebnem", 1000},
{"abdol", 905},
{"imen", 300}
};


--------EXPECTED OUTPUT-------------------------------------------------

std::vector<std::pair<std::string, int>> w {
{"abdol", 905},
{"josh", 851},
{"mark", 600},
{"sebnem", 1000}, // Everyone after this point failed
{"charles", 412},
{"imen", 300}
};

Note: NO LOOPS ALLOWED

Thanks!

Solutions

Expert Solution


Related Solutions

Evaluate the line integral C F · dr, where C is given by the vector function...
Evaluate the line integral C F · dr, where C is given by the vector function r(t). F(x, y, z) = sin(x) i + cos(y) j + xz k r(t) = t5 i − t4 j + t k, 0 ≤ t ≤ 1
C++ Given vector<float> vec; Using a ranged for loop, modify each value in vector to cube...
C++ Given vector<float> vec; Using a ranged for loop, modify each value in vector to cube and subtract 12.5
java You are creating an array where each element is an (age, name) pair representing guests...
java You are creating an array where each element is an (age, name) pair representing guests at a dinner Party. You have been asked to print each guest at the party in ascending order of their ages, but if more than one guests have the same age, only the one who appears first in the array should be printed. Example input: (23, Matt)(2000, jack)(50, Sal)(47, Mark)(23, will)(83200, Andrew)(23, Lee)(47, Andy)(47, Sam)(150, Dayton) Example output: (23, Matt) (47, Mark) (50, Sal...
1a) Write a program in C programming language to determine *pass* or *fail*. Use the GP...
1a) Write a program in C programming language to determine *pass* or *fail*. Use the GP ( 0.00 - 1.49 -> fail 1.50 - 4.00 -> pass ) 1b) Write a program in C to display month in Islamic Calendar.
You are given a set S of n real numbers where for each element x ∈...
You are given a set S of n real numbers where for each element x ∈ S, 1 < | x | < 10. You are also given a black box that returns true if there is some combination (x, y, z) ∈ S such that x · y = z. Say the black box returns only z. Write an O(n log n) algorithm to find x and y. In other words, given a set S with n real numbers...
Given an array A[0 … n-1], where each element of the array represent a vote in...
Given an array A[0 … n-1], where each element of the array represent a vote in the election. Assume that each vote is given as an integer representing the ID of the chosen candidate. Can you determine who wins the election? What is the complexity of your solution? Hint: it is similar to finding the element that is repeated the maximum number of times.
In c++ how do I search a vector for a name and then determine if the...
In c++ how do I search a vector for a name and then determine if the name is found?
Problem 1: Given an array A[0 ... n-1], where each element of the array represents a...
Problem 1: Given an array A[0 ... n-1], where each element of the array represents a vote in the election. Assume that each vote is given as integers representing the ID of the chosen candidate. Write the code determining who wins the election. Problem 2: How do we find the number which appeared maximum number of times in an array? ( Use Java and an original code )
Using Java, Given an array A[0 ... n-1], where each element of the array represent a...
Using Java, Given an array A[0 ... n-1], where each element of the array represent a vote in the election. Assume that each vote is given as an integer representing the ID of the chosen candidate. Can you determine who wins the election? What is the complexity of your solution? Hint: it is similar to finding the element that is repeated the maximum number of times.
2. Vector Element Calculation Write a MATLAB script which will randomly generate a 20-element vector with...
2. Vector Element Calculation Write a MATLAB script which will randomly generate a 20-element vector with integer values ranging between −100 to +100. Using LOOP command, determine the number of negative elements in the vector. For example, given A = [15 −6 0 -8 −2 5 4 −10 -3 −5], the number of negative numbers are 6.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT