Programming and Problem Solving
CSE · Midterm · Spring 24
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
Mid Semester Examination, Spring-2024
Course Code: CSE113 Course Title: Programming and Problem Solving
Level: 1 Term: 1
Exam Duration: 1.5 Hours Marks: 25
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. Expression Evaluation: [3] CO1
Illustrate the following expressions in detailed steps where A=5, B=7, C=3, D=2, E=2. remember all the variables here are integers. write each variable value after every evaluation to obtain a full mark.
a) D = --D * E || A + B / --C [1.5]
b) A *= B++ + C && D++ % C * E [1.5]
2. Demonstrate error finding and bug fixing: [6] CO2
Identify the errors in the following code? Explain the errors by providing the line numbers and reasons why you think they are errors.
#include <studio.H>
int mein() {
int n, i, sum = 0;
printf("Enter a positive integer: );
scanf("%d", %n);
for (i = 1; i <= n; i++);
{
sum += i;
}
printf("Sum = %d, sum");
returne 0;
}
[4]
Rewrite the code without any errors. [2]
3. Construct the output for the given codes below (write only the output segment in a box) [4] CO3
a) #include <stdio.h>
int main(){
int a = -5, b = 10;
if(a > 0 && b < 0){
a++;
}
else if(a < 0 && b < 0){
a--;
}
else if(a < 0 && b > 0){
a--;
b--;
}
else{
b--;
}
printf("%d\n", a + b);
return 0;
}
[2]
b) #include <stdio.h>
int main() {
int numbers[] = {3, -5, 2, 0, 7, -1};
int sum = 0;
for (int i = 0; i < 6; i++) {
int number = numbers[i];
if (number == 0) {
break;
}
if (number < 0) {
printf("Negative numbers are not allowed. Skipping...\n");
continue;
}
sum += number;
}
printf("The sum of positive numbers entered is: %d\n", sum);
return 0;
}
[2]
4. Analyze the problems scenarios given below to write a full program for each of the following [12] CO4
During Covid-19 pandemic, a city enforces a strict quarantine policy. Citizens are allowed to leave their homes only on certain days based on their ID number. For example, citizens whose ID numbers end with an odd digit can leave on Mondays, Wednesdays, and Fridays, while those ending with an even digit can leave on Tuesdays, Thursdays, and Saturdays. Write a program that takes a citizen's ID number as input and outputs the days they are allowed to leave their homes. [4]
Input: An integer N representing the citizen's ID number.
Output: A list of the days the citizen is allowed to leave their home "Monday, Wednesday, Friday" or "Tuesdays, Thursdays, Saturdays".
Sample Input | Sample Output
512 | Tuesdays, Thursdays, Saturdays
513 | Mondays, Wednesdays, Fridays
Sarah is in quarantine due to COVID-19 restrictions. To stay healthy and active, she decides to follow a daily exercise routine at home. Each day, she records the number of minutes spent exercising. Write a program to help Sarah analyze her exercise routine. Calculate the average minutes per day, and identify days where she exercised more than 30 minutes. [4]
Input: Seven integers representing the number of minutes Sarah spent exercising each day during the week.
Sample Input | Sample Output
45 20 35 40 25 50 30 | 35.0 4
| 1 3 4 6
Output: In first line, average minutes of exercise per day & Number of days where she exercised more than 30 minutes. In second line, A list of days where Sarah exercised more than 30 minutes.
During the COVID-19 pandemic, health officials are closely monitoring the spread of the virus in different regions. For several consecutive days, there are different ages of people affected by the coronavirus. Some people are considered at high risk if their age is a prime number; otherwise, they are classified as low risk. Write a C program to count the number of high-risk people and low-risk people based on their ages for each day's data. [4]
Input: First line, the input consists of a number of days.
For each day, the input starts with an integer N (1 <= N <= 10) representing the number of people affected by COVID-19.
The next line contains N space-separated integers representing the ages of the affected individuals for that day. Each age is in the range [1, 100].
Output: For each day, print two integers separated by a space: The number of high-risk people and the number of low-risk people.
Sample Input | Sample Output
3 | 2 3
5 | 1 2
21 32 37 45 53 | 1 3
3 |
25 28 31 |
4 |
18 22 27 29 |