Question 1:
Implement a function:
int printMonthCalender(int numOfDays, int startingDay)
This function is given two parameters:
numOfDays – The number of days in the month
startingDay – a number 1-7 that represents the day in the week of the first day
in that month (1 for Monday, 2 for Tuesday, 3 for Wednesday, etc.).
The function should:
Print a formatted monthly calendar of that month
Return a number 1-7 that represents the day in the week of the last day in that
month.
Formatting Notes:
• •
Example: when calling printMonthCalender(31, 4)it should return 6, and should print:
b. A method for determining if a year is a leap year in the Gregorian calendar system is to check if it is divisible by 4 but not by 100, unless it is also divisible by 400.
For example, 1896, 1904, and 2000 were leap years but 1900 was not.
Write a function that takes in a year as input and return true if the year is a leap year, return false otherwise.
Note: background on leap year https://en.wikipedia.org/wiki/Leap_year c.
• •
The output should include a header line with the days’ names.
Columns should be spaced by a Tab.
Mon Tue Wed Thr Fri Sat Sun
1234
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Implement a function:
void printYearCalender(int year, int startingDay)
This function is given two parameters:
year – an integer that represents a year (e.g. 2016)
startingDay – a number 1-7 that represents the day in the week of 1/1 in that
year (1 for Monday, 2 for Tuesday, 3 for Wednesday, etc.).
The function should use the functions from sections (a) and (b) in order to print a
formatted yearly calendar of that year.
Formatting Note: As the header for each month you should print the months’ name
followed by the year (e.g. March 2016).
Example: Appendix A shows the expected output of the call
printYearCalender(2016, 5).
d. Write program that interacts with the user and your function in (c).
Question 2:
Consider the following definitions:
- A proper divisors of a positive integer (≥ 2) is any of its divisors excluding the number itself.
For example, the proper divisors of 10 are: 1, 2 and 5.
- A perfect number is a positive integer (≥ 2) that is equal to the sum of its proper divisors.
For example, 6 and 28 are perfect numbers, since:
6=1+2+3
28 = 1 + 2 + 4 + 7 + 14
Background of perfect numbers: https://en.wikipedia.org/wiki/Perfect_number - Amicable numbers are two different positive integer (≥ 2), so related that the sum of the proper divisors of each is equal to the other number.
For example, 220 and 284 are amicable numbers, since:
284 = 1 + 2 + 4 + 5 + 10 + 11 + 20 + 22 + 44 + 55 + 110
220 = 1 + 2 + 4 + 71 + 142
(proper divisors of 220)
(proper divisors of 284)
Background of amicable numbers: https://en.wikipedia.org/wiki/Amicable_numbers
- Write a function:
void analyzeDividors(int num, int& outCountDivs, int& outSumDivs) The function takes as an input a positive integer num (≥ 2), and updates two output parameters with the number of num’s proper divisors and their sum.
For example, if this function is called with num=12, since 1, 2, 3, 4 and 6 are 12s proper divisors, the function would update the output parameters with the numbers 5 and 16. Note: - Use the function you wrote in section (a), to implement the function:
bool isPerfect(int num)
This functions is given positive integer num (≥ 2), and determines if it is perfect number or not. - Use the functions you implemented in sections (a) and (b), to write a program that reads from the user a positive integer M (≥ 2), and prints:
- All the perfect numbers between 2 and M.
- All pairs of amicable numbers that are between 2 and M (both numbers must be in the
range).
Note: Pay attention to the running time of your implementation. An efficient algorithm for this part would call analyzeDividors Θ(𝑀) times all together.
Pay attention to the running time of your function. An efficient implementation would
run in Θ”√𝑛𝑢𝑚’.
Question 3:
a. b.
Question 4:
a)E c
b) c) d)
Question 5:
a) b) c) d) e)
Question 6:
a) b)
Question 7:
How many one-to-one functions are there from a set with five elements to sets with the following number of elements?
a) 4
b) 5
c) 6 d) 7
Solve Exercise 8.2.2, section b from the Discrete Math zyBook.
Solve Exercise 8.3.5, sections a-e from the Discrete Math zyBook
Solve the following questions from the Discrete Math zyBook:
xercise 5.1.2, sections b,
Exercise 5.3.2, section a
Exercise 5.3.3, sections b, c
Exercise 5.2.3, sections a, b
Solve the following questions from the Discrete Math zyBook:
Exercise 5.4.2, sections a, b
Exercise 5.5.3, sections a-g
Exercise 5.5.5, section a
Exercise 5.5.8, sections c-f
Exercise 5.6.6, sections a, b
Solve the following questions from the Discrete Math zyBook:
Exercise 5.7.2, sections a, b
Exercise 5.8.4, sections a, b
Appendix A.
The expected output of the call printYearCalender(2016, 5) is:
January 2016
Mon Tue Wed Thr Fri Sat Sun
123
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
February 2016
Mon Tue Wed Thr Fri Sat Sun
1234567
8 9 1011121314
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29
March 2016
Mon Tue Wed Thr Fri Sat Sun
123456
7 8 9 10111213
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
April 2016
Mon Tue Wed Thr Fri Sat Sun
123
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
May 2016
Mon Tue Wed Thr Fri Sat Sun
2345678
9 101112131415
1
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
June 2016
Mon Tue Wed Thr Fri Sat Sun
12345
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
July 2016
Mon Tue Wed Thr Fri Sat Sun
123
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
August 2016
Mon Tue Wed Thr Fri Sat Sun
1234567
8 9 1011121314
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
September 2016
Mon Tue Wed Thr Fri Sat Sun
1234
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
October 2016
Mon Tue Wed Thr Fri Sat Sun
3456789
10 11 12 13 14 15 16
12
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
November 2016
Mon Tue Wed Thr Fri Sat Sun
123456
7 8 9 10111213
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
December 2016
Mon Tue Wed Thr Fri Sat Sun
1234
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31



