< Back

Final Exam


If you do not currently have a directory for tests, create one in your cs170 directory, and also create a directory for the final.

$ mkdir ~/cs170/tests
$ mkdir ~/cs170/tests/final
$ cd ~/cs170/test/final

This portion of the test is worth 30 total points. In addition to this file, you may only access the C++ documentation website and the Qt documentation documentation website. NO OTHER WEBSITES ARE PERMITTED. You are also not allowed to access any personal files in your CS account. As usual, you are not allowed to directly copy any code from the Internet or another individual. You should also follow all coding standards discussed thus far.


Final

Question 9

Create a Qt program called greyscale. This program should create a grey gradient across the entire window.

A color value is grey if it's red, green, and blue values are all the same value. To figure out the color values for a particular pixel, compute the distance the pixel is from \((0, 0)\). Compute the percentage of the distance to \((WIDTH, HEIGHT)\), and use this as the percentage of the maximum color value to use for R, G, and B.

To change the color you draw in, you need to change the color of the pen of the painter. You need to create a QColor object, and pass it to the setPen method of the painter.

(10 points)


Question 10

Create a file called Question10.cc in your directory. Inside this file, write a RECURSIVE function called bool isSortedAscending(int * anArray, int size). This function takes an array of at least size. number of integers. This function should return true if the provided array is sorted in ascending order. It should return false in all other circumstances.

  int myArray[] = {0, 1, 2, 3};
  printBool(isSortedAscending(myArray, 4));       // Prints True
  int mySecondArray[] = {0, 1, 2, 3, 4, 3};
  printBool(isSortedAscending(mySecondArray, 6)); // Prints False
  printBool(isSortedAscending(mySecondArray, 5)); // Prints True

(10 points)


Question 11

Download the files LinkedList.cc and LinkedList.h and save it into your test directory. Add a method called void deleteDuplicates(), which removes all duplicates from the linked list. You may write any additional functions and methods as necessary.

  //Test Case 1: No duplicates
  LinkedList test1();
  for(int i = 0; i < 10; i++) {
    test_list.append(i);
  }

  cout << test1 << endl; //[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  test1.delete_duplicates()
  cout << test1 << endl; //[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

  //Test Case 2: duplicates side by side
  LinkedList test2();
  for(int i = 0; i < 5; i++){
    test2.append(i);
    test2.append(i);
  }
  
  cout << test2 << endl; //[0, 0, 1, 1, 2, 2, 3, 3, 4, 4]
  test2.deleteDuplicates();
  cout << test2 << endl; //[0, 1, 2, 3, 4]

  //Test Case 3: duplicates elsewhere in the list
  LinkedList test3();
  for(int i = 0; i < 5; i++){
    test3.append(i);
  }
  for(int i = 4; i >= 0; i--){
    test3.append(i);
  }

  cout << test3 << endl; //[0, 1, 2, 3, 4, 4, 3, 2, 1, 0]
  test3.deleteDuplicates();
  cout << test3 << endl; //[0, 1, 2, 3, 4]

(10 points)


 

Challenge

Create a file called LinkedList.py. In this file, create a class called LinkedList, which defines a python version of a Linked List. Be sure to provide ample test cases to demonstrate your program working.

(8 points)


Submission

When you have finished, create a tar file of your final directory. To create a tar file, execute the following commands:

cd ~/cs170/tests
tar czvf final.tgz final/

To submit your activity, go to inquire.roanoke.edu. You should see an available assignment called Final Exam.