Skip to content

Programming and Problem Solving

CSE · Final · Spring 24

Batch 66

This browser can’t show the PDF here

Open it, and your phone’s PDF viewer takes it, or download it.

Read the questions as text

Read off the PDF by AI, so it may have mistakes. The PDF is the original.

Daffodil International University Faculty of Science & Information Technology Department of Computer Science and Engineering Final Term Examination, Spring-2024 Course Code: CSE113 Course Title: Programming and Problem-Solving Level: 1 Term: 1 Batch: 66 Exam Duration: 2.0 Hours Marks: 40 Answer ALL Questions [The figures in the right margin indicate the full marks and corresponding course outcomes. All portions of each question must be answered sequentially.] 1. Demonstrate error finding and bug fixing: Identify the errors in the following code? Explain the errors and reasons why you think they are errors. [3, CO 2] a) #includ<stdio.h> stract myStructure { Int myNum; Char myLeter; }; Int main() { struct myStructure s1; s1.myNum = 13; sf.myLetter = 'B'; printf("My number: &d\n", s1.myNum); printf("My letter: &c\n", s1.myLetter); retarn 0; } b) Rewrite the code without any errors. [3, CO 2] 2. Generate the output for the given codes below (write only the output segment in a box): [3+3, CO 3] a) #include <stdio.h> int main() { int a = 5, b = 10; int *x, *y; x = &a; y = &b; *x += a, *y += b; printf("a=%d b=%d\n", *y + a, b); printf("x=%d y=%d\n", *x, a + *y); return 0; } b) #include <stdio.h> void pattern(int r) { int i, n = 1, j; for (i = 1; i <= r; i++) { for (j = 1; j <= i; j++) { printf("%d", n++); } printf("\n"); } } int main() { int n = 4; pattern(n); return 0; } c) #include <stdio.h> void countdown(int n) { if (n <= 0) { printf("Blastoff!\n"); } else { printf("%d\n", n); countdown(n - 1); // Recursive call with n-1 } } int main() { int start = 5; countdown(start); return 0; } 3. Identify the problems scenarios given below to write a full program for each of the following: a) In a severe heat wave in Bangladesh, the government launches a Heat Wave Advisory System to aid citizens in navigating extreme temperatures. Write a C program to provide warnings based on current temperature readings. [5] Input: An integer representing the current temperature. Output: "Baire Agun" if the temperature exceeds 40 degrees. "Sabdhane Jao" if the temperature is between 30 and 40 degrees (inclusive). "Baire Jaoa Jabe" if the temperature is less than 30 degrees. Sample Input | Sample output 30 | Sabdhane Jao 41 | Baire Agun b) In recent heat waves in Bangladesh, authorities have implemented a Temperature Monitoring and Analysis system. Write a C program to analyze consecutive temperatures over 7 days from monitoring stations. If temperatures exceed 35°C for more than 3 days, print "Heat-wave Burning". Otherwise, print "No more heat waves". [5] Input: Seven integers representing the temperatures recorded over consecutive 7 days. Output: "Heat-wave Burning" or "No more heat wave" otherwise. Sample Input | Sample output 25 29 31 36 34 37 35 | No more heat wave 31 34 37 36 30 39 38 | Heat-wave Burning c) During the COVID-19 pandemic, authorities are closely monitoring the spread of the virus across different regions. Write a program that takes a 2D array representing a grid of regions and their COVID-19 infection rates. The program should identify the highest infection rate and display it. [5] Input: An integer N (1 <= N <= 100) representing the number of rows and columns in the grid. N lines, each containing N integers representing the COVID-19 infection rates in each region. Output: The highest infection rate. Sample Input | Sample Output 100 200 150 300 250 180 210 190 220 | 300 d) Sarah is intrigued by the idea of transforming strings in unusual ways. She creates a program that replaces all vowels in a given string with a specified character. With this program, Sarah can input a string of characters and specify the character she wants to replace the vowels with. This unique transformation allows Sarah to explore unconventional text manipulation techniques and experiment with creative ways to modify strings in her programming projects. [5] Write a program that replaces all vowels in a given string with a specified character. Input: A string of characters. Next line, The character to replace the vowels with. Output: The modified string with vowels replaced. Sample Input | Sample Output hello world * | h*ll* w*rld e) In a heat wave, Sarah is exploring different ways to keep her mind engaged while staying indoors. She recalls the concept of palindromes (A palindrome is a sequence of characters that reads the same forwards and backward. For example, "radar" and "madam" are palindromic words, while "hello" and "12345" are not palindromes.) and decides to write a program to check if a given string is a palindrome. With this program, Sarah can challenge herself by entering various strings and testing whether they form palindromes. This activity not only helps Sarah pass the time but also enhances her understanding of programming concepts. [5] Write a program that checks if a given string is a palindrome. Input: A string of characters. Output: "Palindrome" if the input string is a palindrome. "Not a palindrome" if the input string is not a palindrome. Sample Input | Sample Output radar | Palindrome hello | Not a palindrome