Starting from:

$20

COEN243-Assignment 3 User‐Defined Functions/Arrays Solved

Q1. Write a C++ program that uses an array to store the grades of N students (N is entered by the user), and outputs the information below. Your program should be structured using functions. Each functionality should be implemented in a separate function.

1.     Maximum grade 

2.     Minimum grade 

3.     Average grade 

4.     Median grade 

5.     Number of A grades (grades more than 80) 

6.     Number of B grades (grades between 70 and 80) 

7.     Number of C grades (grades between 55 and 70) 

8.     Number of D grades (grades between 40 and 55) 

9.     Number of F grades (grades less than 40) 

 

Q2. Write a user-defined function that takes an integer number and outputs the reverse of that number. Call the function twice in the main function and test your program with two 3-digits and 4-digits numbers.

 

Example of output:  

Type an integer number: 345 

Output: 543 

 

Type an integer number: 3097 

Output: 7903 

 

 

Q3. We want to create a program that controls the movements of a robot in an array of size Initially, the robot is at position 0. The controller supports the following commands:

          ‐    right (n): the robot moves n cells right

          ‐    left (n): the object moves n cells left

          ‐    reboot: the object comes back to cell 0

             

 

Consider the following example:

 

^
 
 
 
 
 
 
 
 
 
                                                     0       1       2       3       4       5       6       7       8       9

 

The new array after executing the command right(5) will look like this:

 

 
 
 
 
 
^
 
 
 
 
                                                     0       1       2       3       4       5       6       7       8       9

 

The new array after executing the command left(3) will look like this:

 

 
 
^
 
 
 
 
 
 
 
                                                     0       1       2       3       4       5       6       7       8       9

 

 

The program takes commands from a user as shown in the following example:

 

Controller Menu:

1.    Right

2.    Left

3.    Display

4.    Reboot

5.    Show Array

6.    Exit

 

Command “Display” display the position of the robot in the array. Command “Show Grid” displays the array. Command “Exit” terminates the program.

‐ Implement the controller’s commands using functions. Add the necessarily checks to ensure that the robot does not go out of bounds. Your program should be structured using functions. For example, each command should be implemented in a separate function. (30 marks)

          ‐    We want to add the following commands :

o   cancel (n): The program cancels the last n operations and returns the robot to the initial position

o   replay (n): The program replays the last n operations that have been cancelled.

More products