Skip to content

VNSGU BCA Sem 2: Programming Skills Using C (204) Practical Solutions - Set C

Paper Details

  • Subject: Programming Skills Using C
  • Subject Code: 204
  • Set: C
  • 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: App Data Structure

Max Marks: 10

Create structure App Data with following members: App Name, download Count, rating, developer. Accept 5 Application details from user and print details of application whose rating is highest.

1. Structure Definition & Input

Define the App structure and read 5 records.

Hint

Use struct AppData to group related variables. Use a loop to accept input for an array of 5 structures.

flowchart TD
start[Start]
struct[Define struct AppData]
loop[Loop 5 times]
input[Accept Name, DL, Rating, Dev]
done[Input Complete]

start --> struct
struct --> loop
loop --> input
input -- "Next" --> loop
input --> done
View Solution & Output
#include <stdio.h>

struct AppData {
    char appName[50];
    long downloadCount;
    float rating;
    char developer[50];
};

int main() {
    struct AppData apps[5];
    int i, maxIndex = 0;

    // [1] Input data
    for(i = 0; i < 5; i++) {
        printf("\nEnter details for App %d:\n", i + 1);
        printf("Name: ");
        scanf("%s", apps[i].appName);
        printf("Downloads: ");
        scanf("%ld", &apps[i].downloadCount);
        printf("Rating: ");
        scanf("%f", &apps[i].rating);
        printf("Developer: ");
        scanf("%s", apps[i].developer);

        // [2] Track highest rating
        if(apps[i].rating > apps[maxIndex].rating) {
            maxIndex = i;
        }
    }

    // [3] Display result
    printf("\n--- App with Highest Rating ---\n");
    printf("Name: %s\n", apps[maxIndex].appName);
    printf("Downloads: %ld\n", apps[maxIndex].downloadCount);
    printf("Rating: %.1f\n", apps[maxIndex].rating);
    printf("Developer: %s\n", apps[maxIndex].developer);

    return 0;
}

Step-by-Step Explanation: 1. Initialization: Define a struct AppData and declare an array of 5 structures to store app details. 2. Logic Flow: Loop 5 times to accept data and simultaneously compare the rating to find the index of the highest-rated app. 3. Completion: Print the full details of the application that has the maximum rating among the five entries.

Q2: Python List Operations

Max Marks: 10

Write a Python program to create a list of student's names and perform following operations on it. 1. Append Name in a list. 2. Display list in sorted order. 3. Count total number of students in list. 4. Display last 3 names of a list.

1. List Transformation & Slicing

Manage a collection of names using standard list methods and slicing.

Hint

Use list.append(), list.sort(), len(list), and negative slicing list[-3:].

flowchart TD
init[Create List]
app[Append Name]
sort[Sort List]
count[Get Length]
slice[Get Last 3]

init --> app
app --> sort
sort --> count
count --> slice
View Solution & Output
# [1] Initial List
students = ['Rahul', 'Priya', 'Amit', 'Sia']

# [i] Append Name
students.append('Aryan')
print("List after append:", students)

# [ii] Display sorted
students.sort()
print("Sorted list:", students)

# [iii] Count total
print("Total students:", len(students))

# [iv] Display last 3
print("Last 3 students:", students[-3:])

Step-by-Step Explanation: 1. Initialization: Create a list of names and use append() to add a new student to the collection. 2. Logic Flow: Sort the list alphabetically, calculate its length, and use negative slicing [-3:] to extract the last three items. 3. Completion: Print the results of each operation to verify list manipulation and slicing.

Q3: Viva Preparation

Max Marks: 5

Potential Viva Questions
  1. Q: What is a Structure in C?
  2. A: A user-defined data type that allows grouping variables of different data types under a single name.
  3. Q: How does list[-3:] work in Python?
  4. A: It is called negative slicing; it starts from the 3rd element from the end and goes until the last element.
  5. Q: Can we sort a list containing both numbers and strings?
  6. A: No, Python 3 will raise a TypeError because it cannot compare different types.
  7. Q: What is the size of a structure in C?
  8. A: It is at least the sum of the sizes of its members, but often larger due to memory alignment (padding).
  9. Q: Difference between list.sort() and sorted(list)?
  10. A: list.sort() modifies the original list in place and returns None. sorted() returns a new sorted list leaving the original unchanged.
  11. Q: How do you find the index of a specific name in a Python list?
  12. A: Use the .index() method, e.g., students.index('Amit').

Common Pitfalls

  • String Input in C: scanf("%s", ...) stops at spaces. For names with spaces, use fgets() or gets().
  • Sorting Direction: sort() sorts in ascending order by default. Use reverse=True for descending.

Quick Navigation

Set Link
Set A Solutions
Set B Solutions
Set C Current Page
Set D Solutions
Set E Solutions
Set F Solutions

Last Updated: April 2025