0% found this document useful (0 votes)
36 views6 pages

QuestionPaper SetORANGE

Uploaded by

f20230568
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views6 pages

QuestionPaper SetORANGE

Uploaded by

f20230568
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Birla Institute of Technology & Science, Pilani

First Semester 2023-24


CS F111 – Computer Programming Online Programming Test
SET ORANGE
==================================================================================
26/11/2023 Max. Marks: 77M Max Duration: 135 mins
==================================================================================

General Instructions
● This paper consists of seven questions (Q1, Q2, Q3, Q4, Q5, Q6 and Q7), each carrying 11 marks.
● The paper is binary marked, so if your answer exactly matches the answer expected in the main.c
file for that specific question, you get 11 marks, else you get 0 marks for that question.
● Read all the instructions and the problem statements very carefully before attempting.
● Carefully follow the submission instructions mentioned below before uploading your solution on
the DomJudge portal.
● If you submit multiple submissions, only the latest one will be considered for evaluation. Whatever
you submit on the DomJudge portal will be considered as final. It is your responsibility to make
sure that you are submitting the correct file. Later, if some student claims that he/she has
mistakenly submitted the wrong file, we won’t be entertaining any such request and we will
evaluate based on whatever is submitted on the DomJudge portal.
● After submitting, on the portal you have an option to verify that you have submitted the correct
files. Ensure you verify it before the countdown timer expires.

Instructions to attempt the test


- Create a new directory with your 13 digit ID number, e.g. if your ID is 2023A2PS0001P, create a
directory with this ID.
- Download the Set_Pink.zip file from your contest in Domjudge portal and extract and paste all the
files into this directory.
- Now, right-click on the file “myScript.sh” which was just copied in the new directory and change
the permissions/properties of the file to allow it to Execute. Do not change permissions of any other
file that you copied.
- While attempting your questions, you are not allowed to modify the files myScript.sh, main.c, f1.h
f2.h, f3.h,…,f7.h, f6_helper.c, f7_helper.c except giving execute permission to myScript.sh. You
should neither make any changes to the function parameters, nor to the return types of any of the
functions in this file.
- You can only modify f1.c, f2.c, f3.c,...,f7.c.
- Now start attempting the questions below.
- To compile and execute, you must use myScript.sh only, e.g., if you want to compile and test your
solution for Q1, you must run the following on the terminal: ./myScript.sh 1
- Similarly, for all the other questions.
**Strictly do not write any printf/scanf functions in f1.c, f2.c, … f7.h. In case you write for
debugging purpose, you must remove them before your final submission on DomJudge.
**Strictly do not change the return type or the function parameters of the functions in f1.c, f2.c,
f3.c,..., f7.c

If you do any of the above dont’s you will definitely incur a heavy penalty.

Submission Instructions
Your final submission should be a zip folder with the name as your 13-digit ID number, e.g.,
2023A2PS0001P with 18 files in all (namely myScript.sh, main.c, f1.c, f2.c,..., f7.c, f1.h, f2.h,..., f7.h,
f6_helper.c, f7_helper.c).
Page 1 of 6
Problem Statements

Q1. In this question, you need to sort three numbers a, b, c in ascending order. Complete the
function aSort in f1.c. You are supposed to store the smallest number using the pointer n1, the
middle number using the pointer n2, and the greatest number using the pointer n3. The integer
pointer variables, n1, n2, and n3 are being passed by reference from main.c into f1.c.

Sample 1:
Enter numbers a b c: 20 10 30
After sorting
10 20 30

Sample 2:
Enter numbers a b c: 1 8 1
After sorting
118

Sample 3:
Enter numbers a b c: -1 -1 -1
After sorting
-1 -1 -1

Q2. In this question, given n two-dimensional points (i.e., x, y coordinates in the cartesian plane),
you are required to find out the Euclidean distance between the two points which are closest to
each other.

Euclidean Distance = √[(x2 – x1)2 + (y2 – y1)2]

Complete the function findMinDistance in f2.c

Hint 01: You may use mathematical functions such as pow(), sqrt() if required. These functions are
included in math.h header file.

Hint 02: pow(a,b) — returns a raise to b; sqrt(a) — returns the square root of a

Sample 1:

Enter the number of points: 3


Enter coordinates for point 1 (x y): 1 2
Enter coordinates for point 2 (x y): 3 4
Enter coordinates for point 3 (x y): 5 6

Output: Minimum Distance is = 2.83

Sample 2:

Enter the number of points: 4


Enter coordinates for point 1 (x y): -9 1
Enter coordinates for point 2 (x y): -6 -3
Enter coordinates for point 3 (x y): 4 2
Enter coordinates for point 4 (x y): 2.1 -8.3
Page 2 of 6
Output: Minimum Distance is = 5.00

Q3. In this question, you are given an array of integers arr and an unsigned integer rotateBy. You
need to rotate the array elements to the right rotateBy number of times.

