Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.8 kB
4
Indexable
Never
#include <stdio.h>
#include <string.h>
#include <conio.h>

float gradesStud[50];
int idStud[50];
int totalStudents = 0;
char nameStud[50][50];

void addStudent()
{
    fflush(stdin);
    printf("Enter New Name:\n");
    fgets(nameStud[totalStudents], 50, stdin);

    printf("Enter New ID: ");
    scanf("%d", &idStud[totalStudents]);

    printf("Enter Grade:");
    scanf("%f", &gradesStud[totalStudents]);

    totalStudents++;
}

void studentList()
{

    printf("ID\tGrade\tName\n");
    for (int i = 0; i < totalStudents; i++)
    {
        printf("%d\t%0.2f\t%s\n", idStud[i], gradesStud[i], nameStud[i]);
    }

    getch();
}

void findMaxGrade()
{
    float maxGrade;

    maxGrade = gradesStud[0];

    int location;

    for (int i = 1; i < totalStudents; i++)
    {
        if (gradesStud[i] > maxGrade)
        {
            maxGrade = gradesStud[i];
            location = i;
        }
    }
    printf("Max grade: %0.2f, Student:\n", maxGrade);
    printf("ID\tName\n");
    printf("%d\t%s\n", idStud[location], nameStud[location]);
    getch();
}

void findMinGrade()
{
    float min;

    min = gradesStud[0];

    int location;

    for (int i = 1; i < totalStudents; i++)
    {
        if (gradesStud[i] < min)
        {
            min = gradesStud[i];
            location = i;
        }
    }
    printf("Min grade: %0.2f, Student:\n", min);
    printf("ID\tName\n");
    printf("%d\t%s\n", idStud[location], nameStud[location]);
    getch();
}

void searchStudent()
{
    int findID;
    int result = 0;
    printf("Enter ID: ");
    scanf("%d", &findID);
    for (int i = 0; i < totalStudents; i++)
    {
        if (findID == idStud[i])
        {
            result = 1;
            printf("%0.2f\n", gradesStud[i]);
            printf("%d", idStud[i]);
        }
    }
    if (result == 0)
    {
        printf("Invalid ID");
    }
    getch();
}

int main()
{
    char username[15];
    char password[12];

    printf("Enter your username[Default : Kydz]:\n");
    scanf("%s", &username);

    printf("Enter your password [Default]: 123 :\n");
    scanf("%s", &password);

    if (strcmp(username, "kydz") == 0)
    {
        if (strcmp(password, "123") == 0)
        {

            printf("\nWelcome.Login Success!");
            int choice; 
            while (1)
            {
                printf("\n===== STUDENT MANAGEMENT SYSTEM =====\n");
                printf("1. Add Student\n");
                printf("2. Show Student List\n");
                printf("3. Find Max Grade\n");
                printf("4. Find Min Grade\n");
                printf("5. Search Student\n");
                printf("0. EXIT PROGRAM\n");
                printf("ENTER YOUR CHOICE: \n");
                scanf("%d", &choice);

                switch (choice)
                {
                case 0:
                    exit(0);
                    break;
                case 1:
                    addStudent();
                    break;
                case 2:
                    studentList();
                    break;
                case 3:
                    findMaxGrade();
                    break;
                case 4:
                    findMinGrade();
                    break;
                case 5:
                    searchStudent();
                    break;
                default:
                    printf("Invalid Choice\n\n");
                }
            }
        }
        else
        {
            printf("\nwrong password");
        }
    }
    else
    {
        printf("\nUser doesn't exist");
    }

    return 0;
}