CS211 - Algorithms and Data Structures II

T Naughton, NUIM
Back to CS211 home


Lab Exam 2

This lab exam is designed to test your basic C++ programming skills.

Problem 2A.1 Write a program that takes a number n as input from the user and writes out 2n rows of asterisks on the screen as shown below. This sample output of the program occurs when the user enters the number 4.

Here we go:
****
 ***
  **
   *
   *
  **
 ***
****
Goodbye!

Problem 2B.1 Write a program that takes a number n as input from the user and writes out n rows of asterisks on the screen as shown below. This sample output of the program occurs when the user enters the number 4.

Here we go:
****
*  *
*  *
****
Goodbye!

Problem 2C.1 Write a program that takes a number n as input from the user and writes out n rows of asterisks on the screen as shown below. This sample output of the program occurs when the user enters the number 4.

Here we go:
* ****
* ***
* **
* *
Goodbye!

Problem 2A.2 Write code for the following function:

int findhighestlessthan100(int * list, int len){
  /* This function returns the index of the element with the
  ** highest value in 'list' that is less than 100. 'list' is
  ** an integer array of length 'len'
  */

  // your code here
}

Problem 2B.2 Write code for the following function:

int findlowestgreaterthan10(int * list, int len){
  /* This function returns the index of the element with the
  ** lowest value in 'list' that is greater than 10. 'list' is
  ** an integer array of length 'len'
  */

  // your code here
}

Problem 2C.2 Write code for the following function:

int findclosestto10(int * list, int len){
  /* This function returns the index of the element in 'list'
  ** that has a value closest to 10. 'list' is an integer
  ** array of length 'len'
  */

  // your code here
}

Problem 2A.3 Write a program that reads 1106 integers from the user and stores them in an array of type int. Using a second array of type double, also of length 1106, the program stores 75% of the value of each of the first array's integers. Finally, the program outputs the element in the second array with the highest value.

Problem 2B.3 Write a program that reads 10 integers from the user and stores them in an array of type int. Using a second array of type double of length 2, the program stores the sum and the average of the list of integers. Finally, the program outputs the sum and average.

Problem 2C.3 Write a program that reads 31 integers from the user and stores them in an array of type int. Using a second array of type int, also of length 31, the program stores half the value of each of the first array's integers. Finally, the program outputs each int int pair where a rounding error has occurred.


Lab Sheet 2

Correct previous exam questions
Continue with problems 1.4 through 1.6.