0% found this document useful (0 votes)
31 views3 pages

Cse Sample Question 4

The document describes a programming challenge presented to students at a picnic. It involves 4 tasks that require skills like functions, recursion, strings, arrays. The tasks get progressively harder and involve decoding scrambled words, finding hidden treasure on a map, sorting numbered stones in a game, and using function composition to find the final treasure location.

Uploaded by

Sakib Reza Saad
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)
31 views3 pages

Cse Sample Question 4

The document describes a programming challenge presented to students at a picnic. It involves 4 tasks that require skills like functions, recursion, strings, arrays. The tasks get progressively harder and involve decoding scrambled words, finding hidden treasure on a map, sorting numbered stones in a game, and using function composition to find the final treasure location.

Uploaded by

Sakib Reza Saad
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/ 3

MILITARY INSTITUTE OF SCIENCE AND TECHNOLOGY

Department of Industrial Production & Engineering (IPE)


Course Code: CSE281
Course Name: Computer Programming
Mid Term Examination Spring 2023
Total Marks: 30 Time:50 mins
1. In MIST, a group of students are preparing for a picnic organized by their computer 12
science club. The event is not just about enjoying delicious food and games; it's also an
opportunity for the students to showcase their programming skills. The club advisor,
Omar Azraf, has come up with a unique challenge for the students to solve during the
picnic using functions, recursion, strings, and arrays in the C programming language.

The Challenge:
On the day of the picnic, Omar Azraf gathers all the students and presents them with a
mysterious puzzle. He explains that they must work together to unravel a secret message
hidden within a set of tasks that involve various programming concepts. To succeed,
they must use their knowledge of functions, recursion, strings, and arrays to complete
each task.

Task 1 - Function and String Manipulation:


The students discover a series of encoded messages, and each message contains a
scrambled word. They are tasked with creating a function that takes a scrambled word as
input and returns the word in its correct form. By using string manipulation functions,
such as substring extraction, character swapping, and sorting, they must decode all the
messages to reveal the first clue.

Task 2 - Recursion and Array Operations:


With the first clue in hand, the students realize that they need to locate a hidden treasure
on the picnic grounds. Omar Azraf hands them a map, which is represented as a
two-dimensional array. However, the map is missing some crucial elements. The
students must implement a recursive function that searches for the missing coordinates,
using backtracking techniques. By placing the missing elements in the correct locations,
they uncover the next clue.

Task 3 - Array Sorting and Optimization:


The next clue leads the students to a challenging game involving a series of numbered
stones. Each student is given an array representing their current position on a game
board. They must implement a sorting algorithm, such as bubble sort or quicksort, to
rearrange the stones in ascending order. The catch is that they can only swap adjacent
stones. Once the stones are sorted, a secret code is revealed.

Task 4 - Function Composition and Final Reveal:


As the students decode the secret code, they realize that it represents a function
composition puzzle. Each student must write a function that takes an input, performs a
specific operation, and passes the result to the next student's function. The final student's
function will produce the ultimate result, which unveils the location of the hidden
treasure.
Outcome:
Through collaboration, problem-solving, and the application of their programming skills,
the students successfully navigate through the challenges. As they follow the clues, they
finally discover the hidden treasure—a chest filled with delicious treats to enjoy during
their picnic. The students celebrate their achievement, showcasing their creativity and
the power of programming in solving real-world puzzles.

a) In Task 1, the students are required to create a function that decodes scrambled words.
Describe the steps you would use to implement this function.
b) Task 4 involves function composition, where each student writes a function that
performs a specific operation and passes the result to the next student's function. How
would you ensure the correct order of function execution to obtain the final result?
c) Imagine that you were one of the students participating in this picnic-themed
programming challenge. Which task do you think would be the most challenging for you
personally, and why? How would you approach and tackle that specific task?

2. Observe the codes carefully and answer the following questions: 4

How many characters are there in the string ‘OpenAI’ in the following
code?

#include <stdio.h>
int main() {
char str[] = "OpenAI";
int count = 0;
while (str[count] != '\0') {
count++; }
printf("The length of the string is %d.\n", count);
return 0;
}

How many elements are there in the ‘numbers’ array in the following code?

#include <stdio.h>
int getArrayLength(int arr[]) {
int count = 0;
while (arr[count] != '\0') {
count++; }
return count; }
int main() {
int numbers[] = {2, 4, 6, 8, 10};
int length = getArrayLength(numbers);
printf("The length of the array is %d.\n", length);
return 0;
}
What is the output of the following code?

#include <stdio.h>
void printNumbers(int n) {
if (n <= 0) {
return;
}
printNumbers(n - 1);
printf("%d ", n);
}
int main() {
int num = 5;
printf("Numbers from 1 to %d: ", num);
printNumbers(num);
printf("\n");
return 0;
}

3. Explain ‘Function Arguments’ with examples. 6

4. Briefly discuss the operation of the following two functions: 4


a) strcat()
b) strrev()

5. Define “Recursion” with an example. 4

You might also like