COL100 Assignment 9 Solved

30.00 $

Category: Tags: , ,

Description

Rate this product

1 Setting Up The Great C (5 marks) (In-Lab Component)

According to a famous saying – Give me six hours to chop down a tree and I will spend the first four sharpening the axe.
So yours first task is to download and install C compiler and setting up the path variable. You can consult these websites regarding same

1. https://www.scaler.com/topics/c/c-compiler-for-windows/
2. https://www.scaler.com/topics/c/how-to-compile-c-program-in-linux/
3. https://www.scaler.com/topics/c/c-compiler-for-mac/
4. https://www.geeksforgeeks.org/installing-mingw-tools-for-c-c-and-changing-environment-variable 5. https://www.rose-hulman.edu/class/csse/resources/MinGW/installation.htm
6. https://www.geeksforgeeks.org/setting-c-development-environment/

Some important background information and definitions:

  1. GNU is an extensive collection of free software which can be used as an operating system or can be used in parts with other operating systems.
  2. The GNU Compiler Collection, commonly known as GCC, is a set of compilers and development tools available for Linux, Windows, various BSDs, and a wide assortment of other operating systems. It includes support primarily for C and C++ and includes Objective-C, Ada, Go, Fortran, and D.
  3. MinGW stands for “Minimalist GNU for Windows” It is essentially a tool set that includes some GNU software, including a port of GCC. In summary, MinGW contains GCC which is in the collection of GNU free software.
  4. We recommend you to right click on every option in minGW installation manager and mark it for installation – if you do not know, what they do.
  5. You can also download IDE of yours choice with or without C compiler. But make sure to follow instruction and not use IDE for compiling and running the program.
  6. A funny and easy way to install C compiler on Windows is using Chocolatey Package Manager. Consult these videos regarding same –

    (a) https://www.youtube.com/watch?v=t6YQ8MousWo (b) https://www.youtube.com/watch?v=OEIyk80XuDU

Yours Second task is to write a C program which is equivalent to python program given below.

a = 200
b = 100
print(a*b if b else 0)

Yours Third task is to Compile and run the above C program, you have made, using command prompt/ bash terminal, or any other terminal. Do not use IDE for running the program. Make sure to get the same answer as you may get in python.

2

2 Clock (10 marks)

You have a wall clock which shows time in the format XX:YY, here XX denotes the hours and YY denotes the Minutes. You have to calculate the angle between the hour hand and minute hand of the wall clock.

As there will be 2 angles the small and large between both hands, such that large + small = 360. You have to return the smaller one as a result. The time given to you is in 24 hrs format, you have to convert it into 12hrs format then find the angle.

For example If time is 00:30 then the time in 12 hrs format will be 12:30 and the angle between hour hand and minute hand is 165 degrees.

We have provided a skeleton code which takes input from standard input and calls the function time_angle() and prints the returned output which you have to return from function time_angle(). You have to write your code, in function time_angle() only and return your output. You cannot print anything in function.

Input: The first line of input will contain value of XX as an integer. The second line of input will contain value of YY as an integer type.

Return Output : Only return the float value as asked in the question. Result should be posi- tive only.

Some important points to note:

  1. You have to write your code in C
  2. In this question, we will be checking ONLY your Output, so make sure to return the correct format. Any output format mismatch will result in 0.
  3. Follow skeleton code, otherwise you can loose marks. You can make your own functions which can be called from function time_angle()
  4. We will be converting your float output to int with the help of typecasting
  5. Do not consider sign while calculating angle i.e. do not consider direction while calculating angle.

Input Constraints: Example 1:

INPUT: 1

2

INPUT: 1

2

All valid 24hrs format from 00:00 to 23:59.

06 00

OUTPUT: 180 Example 2:

12 20

OUTPUT: 110 EXPLANATION:

3

If we assume the 12 on the clock as the reference point i.e. it is considered to be at 0 degrees .The minute hand is at 20 minutes which corresponds to an angle of 120 degrees and the hour hand will be at 10 degrees w.r.t. the reference point. So the angle difference between the minute and the hour hand will be 120-10 = 110

