Assignment 2 SPL
Assignment 2 SPL
Q.3 a) Identify and correct the errors of the following code: [3]
struct student{
char name[];
int ID;
}
int main() {
student s1,s2;
s1.name="Rahim";
s1.ID=101;
struct student* s_ptr = s2;
scanf("%s",&s_ptr.name);
scanf("%d",&s_ptr.ID);
}
Page 1 of 2
Q.3 b) Write a C program to store the following information about patients and perform the following [5]
operations:
i. Create a structure named Patient with the following members: name (string), age (int),
height (float), weight (float) and BMI (float).
ii. Declare an array of size 100 of type Patient structures.
iii. Take inputs (name, age, height, weight) from the keyboard and calculate the BMI of the
respective patient using the formula: weight / (height).
iv. Find and display all the information of the youngest patient with lowest age.
Q.4 a) Write the output of the program provided below on the left. [4]
b) Find the output of the code provided below on the right. [4]
b) Suppose, you are trying to save a simple string in a file named “string.txt”, and for this you have
written the following code:
FILE *fp = fopen("string.txt", "w");
fprintf(fp, "Yet another string\n");
fclose(fp);
i. What will happen if the file does not exist? [1]
ii. What is the difference between read and append mode? [1]
iii. Write C code segment to re-open the same file in append mode and add a new string “This
[2]
is another string” into the file and then close the file.
Page 2 of 2
United International University (UIU)
Dept. of Computer Science & Engineering (CSE)
Final Exam:: Trimester: Summer 2024
Course Code: CSE 1111, Course Title: Structured Programming Language
Total Marks: 50 Duration: 2 hours
[Any examinee found adopting unfair means will be expelled from the
trimester/program as per UIU disciplinary rules.]
There are FIVE questions. Answer all the questions. Marks are indicated in the right margin.
Q.1 a) Implement getSumMean(float marks[ ], int N, int type) function, which computes sum and mean
of marks of N students from an input array A.
i. In the main() function, initialize an array of floats to store the marks of 100 students. Take [1]
the values from the user as input.
ii. Take 2 values as input from user: an integer (number of elements) & an integer (value type). [1]
iii. Call the getSumMean() function from the main() passing those values. If the value type is 1,
then calculate and return the sum of N elements in the array A. If the value type is 2, then [2]
calculate and return the average/mean of N elements in the array A.
iv. What type of argument passing is used in getSumMean() function call? Call-by-value, or call- [1]
by-reference? Justify and explain.
b) Find the output of the following program (left). Notice the local and global contexts. [5]
Page 1 of 2
Q.3 b) Suppose you are developing a C program for the UIU Sports Club to store and manage players’
performance for the VC Cup football Season 3 to be held in 2025. Your task is to create a C
program that can store, manage and manipulate the data to select best goal scorer. Write a C
program that will:
i. Create a structure named player to store the following information of each player [1]
participating in the tournament as follows (use appropriate data types and variable names
for all the features):
- Name
- ID
- Number of matches played, and
- An array G[ ] of scored goals in each of the matches played.
ii. Scan information as input from the user for 120 players registered in the tournament. [1]
iii. Write a function goalsScored(struct player p, int matches) that takes a player structure [2]
and total number of matches played and returns the sum of the elements of array G[ ] to
get total goals scored by a particular player.
iv. Write a function selectBestScorer(struct player b[ ], int total_players) that takes an array [3]
of player structure and total number of players and returns the index of the player array
representing the player with highest number of goals scored.
Q.4 a) Write the output of the program provided below on the left. What type of argument passing is used [5]
in mystery() function call? Call-by-value, or call-by-reference? Justify and explain.
b) Find the output of the code provided below on the right. [5]
int fun(int *a, int *b){ void f(char *s1, char *s2, int n, int *a) {
if (*a > 1) int i;
return *a + *b; for(i=0; i<n; i++) {
else if(s1[i] > s2[i]) *a = *a+1;
return *b - *a; else if(s1[i]<s2[i]) *(s1+i)=*(s2+i);
} else if(s1[i] == s2[i]) *a = *a-1;
}
int main(void) { }
int x = -10; void main() {
int y = 20; int a, b;
char s1[] = "worldcupBangladesh";
printf("The result is %d", char s2[] = "BanglaWash";
fun(&x, &y)); a = 0;
} f(s1,s2,13,&a);
printf("%d\n s1=%s , s2=%s\n",a,s1,s2);
}
C Code for 4(a) C Code for 4(b)
Page 2 of 2