× Home (CS 111) Lectures Assignments Review Ryba's Website

Details

This set of problems and coding challenges are to be done in lab and at home.
All the cpp files from this assignment should be in a folder.
The name of the folder should follow this format:
lastName_firstName_#5
For example, my name is Alex Chen, folder name will be "Chen_Alex_#5"
Failure to follow this naming convention will result in your assignment not being graded.
The folder is to be zipped and submitted on blackboard on the due date.

#1 (Not Graded)

Watch the movie "Inception"

#2

Write removeLast0.cpp program that has a function called removeLast0 that prints an integer parameter without its rightmost 0. If there is no 0, print the number itself. If the number is 0, print nothing. Use recursion.
For example:
removeLast0(7070); // prints 707
removeLast0(7007); // prints 707
removeLast0(777); // prints 777

#3

Write diff2.cpp that has a function called diff2 that returns the absolute value of the difference of the first two digits of a positive integer parameter. If the parameter has just one digit, that digit should be returned. Use recursion.
For example:
cout << diff2(7070); // prints 7
cout << diff2(7907); // prints 2
cout << diff2(7); // prints 7

#4

Write cutAfter7.cpp that has a function called cutAfter7 that cuts a positive integer parameter after the first digit 7 that it contains. Parameters that are not positive should be returned without any change.
For Example
cout << cutAfter7(765) << endl; // prints 7
cout << cutAfter7(765765) << endl; // prints 7
cout << cutAfter7(666) << endl; // prints 666
cout << cutAfter7(107) << endl; // prints 107
cout << cutAfter7(107007) << endl; // prints 107

#5

Write biggerDigits.cpp that has a function called biggerDigits that uses two positive integer parameters with the same number of digits and returns an integer whose digit in each position is the bigger of the two digits in that position in the input parameters. If a negative parameter is given, or if parameters with unequal numbers of digits are given your function can return any result of your choosing
For Example:
cout << biggerDigits(567, 765) << endl; // prints 767
cout << biggerDigits(123456, 444444) << endl; // prints 444456
cout << biggerDigits(999, 111) << endl; // prints 999