Complete the function rotateArray in f3.c. You do not need to return or print anything in the
function rotateArray. Just make changes in the array being passed into the function rotateArray
itself.

Sample 1:

Enter the size of the array: 5


Enter the elements of the array: 1 2 3 4 5
Enter the number of positions to rotate right: 2

Rotated array: 4 5 1 2 3

Sample 2:

Enter the size of the array: 4


Enter the elements of the array: 10 20 30 40
Enter the number of positions to rotate right: 18

Rotated array: 30 40 10 20

Q4. In this question, you are given an array of integers arr. You are required to remove the adjacent
duplicates from the string. In the main function, you are given a code prompting the user to enter a
string as input. After processing, it should output a string without adjacent duplicates. Your code
should satisfy the following samples.

Complete the function removeDuplicates in f4.c.

Sample 1:

Enter a string: Hello World

Original string: Hello World

String after removing duplicates: Helo World

Sample 2:

Enter a string: C Programming

Original string: C Programming

String after removing duplicates: C Programing

Page 3 of 6
Q5. You are given a square matrix mat of size nxn. You have to rotate the matrix by 90 degrees in
CLOCKWISE direction (See samples below).

Complete the function rotateMatrix in f5.c. You do not need to return or print anything in the
function rotateMatrix. Just make changes in the matrix mat itself.

Sample 1:

Enter the value of n (for square matrix nxn): 3


Enter the elements of the matrix:
123
456
789

Rotated Matrix:
741
852
963

Sample 2:

Enter the value of n (for square matrix nxn): 4


Enter the elements of the matrix:
1234
5678
9012
3456

Rotated Matrix:
3951
4062
5173
6284

Q6 & Q7. In the main function, you already have code to prompt the user to enter the coefficients
and exponents for two polynomials, poly1 and poly2. Using a do-while loop, you take input from the
user for coefficients and exponents individually to create a term for polynomials in the linked list
using the addTerm function. Following that, you invoke the function addPolynomial, passing two
heads of the linked list (Polynomials) as an argument and interchangeCoefficients, passing the
address of two polynomials. The addPolynomial function adds the two linked lists (Polynomials) and
returns the head of the result polynomial, you can use addTerm function to create the result
Polynomial and interchangeCoefficients function interchanges the coefficient of polynomials based
on their exponents.
Complete the following functions:

(a) addPolynomials
(b) interchangeCoefficients

Your task is to code the functions addPolynomials and interchangeCoefficients in f6.c and f7.c,
respectively, to satisfy the following samples. (Enter: “0 0” to exit from entering the coefficient and
exponents of a polynomial)

Page 4 of 6
Sample 1:
Enter Polynomial 1 (Enter coefficient and exponent, separate with space. Enter 0 0 to stop):
Enter coefficient and exponent: 9 5
Enter coefficient and exponent: 5 4
Enter coefficient and exponent: 3 1
Enter coefficient and exponent: 1 0
Enter coefficient and exponent: 0 0

Enter Polynomial 2 (Enter coefficient and exponent, separate with space. Enter 0 0 to stop):
Enter coefficient and exponent: 1 4
Enter coefficient and exponent: 2 3
Enter coefficient and exponent: 1 2
Enter coefficient and exponent: 5 1
Enter coefficient and exponent: 6 0
Enter coefficient and exponent: 0 0

Polynomial 1: 9x^5 + 5x^4 + 3x^1 + 1x^0


Polynomial 2: 1x^4 + 2x^3 + 1x^2 + 5x^1 + 6x^0

Sum: 9x^5 + 6x^4 + 2x^3 + 1x^2 + 8x^1 + 7x^0

Coefficients Interchanged

Polynomial 1 after interchange: 9x^5 + 1x^4 + 5x^1 + 6x^0


Polynomial 2 after interchange: 5x^4 + 2x^3 + 1x^2 + 3x^1 + 1x^0

Sample 2:
Enter Polynomial 1 (Enter coefficient and exponent, separate with space. Enter 0 0 to stop):
Enter coefficient and exponent: 5 2
Enter coefficient and exponent: 1 1
Enter coefficient and exponent: 6 0
Enter coefficient and exponent: 0 0

Enter Polynomial 2 (Enter coefficient and exponent, separate with space. Enter 0 0 to stop):
Enter coefficient and exponent: 3 3
Enter coefficient and exponent: 7 2

Page 5 of 6
Enter coefficient and exponent: 4 1
Enter coefficient and exponent: 3 0
Enter coefficient and exponent: 0 0

Polynomial 1: 5x^2 + 1x^1 + 6x^0


Polynomial 2: 3x^3 + 7x^2 + 4x^1 + 3x^0

Sum: 3x^3 + 12x^2 + 5x^1 + 9x^0

Coefficients Interchanged

Polynomial 1 after interchange: 7x^2 + 4x^1 + 3x^0


Polynomial 2 after interchange: 3x^3 + 5x^2 + 1x^1 + 6x^0

—----------------------------------------------------------------------------------------------------

Page 6 of 6

You might also like