1. Discussion based on course subjects (40 minutes)

  • Function declarations
  • Examples of functions that return a value
  • Examples of void functions
  • Parameters passed by value
  • Parameters passed by reference
  • Local vs global vs formal variables

2. Exercises (60 minutes)

Warning! For each of the following functions a test program will be created. Generate different and diverse input data for tests (minimum values, maximum values, values that have certain characteristics etc. ).

  1. (0.20p) Write an iterative function which for a number n, it returns the n’th number of a Fibonnaci sequence (fib(0)=0,fib(1)=1,fib(n)=fib(n-1)+fib(n-2), for n>1)
    Ex: fib(3) = fib(2) + fib(1) = fib(1) + fib(0) + 1 = 1 + 0 + 1 = 2
    unsigned int fibonnaci_it(int index);
  2. (0.20p) Write a recursive function which for a number n, it returns the n’th number of a Fibonnaci sequence (fib(0)=0,fib(1)=1,fib(n)=fib(n-1)+fib(n-2), for n>1)
    Ex: fib(3) = fib(2) + fib(1) = fib(1) + fib(0) + 1 = 1 + 0 + 1 = 2
    unsigned int fibonnaci_rec(int index);
  3. (0.20p) Write a function that tests if a year is leap.
    bool isLeapYear(unsigned short year);
  4. (0.40p) Write a function that verifies if a number is palindrome. A number is palindrome if read from left to right is equal with the number read from right to left. Ex: 13231 is palindrome but 12331 is not palindrome.
    bool isPalindrom(unsigned long long number);
  5. (0.50p) Write a function which for a day (year month day) it will return the week day’s number.
    unsigned char dayOfTheWeek(unsigned short year, unsigned char month, unsigned char day);
  6. (0.50p) Write a function which, for a natural number, it computes the digit’s sum of its binary representation.  unsigned char sumBinaryFigure(unsigned long long number);
  7. (0.50p) We say that a natural number is perfect if it is equal to the sum of its divisors strictly lower than it. Write a function that returns the sum of  the sum of the two largest perfect numbers smaller than a given number (number> = 30).
    unsigned long perfectNumbers(unsigned int number);
  8. (0,50p) Declare, then implement a function that calculates the control number for an ISBN-10 code. Hints at https://en.wikipedia.org/wiki/International_Standard_Book_Number
  9. (0,50p) Write an iterative function that computes the sum of the negative elements of an integer array.
  10. (0.75p) Write a function that for a given interval [left, right] returns the number of numbers having the maximum number of prime divisors.
    Example: For [30, 45] the numbers with the maximum number of prime divisors = 30,42 (they have 3 prime divisors, no other number in the interval has more prime divisors) and the function returns 2.
    unsigned short primeDivisors(unsigned int left, unsigned int right);
  11. (1,00p) Two consecutive odd natural numbers and primes are called twin prime numbers. Write a function which determines the first count pair of twin prime numbers larger than a given lowerBound.
    Example: For count = 1 and lowerBound = 2 the function will return a matrix with a row (one result) and 2 columns (pair of numbers – two numbers): 3 5
    matrix primeTwins(unsigned int count, unsigned int lowerBound);
  12. (1,25p) An array of closed integer intervals is given. Two consecutive intervals in the array that have a nonempty intersection are merged and replaces with their reunion. The operation is repeated until there are no more consecutive intervals with their intersection nonempty.Write a function which determines how many intervals remained in the array after a sequence of operations are performed.
  13. (1,50p) The following declarations are given:  #define MAX_DNA 10 and typedef char DNAarray[MAX_DNA]; A computer scientist discovered a new way of coding an integer number using Deoxyribonucleic acid (DNA), which contains A(adenine), C (cytosine), G (guanine) and T (thymine). Thus, in the calculations the numbering base 4 is used, but the numbers of A, C, G and T have the values ​​A = 0, C = 1, G = 2, and T = -1. For example, integer 27 is represented by „GTT” using DNA. Similarly, integer -6 is represented by „TGG” and number 84 is represented by „CCCA”. Justification: GTT = Gx42+Tx41+Tx40 = 2×16+(-1)x4+(-1)x1 = 32-4-1=27, TGG = Tx42+Gx41+Gx40 = (-1)x16+2×4+2×1 = -16+8+2=-6, CCCA = Cx43+Cx42+Cx41+Ax40=1×64+1×16+1×4+0x1=84
    • (0,70p) Write a void function void codificationDNA(long integerNr, DNAarray,codeDNA) which codifies an integer number integerNr in his DNA representation. For example, for integerNr=27, the function will set DNAarray to „GTT”.
    • (0,50p) Write a void function void decodificationDNA(char DNAarray[MAX_DNA], long& integerNr), which decodifies a DNA array into an integer number. For example, for DNAarray=”GTT”  the function will obtain integerNr=27.
    • (0,15p) Write a function void sumDNA(DNAarray firstArray, DNAarray secondArray, DNAarray sum), which sums up two DNA arrays, the result being the DNA representation of the sum of the two numbers, represented by firstArray, secondArray. For example, for firstArray=„GTT” and secondArray=”C”, the function will return sum=”GTA”.
    • (0,15p) Write a function void subtractDNA(DNAarray firstArray, DNAarray secondArray, DNAarray subtraction), which subtracts two DNA arrays, the result being the DNA representation of the subtraction of the two numbers firstArray and secondArray. For example , for firstArray=”GTA” and secondArray=”C”, the function will return subtraction=”GTT”.