3 Food Delivery (15 marks)

Mr John, works as a full time food delivery partner at Zomato. Currently he is at location with coordinates as (0, 0) and wants to take food from a restaurant which is at coordinate (x, y). After that he wants to deliver that food to the coordinate (m, n).

We assume that 0 < x < m and 0 < y < n.
If Mr John is currently at the location (a, b) then he can move to the location (a + 1, b) or (a, b + 1) in

one step i.e Mr John either moves one unit distance horizontally or vertically.
To Do: Find the number of distinct paths which Mr John can take to reach (m,n) from (0,0)

via (x, y) in minimum number of steps.

For example if (x,y) is (2,2) and (m,n) is (3,3) then
1. 1st pathcanbe(0,0),(0,1),(0,2),(1,2),(2,2),(2,3),(3,3) 2. 2nd pathcanbe(0,0),(0,1),(0,2),(1,2),(2,2),(3,2),(3,3) 3. 3rd pathcanbe(0,0),(1,0),(1,1),(1,2),(2,2),(3,2),(3,3) 4. so on…

In the above example Mr. John has to pick up food from (x, y) and then deliver to (m, n) after starting from (0, 0).

We have provided a skeleton code which takes input, calls the function food() and prints the returned output which you will return from function food(). You have to only implement the function food() and return your answer without printing anything in the function.

Input: The first line of input will contain value of x. The second line of input will contain value of y. The third line of input will contain value of m. The fourth line of input will contain value of n. (only integer, follow skeleton code.).

Return Output : Only return the integer as asked in the question. The return type is an in- teger

Some points to note:

1. You have to write your code in C

2. In this question, we will be checking ONLY your output, so make sure to return correct format. Any output format mismatch will result in 0.

3. Use simple permutation and combination formula to solve this.

4

InputConstraints: 0<x<mand0<y<n. Example 1:

INPUT:

1 2 3 4

OUTPUT: 1 12

Example 2:

INPUT:

1 2 3 4

OUTPUT: 1 40

4 Birthdays (20 marks)

Mr. Sam was born on XX-YY-ZZZZ which happened to be a Saturday. If he died on AA-BB-CCCC, how many birthdays would he celebrate that fall on a Monday?

Assume, the year which is divisible by 4 are leap years and February has 29 days in a leap year. Also, rest of the calendar months have same days as in original calendar.

For example If Sam was born on 28-05-2022 and died on 28-05-2023 then number of birthdays he would have celebrated that fall on a Monday is 0 .

We have provided a skeleton code which takes input from standard input and calls the function birt() and prints the returned output which you have to return from function birt(). You have to write your code, in function birt() only and return your output. You cannot print anything in function.

Input:

1. The first line of input will contain value of XX as an integer type.
2. The second line of input will contain value of YY as an integer type. 3. The third line of input will contain value of ZZZZ as an integer type. 4. The fourth line of input will contain value of AA as an integer type. 5. The fifth line of input will contain value of BB as an integer type.
6. The sixth line of input will contain value of CCCC as an integer type.

Return Output : Only return the integer value as asked in the question. Some important points to note:

2 2 3 3

1 1 4 4

5

  1. You have to write your code in C
  2. In this question, we will be checking ONLY your Output, so make sure to return the correct format. Any output format mismatch will result in 0.
  3. Follow skeleton code, otherwise you can loose marks. You can make your own functions which can be called from function birt()
  4. Do not include day of birth and day of death in the number of birthdays he would have celebrated on Monday.
  5. If birthday falls on 29th Feb then he will celebrate his birthday on 1st March for every non leap year and on 29th Feb for every leap year.

Input Constraints: Example 1:

INPUT:

1 2 3 4 5 6

INPUT:

1 2 3 4 5 6

All valid Date such that date of death comes after the date of birth.

28
05
2022
05
05
2030

OUTPUT: 1 Example 2:

28
05
2020
02
02
2034

OUTPUT: 2
EXPLANATION:
We have got 28 May as Monday in the year 2022 and 2033

6

  • A9-xl3jbf.zip