0% found this document useful (0 votes)
18 views

Assignment 2

Uploaded by

imaanjot20
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Assignment 2

Uploaded by

imaanjot20
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment 2

CS 115 001 - Object-Oriented Design


Due: February 18, 2024

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.

Sample input and corresponding output:

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. Given an array of positive integer values, implement the Selection sort


method to sort the array elements in ascending order. Then, implement
the Binary Search method to find the index of an element in the sorted
array. Write a main function to test it as follows.

Sample input and corresponding output:

Enter the number of elements of the array: 7


Enter the elements: 7 3 19 5 100 4 45
The sorted array is: 3 4 5 7 19 45 100
Enter the element that you are searching for: 45
45 can be found at index 5.
Thank you!

Enter the number of elements of the array: 7


Enter the elements: 7 3 19 5 100 4 45
The sorted array is: 3 4 5 7 19 45 100
Enter the element that you are searching for: 92
The element 92 does not exist in the array.
Thank you!

Enter the number of elements of the array: 6


Enter the elements: 98 27 38 53 68 38

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.

Sample input and corresponding output:

Enter the number of elements that you want in the array: 6


Enter the elements: 98 27 38 53 68 38
The sorted array is 27 38 38 53 68 98
Enter the element that you are searching for: 38
The index of the first occurrence of 38 is 1.
Thank you!

Enter the number of elements that you want in the array: 6


Enter the elements: 98 27 38 53 68 38
The sorted array is 27 38 38 53 68 98
Enter the element that you are searching for: 7
The element 7 does not exist in the array.
Thank you!

You might also like