Given an array arr[] sorted in ascending order of size N and an integer K. Check if K is present in the array or not. (Use Binary Search) Input: N = 5 K = 6 arr[] = {1,2,3,4,6} Output: 1
Explanation: Since, 6 is present in the array at index 4 (0-based indexing), output is 1
Write a program that reads the numbers and sorts them by using the Counting Sort algorithm and finally search a number from that array using Linear Search Algorithm. 8 Input: 3 6 5 4 7 8 9 Search Item: 7 Output: Sorted Array: 3 4 5 6 7 8 9 Search item 7 is found.
Display the total amount per section code and the overall total
4. At the end of each event five (5) lucky customers are randomly chosen from the name
array to win daily prizes. Call a function to accomplish this.
5. Display the names of the five lucky winners.(15
Define the following modules below the main function:
a function to determine the ticket price based on the received seating section code.(7)
a void function to accumulate total amounts made per sitting section(5)
a void function that will generate 5 numbers to represent winners, ensure that the
function does not duplicate numbers and store the winning numbers in an array called
luckyCust. (
T is an array of N integers. N is defined as a constant equal to 10.
Write a procedure proc1(int *T) that reads the N elements of the array by checking that the entered values are between 10 and 20. This procedure will display thereafter the N values of the array, the sum value, the maximum value and the minimum value of elements in this array.
Test #2:
Find the bug and write the correct version of the program
#include <iostream>
class Utils
{
public:
static double findAverage (int number1, int number2)
return number1 + number2 / 2;
};
}
int main()
std::cout << Utils::findAverage(5, 2); // it should return 3.5
}
Test #3 (optional):
Please find and explain all the errors in the following function. There is at least one of the
following:
1. Compilation error
2. Segmentation fault
3. Performance issue
Flight minFlight(std::vector<Flight> flights)
{
std::sort(flights.begin(), flights.end()); return flights.begin();
}
Also, write the correct version of the program.
1. Write a c++ program that sum's up the even numbers between 0 and
any positive integer number n given by the user.
Write a C++ program that will allow the teachers to do the following:
4.1 Capture the student performance record in a sentinel-controlled loop and store the results in three parallel arrays. The information to be stored in the three arrays is the student’s full name, continuous assessment mark, and final mark. If the lecturer types the word ‘Done’ instead of a full name, the loop should immediately stop even before capturing any marks.
(6 Marks)
4.2 Search the array for the student’s full name and then display the full record of the student, or the notification that student does not exist. You should also allow the teachers to search for the best or worst performer in the Final Mark column. When the mark is found, let it be displayed with all the student’s details. (8 Marks)
4.3 Make this program a menu driven system with the following options: Capture Marks, Find a Student, Find the Best Performer, Find the Worst Performer,
#include <iostream> #include <vector>
std::vector<std::string> getUniqueBrands(const std::vector<std::string>& brand1, const std::vector<std::string & brand2)
{
throw std::logic_error("yet to be implemented");
}
int main()
{
std::vector<std::string> brand1 = {"LOUIS VUITTON", "HERMES", "PRADA"};
std::vector<std::string> brand2 = ("GUCCI", "PRADA", "HERMES"};
std::vector<std::string> result = getUniqueBrands(brand1, brand2);
for(auto element: result)
{
std::cout << element << '
// should print GUCCI HERMES LOUIS_VUITTON PRADA
}
}
5.1 Use the provision for Rrecords in C++ to create each employee’s record. The record should have the following fields: Name, Surname, Gender, Qualification (Education Level), Position, NoOfChildren, and Salary. All these must be captured by one cin statement, the values separated by spaces, which means that each field value should not have spaces.
(4 Marks)
5.2 Every record captured must be written into a file that is open for output while information is being captured from the keyboard. Each record must use a space as the field delimiter. Therefore, each record is saved on one line on the text file. Make sure the file is only closed just before it is opened for read. Keep it open until all records have been captured. (4 Marks).
5.4 The system should be a menu driven system with the options: Capture Employee, Print Payslips and Exit. When the Capture Employee menu is chosen, the user is asked how many employees they want to capture.