关键词 > C++代写

Assignment 3 – User‐Defined Functions/Arrays

发布时间:2022-07-26

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Assignment 3  User Defined Functions/Arrays

Submission instructions:

-    Make a word file containing the screenshots of all programs and their results

-     Include the statement of originality in your assignment file

Create a cpp file for each question

Compress the files using zip or other tools (name both word file and zip file as your lastName_student_id, see the complete instructions on Moodle)

Submit the zip file on Moodle

Do not submit executable files

All submissions must be done through Moodle

Q1. (20 marks) Use a one-dimensional array to solve the following problem. A company pays its salespeople on a commission basis. The salespeople each receive $200 per week plus 9 percent of their gross sales for that week. For example, a salesperson who grosses $5000 in sales in a week receives $200 plus 9 percent of $5000, or a total of $650. Write a program (using an array of counters) that determines how many of the salespeople earned salaries in each of the following ranges (assume that each salesperson’s salary is truncated to an integer amount):

A. $200 –299

B. $300 –399

C. $400 –499

D. $500 –599

E. $600 –699

F. $700 –799

G. $800 –899

H. $900 –999

I. $1000 and over

Note: You need to keep asking the user to input the gross sale for an employee until the user wants to terminate inputting. Store the results in a one-dimensional array. Assume a maximum number of 100 employees.

Q2. (30 marks) Write a C++ program that uses an array to store the grades of maximum 100 students, and outputs the information below. Your program should be structured using functions. You can test your program for smaller number of students.

A.  The following functions take the array as the input and return an output to the main function. Print the value within the main function.

1.   max_func: returns maximum grade

2.   min_func: returns minimum grade

3.  avg_func: returns average grade

4.   med_func: returns median grade

B.  Write a function called stat_func that takes an array as an input and prints the following information within the function itself. The function does not return any value to the main function.

•   Number of A grades (grades more than 80)

•   Number of B grades (grades between 70 and 80)

•   Number of C grades (grades between 55 and 70)

•   Number of D grades (grades between 40 and 55)

•   Number of F grades (grades less than 40)

Q3. (25 marks) (Palindrome)  A palindrome is a string that’s spelled the same way forward and backward. Examples of palindromes include   “radar” and   “able was i ere i saw elba” . Write a recursive function testPalindrome that returns true if a string is a palindrome, and false otherwise. Note that like an array, the square brackets ([]) operator can be used to iterate through the characters in a string.

Q4. (25 marks) Write a C++ program to add the elements on the two diagonals of a square two- dimensional integer array and display that sum. Ensure that if there is a middle element in the

array it is not counted twice in the sum.

For example, with the array:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

your program should display 68 (1+6+11+16+4+7+10+13).

With the array:

1

2

3

5

6

7

9

10

11

your program should display 30 (1+6+11+3+9) (note that the 6 is not counted twice).