VNSGU BCA Sem 2: Programming Skills Using C (204) Practical Solutions - Set D¶
Paper Details
- Subject: Programming Skills Using C
- Subject Code: 204
- Set: D
- Semester: 2
- Month/Year: April 2025
- Max Marks: 25
- Time Recommendation: 45 Minutes
- Paper: View Paper | Download PDF
Questions & Solutions¶
All questions are compulsory¶
Q1: Student Record Sorting¶
Max Marks: 10
Consider a structure as follow:
Write a C program that accept details of N-students and display student's details in descending order on marks.1. Data Structure & Selection Sort¶
Implement student records and sort them by performance using a simple sorting algorithm.
Hint
Accept \(N\) from the user, then use an array of struct stud_info. Use a nested loop (Bubble or Selection sort) to rearrange the array based on the marks field.
flowchart TD
start[Start]
input_n[Accept N Students]
loop_in[Input Details Loop]
sort[Sort by Marks Desc]
loop_out[Display Results Loop]
done[End]
start --> input_n
input_n --> loop_in
loop_in --> sort
sort --> loop_out
loop_out --> done
View Solution & Output
#include <stdio.h>
#include <string.h>
struct stud_info {
int rno;
char sname[30];
int marks;
};
int main() {
int n, i, j;
struct stud_info s[100], temp;
printf("Enter number of students: ");
scanf("%d", &n);
// [1] Accept Input
for(i = 0; i < n; i++) {
printf("\nEnter Details for Student %d:\n", i+1);
printf("Roll No: "); scanf("%d", &s[i].rno);
printf("Name: "); scanf("%s", s[i].sname);
printf("Marks: "); scanf("%d", &s[i].marks);
}
// [2] Sort Descending (Bubble Sort)
for(i = 0; i < n - 1; i++) {
for(j = 0; j < n - i - 1; j++) {
if(s[j].marks < s[j+1].marks) {
temp = s[j];
s[j] = s[j+1];
s[j+1] = temp;
}
}
}
// [3] Display Output
printf("\nStudents Sorted by Marks (Descending):\n");
printf("RNo\tName\tMarks\n");
for(i = 0; i < n; i++) {
printf("%d\t%s\t%d\n", s[i].rno, s[i].sname, s[i].marks);
}
return 0;
}
Step-by-Step Explanation:
1. Initialization: Define the stud_info structure and accept the total number of students N from the user.
2. Logic Flow: Read details into an array of structures and apply the Bubble Sort algorithm to sort them based on marks in descending order.
3. Completion: Display the sorted student records in a tabular format showing Roll No, Name, and Marks.
Q2: Python String Menu¶
Max Marks: 10
Write a Python program that accept a line of text from user and perform following operations on it. 1. Toggle case 2. Title case 3. Sentence case 4. Exit Note: Menu will be repeated until user select Exit option.
1. Multi-Case String Transformation¶
Implement a command-line interface to manipulate text formatting.
Hint
Use input().swapcase() for toggle, input().title() for title case, and input().capitalize() for sentence case. Wrap everything in a while True loop.
flowchart TD
start[Start]
input[Accept Text]
menu[Show Menu]
choice[User Choice]
proc[Transform Text]
exit[Exit]
start --> input
input --> menu
menu --> choice
choice -- "1,2,3" --> proc
proc --> menu
choice -- "4" --> exit
View Solution & Output
# [1] Accept initial text
text = input("Enter a line of text: ")
while True:
print("\n--- STRING MENU ---")
print("1. Toggle Case")
print("2. Title Case")
print("3. Sentence Case")
print("4. Exit")
choice = input("Enter your choice (1-4): ")
if choice == '1':
print("Result:", text.swapcase())
elif choice == '2':
print("Result:", text.title())
elif choice == '3':
print("Result:", text.capitalize())
elif choice == '4':
print("Exiting...")
break
else:
print("Invalid Choice!")
Step-by-Step Explanation:
1. Initialization: Accept a string input and enter a while True loop to display a repeating menu.
2. Logic Flow: Based on user choice, apply swapcase(), title(), or capitalize() methods to transform the text.
3. Completion: Print the transformed result or exit the loop if the user chooses the exit option.
Q3: Viva Preparation¶
Max Marks: 5
Potential Viva Questions
- Q: How do you swap two structures in C?
- A: By using a temporary structure variable of the same type and performing three assignment operations.
- Q: Difference between
title()andcapitalize()in Python? - A:
title()capitalizes the first letter of EVERY word;capitalize()only the first letter of the ENTIRE string. - Q: What is a nested loop?
- A: A loop inside another loop, often used for processing 2D arrays or sorting.
- Q: What is Bubble Sort?
- A: A simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.
- Q: How can you check if a string consists only of digits in Python?
- A: Use the
.isdigit()method. - Q: What is
structpadding in C? - A: It is the addition of empty bytes by the compiler between structure members to align them with memory boundaries for faster access.
Common Pitfalls
- Infinite Loops: Ensure the Python menu has a clear
breakcondition for choice 4. - Buffer Overflow: In C,
char sname[30]can only hold 29 characters + null. Usescanf("%29s", ...)for safety.
Quick Navigation¶
Related Solutions¶
| Set | Link |
|---|---|
| Set A | Solutions |
| Set B | Solutions |
| Set C | Solutions |
| Set D | Current Page |
| Set E | Solutions |
| Set F | Solutions |
Last Updated: April 2025