Date
SRN
Semester End Examination March 2024 (Sample Docu-
ment)
First Semester [Link]
Course Title: Advanced C Program-
ming & Applications
Course Code: B24CI0201
Dura- 3 Hours Max.
tion: Marks: 100
Note:
1. Answer all questions in Section-1 and any one full question from
each of sections II, III and IV.
2. Verify and ensure that the question paper is completely printed be-
fore answering the question paper.
3. Any queries/discrepancies regarding the question paper, must be
brought to the notice of the invigilator
4. Students must check the course title and course code before an-
swering the question paper
5. Use of Data handbook, Steam Tables and Psychrometric charts are
permitted.
Bloo
Q. Mar
Questions CO PO m’s
No ks
level
Note: Answer all the Questions of section-I (Question No. 1 to 2).
Section-I
1 a
. ) Write an if-else-if ladder in C to determine
the income tax slab of a person based on
their annual income using the following cri-
teria:
· ₹10,00,000 and above: Tax Rate –
30%
5 1 1-3 3
· ₹5,00,000 to ₹9,99,999: Tax Rate –
20%
· ₹2,50,000 to ₹4,99,999: Tax Rate –
10%
· Below ₹2,50,000: Tax Rate – 0%
Assume that income is a float variable storing
the person's annual income in rupees.
b What will be the output of the following C 5 2 1-3 2
) program?
#include <stdio.h>
int main() {
int arr[5] = {10, 20, 30, 40, 50};
int *ptr = arr;
printf("%d\n", ptr[2]);
printf("%d\n", arr[2]);
arr[4] = 100;
printf("%d\n", arr[4]);
return 0;
} And explain why we are not using '&' while defining a pointer here?
c) Explain the structure used in the below program and predict the out-
put.
#include <stdio.h>
typedef struct {
int emp_id;
char name[20];
float salary;
} Employee;
int main() {
Employee e[4] = { 5 3 1-3 3
{201, "Rama", 45000.0},
{202, "Krishna", 52000.0},
{203, "Vasudeva", 47500.5},
{204, "Hari", 50000.0}};
for (int i = 1; i < 4; i += 2) {
printf("Employee ID: %d, Salary: %.2f\n", e[i].emp_id, e[i].salary);
}
return 0;
}
d)
You are developing a C program to store and retrieve employee
records using a binary file named [Link]. Each record includes:
Employee ID (int), Name (string), and Salary (float).
Based on this scenario:
5 4 1-3,5 2
(i) How will you define the structure to store employee details?
(ii) Which function is used to write the structure to a binary file? Show
its syntax.
(iii) Write a code snippet to write one Employee structure variable
into the file.
(iv) How will you read the stored data back from the file?
(v) What are the differences between 'rb' and 'wb'?
2. a)
You are developing a C program to manage the inventory of a book-
store. Each book's details include: Book ID, Title, Author Name, Price,
and Quantity in Stock.
5 5 1-5 2
Which C programming concepts would be most appropriate to store
and manage the details of 200 books efficiently, persistently and why?
Explain how these concepts help in organizing and accessing the data
effectively.
b) You are working in a Unix environment to perform the following tasks 5 6 5 3
using suitable commands:
(i). Create a directory named Project.
Page 2 of 6
(ii). Move into the Project directory.
(iii). Create an empty file named [Link] inside it.
(iv). Display the path of the current directory.
(v). List all the files in the current directory with detailed information
(permissions, size, date, etc.).
Write the commands used for each task.
c)
You are building a C program to manage the heights (in cm) of partici-
pants in a sports event. Since the number of participants is not fixed
and will be entered by the user at runtime, you decide to use dynamic
memory allocation instead of static arrays.
Based on this scenario:
5 2 1-3 2
(i) Which standard library function in C would you use to allocate
memory for storing participant heights dynamically? Explain with
the syntax.
(ii) Write a code snippet to allocate memory for n float values
(heights), where n is entered by the user.
(iii) How will you safely release the memory once it is no longer
needed?
d) You are storing the string str[] = "Bengaluru is Beautiful" in a character
array.
(i). What is the length returned by strlen()?
(ii). Why is scanf("%s", str); not ideal for taking this? 5 1 1-3 2
(iii). Which standard input function allows spaces in the string input?
(iv). What will strcmp("Hello", "hello") return and why?
(v). What will sizeof(str) return?
Note: Answer the following questions by selecting any one full question from each of the following sections.
Each main question carries 20 Marks
Section-II
3. a) Write a modular program to calculate a mobile user's monthly bill. The
bill includes fixed monthly charge, cost per call and number of calls
made.
Formula: Total Bill=Fixed Charge + (Number of Calls × Cost per Call)
Function prototype: 8 1 1-3 1
void input(float *fixed_charge, int *num_calls, float *cost_per_call);
float calculate_bill(float fixed_charge, int num_calls, float
cost_per_call);
void output(float total_bill);
b) (i). Write the code snippet to read the temperature of each day for a 10 1 1-3 2
week (7 float values), store them in an array, and find the min-
imum temperature.
Function prototype:
void inputTemperatures(int n, float temps[n]);
float findLowest(int n, float temps[n]);
(ii). You are recording the temperatures (in °C) for 7 days of the week:
30.5, 30.5, 30.5, 34.0, 33.0, 36.0, 36.0
Page 3 of 6
Declare a suitable array in C to store this data and initialize it with
the given values. Also, mention the value that will be returned by
the findLowest() function when this array is used as input.
c) You read a string using scanf("%s", str);. The input is "REVA Univer-
2 1 1-3 2
sity". What will be stored in str and why?
OR
4. a) Write a modular C program to swap two strings.
Function prototype:
void read_string(char str[], int size); 7 2 1-3 1
void print_string(char str[]);
void swap_strings(char str1[], char str2[]);
b) a) Write the code snippet to perform the following operations on an
integer array using dynamic memory allocation:
(i). Create an integer array of size n using dynamic memory
allocation.
(ii). Initialize the array elements by reading from the user.
(iii). Delete the array by freeing the dynamically allocated
memory. 7 2 1-3 1
Use the following function prototypes for each of the above opera-
tions:
int* create_array(int n);
void initialize_array(int *arr, int n);
void delete_array(int **arr);
c) Write the code snippet to perform the following operations on a singly
linked list:
6 2 1-3 1
(i). Create node.
(ii). Insert elements at the beginning of the list.
Section-III
5. a) Write a modular C program using array of structures and functions to
perform the following tasks:
(i). Accept the number of rectangles from the user.
(ii). For each rectangle, accept its length and width.
(iii). Calculate the area of each rectangle.
(iv). Display the area of each rectangle.
typedef struct {
float length; 8 3 1-3 1
float width;
float area;
} Rectangle;
Function prototype:
void input(int n, Rectangle rects[n]);
void calculateArea(int n, Rectangle rects[n]);
void output(int n, Rectangle rects[n]);
b) Write a C program to perform the following tasks using file handling 10 4 1-3,5 1
functions:
(i). Read the details of n students from the user and store
them in an array of structures.
Page 4 of 6
(ii). Write the array of structures to a text (ASCII) file.
typedef struct {
int id;
char name[50];
float marks;
} Student;
Function prototypes:
void inputStudents(Student students[], int n);
void writeToTextFile(Student students[], int n, const char *filename);
c) Given a structure Book with members title, author, price, and
year_of_publication, define the structure and declare a structure vari- 2 3 1-3 2
able.
OR
6. a) A modular program uses array of structures to calculate electricity bills
for multiple consumers and finds the highest bill. Explain the below
structure definition and write a code snippet for the following func-
tion prototypes:
typedef struct
{
int consumerID;
8 3 1-3 1
float unitsConsumed;
float billAmount;
} Bill;
Function prototypes:
void input(int n, Bill bills[n]);
void calculateBills(int n, Bill bills[n]);
Bill findHighestBill(int n, Bill bills[n]);
b) Write a modular C to program to perform the following tasks using
file handling functions:
(i). Read the details of n students from the user and store them
in an array of structures.
(ii). Write the array of structures to a binary file.
typedef struct {
int id; 10 4 1-3,5 1
char name[50];
float marks;
} Student;
Function prototypes:
void inputStudents(Student students[], int n);
void writeToBinaryFile(Student students[], int n, const char *file-
name);
c) Given a structure Car with model_name, year, and mileage. Define the
2 3 1-3 2
structure and declare an array of 3 cars.
Page 5 of 6
Section-IV
7. a) Write a modular C program to modify array elements in such a way
that
Mutiples of 2 is replaced with 0
Multiples of 5 is replaced with 1
10 5 1-5 1
other numbers are displayed as it is
Function prototypes:
void modifyArrayElements(int arr[], int size);
void printArray(int arr[], int size, const char *message);
b) (i). Perform the following task using Unix commands:
Create a file named [Link] and add the following tasks to it:
Study for lab IA
Finish writing record
Work on mini project
10 6 5 3
Save the file.
Display the contents of the file on the terminal.
(ii). You have a directory called temp containing old log files and un-
wanted folders. Delete the folder and its contents permanently.
Explain why that command should be used very carefully?
OR
8. a) Write a modular program in C to calculate the velocity of a vehicle,
use the function prototypes below to do the respective activities.
void input(float *distance, float *time);
float compute_velocity(float distance, float time);
10 5 1-5 1
void output(float velocity);
Note:
Make sure time is not 0, since you cant divide any value with 0. If
time is 0 then return -1.
b) (i). You're working on a project and need to create the following
structure:
10 6 5 3
Create the folder structure using Unix Commands.
(ii). You have a file called [Link]. You need to make a backup copy
and save the backup copy in a subfolder called Backup. Create the
subfolder “Backup” if it is not present. Rename the original file to
report_old.txt.
Page 6 of 6