4 questions c++ codes

4 questions c++ codes

1) Write a c++ program that contains the following functions

a) A function that takes in an integer array of any size, and fills up the array with values taken from the user. (Your function should work for any size array, and should be tested with at least 3 arrays of different sizes)

b) Do the same as a) above, but get the values from a file instead. (Create a file that has input for at least 3 arrays of different sizes).

c) A function that takes in an array of any size, and returns the sum of all multiples of 5 in the array.

d) A function that takes in an array of any size and an integer key m. It should return the mth smallest element in the array. (m cannot be larger than the size of the array, and your array should be unsorted).

For example for an array containing 3 2 4 8 9 6, and m is 2, it should return the 2nd smallest number in the array which is 3

e) A function that takes in an array of any size and a key, and returns the number of passes it takes to find the key in the array or 0 if it’s not in the array. Use Binary Search

f) A function that takes in an array of any size and prints the content 4 per line. (Test this function with at least 3 arrays of different sizes)

Optional Question (Practice)

Write the definition of a function that takes in any array of any size, and an integer key, and returns the smallest value closest to they key if it is in the array, returns 0 otherwise (Use Binary Search)

Example

6, 11, 15, 24 29 35 49 61 75 83. is contained in an array, with a key of 49, the smallest value closest to 49 is 35, and your function returns that.

2) Write a C++ program that reads from a file the last name of an election candidate and the number of votes that they received, you program would then determine what percentage of vote each candidate received and the winner of the election. Use the concept of parallel arrays. Your program should contain the following functions

a) A function to read in the data from the file into the appropriate data structure

b) A function to calculate each candidates percentage of vote earned

c) A function to print out each candidate’s name, number of votes and percentage of total vote earned (Output should be formatted to look like the file, with a new header for vote percent)

d) A function that returns the name of the election winner.

Use appropriate function calls to test your program. Below is the content of the file. ignore the first line containing the headers if it makes it easier to write

Candidate Number of Votes

Lannister 350000

Stark 310000

Targaryen 397000

Baratheon 275000

Martell 280000

Greyjoy 205000

Mormont 415000

Tully 30000

(Feel free to adjust the numbers in the file)

there is two more questios in the attachments

"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.


Discount Code: CIPD30



Click ORDER NOW..

order custom paper