Assignment 2
Assignment 2
Instructions:
Your program should be written in C/C++. Please submit the source files for
all 3 exercises.
Marking Scheme:
1. Readability and programming style (10%): The program should be easy to
read, well commented, structured (i.e. should incorporate proper layout,
indentation, white-spaces, etc.), and well designed (i.e. should follow top-
down design approach). Follow the commenting guidelines for interface
specification provided in the class/slides/notes.
2. Compiling and execution process (10%): The program must compile and
execute without errors and warnings.
3. Correctness (80%): The program should produce correct results.
4. Sample-based marking might be practised for this assignment.
Questions:
1. Define and implement a class myInt that has an integer variable as a
field and that contains member functions for determining the following
information for the member data (i.e. the stored integer) of an object of
type myInt.
(a) Is it a multiple of 7, 11, or 13?
(b) Is the sum of the digits odd or even?
(c) Is it a prime number?
Write a main function to test it as follows.
Enter an integer: 63
The integer is a multiple of 7.
1
The integer is not a multiple of 11.
The integer is not a multiple of 13.
The sum of digits of the integer is 9, which is an odd number.
The integer is not a prime number.
Thank you!
Enter an integer: 17
The integer is not a multiple of 7.
The integer is not a multiple of 11.
The integer is not a multiple of 13.
The sum of digits of the integer is 8, which is an even number.
The integer is a prime number.
Thank you!
Enter an integer: 77
The integer is a multiple of 7.
The integer is a multiple of 11.
The integer is not a multiple of 13.
The sum of digits of the integer is 14, which is an even number.
The integer is not a prime number.
Thank you!
2
The sorted array is: 27 38 38 53 68 98
Enter the element that you are searching for: 38
38 can be found at index 2.
Thank you!
3. Modify the above binary search algorithm to instead find the first occur-
rence of the item (i.e. if the item is indeed in the array). Write a main
function to test it as follows.