December 19, 2014, 17:26

CP104 : Challenge For Credit Exam

Students who may have, through past experience, gained knowledge in software design and modern programming techniques may challenge for a credit in CP104. With a grade of B or higher on an examination at the beginning of the fall term, a student will receive that grade and credit for CP104 without further course work. Students must be registered in CP104 in order to take the challenge for credit exam and the course registration fee applies. Students who are successful in challenging for credit may take an additional course but are not required to do so.

On the exam you may provide answers in C, C++, Java, Python, Pascal, or some other high-level language, subject to prior approval by the course instructor.

If you wish to write the exam, please email the course instructor for CP104 with the subject "CP104: Challenge for Credit".

Further information from the Undergraduate Calendar:


CP104: Objectives


Sample Challenge for Credit Exam

  1. (10) Write a function that takes an integer array and the size of the array as its parameters. The function must search the array and print both the smallest value stored in the array and the index of that value. Provide code that calls the function in a main program.
  2. (10) Assume that an integer array is sorted in descending order. Write a function that takes the array, the size of the array, and a target value as its parameters. Without searching the entire array print the index of the first element that is equal to the target value. If no element in the array contains the target value print -1. Provide the code that calls the function in a main program.
  3. (8) Given a square 2-dimensional array with SIZE rows and SIZE columns, write a function named Swap that swaps the rows with the columns in the array and returns the swapped values in a second array. That is, return the transpose of the input array. For example, the array
     1  2  3  4
     5  6  7  8
     9 10 11 12
    13 14 15 16
    

    becomes

     1  5  9 13
     2  6 10 14
     3  7 11 15
     4  8 12 16
    

  4. (12) Write a function that read from a file inputfile.txt. Each line in inputfile.txt contains a name, an integer id, a pay rate per hour (a real number), and the number of hours worked (a real number). Your program must calculate the pay, the tax withheld for each person and generate the output listed below to the file pay.txt. For an amount that is below $1000, withhold 10%. For amount between $1000 and $2000, withhold 20%, and for amount higher than $2000, withhold 30%. For example, a pay of $3200 has 1000*0.1 + 1000*0.2 + 1200*0.3 = 660 withheld.

    Sample input

    Tom   1234 20.5 80
    Susan 2345 30.0 90
    Jim   3456 10.0 70
    

    Sample output in file pay.txt

    ----------------------------------------
    Name   Id     Pay       Tax     Net-Pay
    ----------------------------------------
    Tom   1234   1640.00   228.00   1412.00
    Susan 2345   2700.00   510.00   2190.00
    Jim   3456    700.00    70.00    630.00
    ----------------------------------------
    Total        5040.00   808.00   4232.00
    

  5. (6) Write a function that returns the length of the longest common prefix of two words (e.g. the longest common prefix of "global" and "glossary" is "glo", of "department" and "depart" is "depart", and of "glove" and "dove" is the empty string).
  6. (6) Write a function that prompts the user to enter a password, and compares it to real_password to see if they are the same. If they are, the password is correct. The function should allow the user at most three attempts to enter the password. The function should return either True if the password was correct, or False if it was not.
  7. (6) A palindrome consists of a word that is spelled exactly the same when the letters are reversed. For example, "eve" and "level". Note that in a palindrome, the first letter matches the last, the second letter matches the second-to-last, etc. Write a function that determines if its string parameter is a palindrome.
  8. (6) Write a function product_code that returns True if the string argument is a product code and returns False otherwise. A string is a product code if it has some digits, then has a slash "/" followed by more digits and ends with a colon ":". For example, "345/98:" is a product code.

Wilfrid Laurier University 75 University Avenue West, Waterloo, Ontario, Canada N2L 3C5
phone: (519) 884-1970