Student Database Manager

Student Database Manager

Easy C Structures 35 views
Explanation Complexity

Problem Statement

Make the structure of the student (roll_no, name, marks). Create an array of 5 students. Create Functions: addStudent(), displayAll(), findTopScorer(), calculateClassAverage(). Poor mini-project.

Input Format

Student details:

• roll_no

• name

• marks
Total students = 5

Output Format

• All student details

• Top scorer details

• Class average marks

Example

1 Rahul 80
2 Anu   70
3 Mohit 90
4 Neha  60
5 Ravi  85
All Students:
1 Rahul 80
2 Anu 70
3 Mohit 90
4 Neha 60
5 Ravi 85

Top Scorer:
Mohit 90

Class Average:
77

Constraints

• Total students fixed = 5

• Marks between 0 and 100

Concept Explanation

Student data is stored in a structure array.
Different functions are used to keep work separate and clear.

Step-by-Step Explanation

1.Create Student structure (roll_no, name, marks).

2.Store 5 students in an array.

3.displayAll() → print all students.

4.findTopScorer() → find max marks.

5.calculateClassAverage() → sum marks ÷ 5.

Concept Explanation

Student data is stored in a structure array.
Different functions are used to keep work separate and clear.

Step-by-Step Explanation

1.Create Student structure (roll_no, name, marks).

2.Store 5 students in an array.

3.displayAll() → print all students.

4.findTopScorer() → find max marks.

5.calculateClassAverage() → sum marks ÷ 5.

Input / Output Format

Input Format
Student details:

• roll_no

• name

• marks
Total students = 5
Output Format
• All student details

• Top scorer details

• Class average marks
Constraints
• Total students fixed = 5

• Marks between 0 and 100

Examples

Input:
1 Rahul 80 2 Anu 70 3 Mohit 90 4 Neha 60 5 Ravi 85
Output:
All Students: 1 Rahul 80 2 Anu 70 3 Mohit 90 4 Neha 60 5 Ravi 85 Top Scorer: Mohit 90 Class Average: 77

Example Solution (Public)

C
#include <stdio.h>

#define SIZE 5

// Structure definition
struct student {
    int roll_no;
    char name[50];
    float marks;
};

// Function to add student details
void addStudent(struct student s[]) {
    int i;
    for (i = 0; i < SIZE; i++) {
        printf("nEnter details of student %dn", i + 1);

        printf("Roll Number: ");
        scanf("%d", &s[i].roll_no);

        printf("Name: ");
        scanf("%s", s[i].name);

        printf("Marks: ");
        scanf("%f", &s[i].marks);
    }
}

// Function to display all students
void displayAll(struct student s[]) {
    int i;
    printf("n--- Student Details ---n");
    for (i = 0; i < SIZE; i++) {
        printf("nRoll No: %d", s[i].roll_no);
        printf("nName: %s", s[i].name);
        printf("nMarks: %.2fn", s[i].marks);
    }
}

// Function to find top scorer
void findTopScorer(struct student s[]) {
    int i, topIndex = 0;

    for (i = 1; i < SIZE; i++) {
        if (s[i].marks > s[topIndex].marks) {
            topIndex = i;
        }
    }

    printf("n--- Top Scorer ---n");
    printf("Roll No: %d", s[topIndex].roll_no);
    printf("nName: %s", s[topIndex].name);
    printf("nMarks: %.2fn", s[topIndex].marks);
}

// Function to calculate class average
void calculateClassAverage(struct student s[]) {
    int i;
    float sum = 0, average;

    for (i = 0; i < SIZE; i++) {
        sum += s[i].marks;
    }

    average = sum / SIZE;
    printf("nClass Average Marks: %.2fn", average);
}

// Main function
int main() {
    struct student students[SIZE];

    addStudent(students);
    displayAll(students);
    findTopScorer(students);
    calculateClassAverage(students);

    return 0;
}

Official Solution Code

#include <stdio.h>

#define SIZE 5

// Structure definition
struct student {
    int roll_no;
    char name[50];
    float marks;
};

// Function to add student details
void addStudent(struct student s[]) {
    int i;
    for (i = 0; i < SIZE; i++) {
        printf("nEnter details of student %dn", i + 1);

        printf("Roll Number: ");
        scanf("%d", &s[i].roll_no);

        printf("Name: ");
        scanf("%s", s[i].name);

        printf("Marks: ");
        scanf("%f", &s[i].marks);
    }
}

// Function to display all students
void displayAll(struct student s[]) {
    int i;
    printf("n--- Student Details ---n");
    for (i = 0; i < SIZE; i++) {
        printf("nRoll No: %d", s[i].roll_no);
        printf("nName: %s", s[i].name);
        printf("nMarks: %.2fn", s[i].marks);
    }
}

// Function to find top scorer
void findTopScorer(struct student s[]) {
    int i, topIndex = 0;

    for (i = 1; i < SIZE; i++) {
        if (s[i].marks > s[topIndex].marks) {
            topIndex = i;
        }
    }

    printf("n--- Top Scorer ---n");
    printf("Roll No: %d", s[topIndex].roll_no);
    printf("nName: %s", s[topIndex].name);
    printf("nMarks: %.2fn", s[topIndex].marks);
}

// Function to calculate class average
void calculateClassAverage(struct student s[]) {
    int i;
    float sum = 0, average;

    for (i = 0; i < SIZE; i++) {
        sum += s[i].marks;
    }

    average = sum / SIZE;
    printf("nClass Average Marks: %.2fn", average);
}

// Main function
int main() {
    struct student students[SIZE];

    addStudent(students);
    displayAll(students);
    findTopScorer(students);
    calculateClassAverage(students);

    return 0;
}
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.