PROG SKILL (204) Set A - Practical Solutions¶
Paper Information¶
| Attribute | Value |
|---|---|
| Subject | Programming Skills Using C |
| Subject Code | 204 (PROG SKILL) |
| Set | A |
| Exam Type | Practical |
| Max Marks | 25 |
| Month/Year | April 2024 |
Question 1: Student Structure with Total and Percentage¶
Question 1: Create Structure and Calculate
Q: Write a program to create a structure of five student with a member name, roll no, 3 subject marks calculate total and percentage display it proper format.
Requirements: - Create structure with: name, roll_no, 3 subject marks - Calculate total marks - Calculate percentage - Display in proper format - Handle 5 students
Solution - C Language
#include <stdio.h>
#include <string.h>
// Define structure for student
struct Student {
char name[50];
int roll_no;
int marks[3];
int total;
float percentage;
};
int main() {
struct Student s[5];
int i, j;
// Input data for 5 students
printf("Enter details for 5 students:\n\n");
for(i = 0; i < 5; i++) {
printf("Student %d:\n", i + 1);
printf("Enter Name: ");
scanf(" %[^\n]", s[i].name);
printf("Enter Roll No: ");
scanf("%d", &s[i].roll_no);
printf("Enter 3 Subject Marks: ");
for(j = 0; j < 3; j++) {
scanf("%d", &s[i].marks[j]);
}
// Calculate total
s[i].total = 0;
for(j = 0; j < 3; j++) {
s[i].total += s[i].marks[j];
}
// Calculate percentage
s[i].percentage = s[i].total / 3.0;
printf("\n");
}
// Display results in proper format
printf("\n========================================\n");
printf(" STUDENT MARKSHEET - SET A\n");
printf("========================================\n\n");
printf("%-5s %-15s %-8s %-10s %-12s %-12s\n",
"No", "Name", "Roll", "Total", "Percentage", "Grade");
printf("-------------------------------------------------------------\n");
for(i = 0; i < 5; i++) {
char grade;
if(s[i].percentage >= 80) grade = 'A';
else if(s[i].percentage >= 60) grade = 'B';
else if(s[i].percentage >= 40) grade = 'C';
else grade = 'F';
printf("%-5d %-15s %-8d %-10d %-12.2f %-12c\n",
i + 1, s[i].name, s[i].roll_no,
s[i].total, s[i].percentage, grade);
}
printf("=============================================================\n");
return 0;
}
Expected Output - C
Enter details for 5 students:
Student 1:
Enter Name: Rahul
Enter Roll No: 101
Enter 3 Subject Marks: 85 90 88
Student 2:
Enter Name: Priya
Enter Roll No: 102
Enter 3 Subject Marks: 78 82 80
Student 3:
Enter Name: Amit
Enter Roll No: 103
Enter 3 Subject Marks: 92 88 95
Student 4:
Enter Name: Sita
Enter Roll No: 104
Enter 3 Subject Marks: 75 80 78
Student 5:
Enter Name: Ram
Enter Roll No: 105
Enter 3 Subject Marks: 88 85 90
========================================
STUDENT MARKSHEET - SET A
========================================
No Name Roll Total Percentage Grade
-------------------------------------------------------------
1 Rahul 101 263 87.67 A
2 Priya 102 240 80.00 A
3 Amit 103 275 91.67 A
4 Sita 104 233 77.67 B
5 Ram 105 263 87.67 A
=============================================================
Solution - Python
# Student data structure using dictionary
students = []
# Input data for 5 students
print("Enter details for 5 students:\n")
for i in range(5):
print(f"Student {i + 1}:")
name = input("Enter Name: ")
roll_no = int(input("Enter Roll No: "))
print("Enter 3 Subject Marks (space separated): ", end="")
marks = list(map(int, input().split()))
# Calculate total and percentage
total = sum(marks)
percentage = total / 3
# Store student data
student = {
'name': name,
'roll_no': roll_no,
'marks': marks,
'total': total,
'percentage': percentage
}
students.append(student)
print()
# Display results in proper format
print("\n" + "=" * 60)
print(" STUDENT MARKSHEET - SET A")
print("=" * 60 + "\n")
# Header
print(f"{'No':<5} {'Name':<15} {'Roll':<8} {'Total':<10} {'Percentage':<12} {'Grade':<10}")
print("-" * 60)
# Student data
for i, s in enumerate(students, 1):
# Determine grade
if s['percentage'] >= 80:
grade = 'A'
elif s['percentage'] >= 60:
grade = 'B'
elif s['percentage'] >= 40:
grade = 'C'
else:
grade = 'F'
print(f"{i:<5} {s['name']:<15} {s['roll_no']:<8} "
f"{s['total']:<10} {s['percentage']:<12.2f} {grade:<10}")
print("=" * 60)
Expected Output - Python
Enter details for 5 students:
Student 1:
Enter Name: Rahul
Enter Roll No: 101
Enter 3 Subject Marks (space separated): 85 90 88
Student 2:
Enter Name: Priya
Enter Roll No: 102
Enter 3 Subject Marks (space separated): 78 82 80
Student 3:
Enter Name: Amit
Enter Roll No: 103
Enter 3 Subject Marks (space separated): 92 88 95
Student 4:
Enter Name: Sita
Enter Roll No: 104
Enter 3 Subject Marks (space separated): 75 80 78
Student 5:
Enter Name: Ram
Enter Roll No: 105
Enter 3 Subject Marks (space separated): 88 85 90
============================================================
STUDENT MARKSHEET - SET A
============================================================
No Name Roll Total Percentage Grade
------------------------------------------------------------
1 Rahul 101 263 87.67 A
2 Priya 102 240 80.00 A
3 Amit 103 275 91.67 A
4 Sita 104 233 77.67 B
5 Ram 105 263 87.67 A
============================================================
Explanation
C Language:
- struct Student defines a blueprint with name, roll_no, marks array, total, and percentage
- s[5] creates an array of 5 student structures
- Nested loops handle input and calculations for all 5 students
- scanf(" %[^\n]", ...) reads string with spaces for names
- Grade is determined using simple if-else conditions
Python:
- Dictionary stores each student's data with clear key-value pairs
- list(map(int, input().split())) efficiently reads 3 marks in one line
- sum(marks) calculates total automatically
- Formatted string literals (f-strings) create clean table output
- Grade logic identical to C version
Concept Deep Dive: Structures vs Dictionaries
C Structure: - Groups related data under one name - Memory-efficient, contiguous storage - Requires manual memory management for strings - Compile-time type checking
Python Dictionary: - Dynamic, flexible key-value storage - Automatic memory management - No fixed schema - can add/remove keys - Runtime type checking
Question 2: Viva Preparation¶
Question 2: Viva + Journal
Q: Viva + Journal (5 Marks)
Be prepared to explain: - Your program logic - Structure/Dictionary concepts - Calculation methodology
Potential Viva Questions
Q1: What is a structure in C? - A: A structure is a user-defined data type that groups related variables of different types under a single name. It allows organizing complex data efficiently.
Q2: Why use an array of structures instead of separate variables? - A: An array of structures allows handling multiple records efficiently with loops, reduces code repetition, and makes data management organized.
Q3: How is percentage calculated? - A: Percentage = (Total marks obtained / Maximum possible marks) × 100. Here, total = sum of 3 subjects, max = 300, so percentage = total/3.
Q4: What is the difference between structure and array? - A: Array stores elements of same data type with contiguous memory. Structure stores elements of different data types grouped together under one name.
Q5: Explain the format specifiers used in printf.
- A: %s for string, %d for integer, %f for float, %.2f for float with 2 decimal places, %c for character, - for left alignment, number for width.
Common Pitfalls
- Buffer overflow: Ensure name array size (50) is sufficient
- Integer division: Use
3.0instead of3for accurate percentage - Input buffer: Use space before
%[^\n]to clear buffer - Array bounds: Always check marks array index stays 0-2
- Format alignment: Match width specifiers with actual data length
Related Solutions¶
| Set | Link |
|---|---|
| Set A | Current Page |
| Set B | Coming Soon |
| Set C | Coming Soon |
| Set D | Coming Soon |
| Set E | Coming Soon |
| Set F | Coming Soon |