Structured Programming
SWE · Midterm · Fall 24
Section ALL
Read the questions as text
Read off the PDF by AI, so it may have mistakes. The PDF is the original.
Daffodil International University
Department of Software Engineering
Faculty of Science & Information Technology
Midterm Examination, Fall 2024
Course Code: SE 121; Course Title: Structured Programming
Sections & Teachers: ALL
Time: 1 Hour 30 Mins
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. a) Define header files in C programming. Describe the rules for valid and invalid identifiers in C with examples. | [Marks-5] | CLO-1
Level-1
1. b) Consider the following C program,
#include <stdio.h>
int main() {
int a = 15, b = 7, c;
c = (a - b) / 2 + o;
printf("The value of c: %d\n", c);
a *= 3;
printf("The value of a: %d\n", a);
a++;
c = a % (b + 5) / b + b;
printf("The updated value of c: %d\n", c);
return 0;
}
Interpret the output of the program and explain how the arithmetic and assignment operators are applied in the calculations. | [Marks-5] | CLO-1
Level-2
2. a) Examine the following code for any errors and rewrite the code with the necessary corrections.
#include <stdio.h>
int main() {
int number sum = 0;
printf("Enter a number: ");
scanf("%d", number);
while (number =! 0)
sum += number % 10;
number /= 10;
}
printf("Sum of digits is: %d\n", sum);
return 0;
}
| [Marks-5] | CLO-2
Level-3
2. b) A school is interested in helping students learn about even and odd numbers. The objective is to calculate the sum of all even numbers and the sum of all odd numbers within a given range defined by two positive integers. Refer to the sample input and output below for a clearer understanding.
Sample Input: | Sample Output:
5 9 | The sum of Even Numbers: 14
The sum of Odd Numbers: 21
Articulate the steps required to build the program and solve this logic using the C programming language. | [Marks-5]
2. c) Construct a C program based on the following scenario,
In rural Bangladesh, people often calculate how much money they need to save depending on the number of animals they own, like cows or chickens. Different types of animals require different amounts of savings for their care.
Your task is to create a simple system that calculates the total savings needed based on the number of animals and their respective care costs.
- If the user owns 1 cow - Add 5000 taka to the savings.
- If the user owns 2 cows - Add 10,000 taka to the savings.
- If the user owns 3 or more cows - Add 15,000 taka to the savings.
- If the user owns 1 chicken - Add 100 taka to the savings.
- If the user owns 2 chickens - Add 200 taka to the savings.
- If the user owns 3 or more chickens - Add 300 taka to the savings.
If the input is invalid, such as a negative number of animals, display: "Please enter a valid number."
Sample Input: | Sample Output:
2 5 | Total savings: 10300
Explanation: For the first sample, the first input is 2 which is the number of cows and the second input is 5 which is the number of chickens.
2 cows = 10,000 taka
5 chickens = 300 taka
So total savings are = (10000 + 300) = 10300 | [Marks-5]