Wednesday, July 10, 2024

Student Record System in C++


 


Program Listing

#include <iostream>

#include <string>


class Student {

public:

    // Constructor to initialize the student's information

    Student(std::string name, int rollNumber, double marks) {

        this->name = name;

        this->rollNumber = rollNumber;

        this->marks = marks;

    }


    // Function to display the student's information

    void displayInfo() {

        std::cout << "\n\tStudent Name: " << name << std::endl;

        std::cout << "\tRoll Number: " << rollNumber << std::endl;

        std::cout << "\tMarks: " << marks << std::endl;

    }


private:

    std::string name;

    int rollNumber;

    double marks;

};


int main() {

    std::string name;

    int rollNumber;

    double marks;


    // Input student information

    std::cout <<"\n";

    std::cout << "\tEnter student's name: ";

    std::cin >> name;


    std::cout << "\tEnter roll number: ";

    std::cin >> rollNumber;


    std::cout << "\tEnter marks: ";

    std::cin >> marks;


    // Create a Student object with the provided information

    Student student(name, rollNumber, marks);


    char choice;

    

    do {

        std::cout << "\n\tStudent Record Main Menu\n" << std::endl;

        std::cout << "\t[1] Display student information" << std::endl;

        std::cout << "\t[2] Quit Program" << std::endl;

        std::cout << "\tEnter your choice: ";

        std::cin >> choice;


        if (choice == '1') {

            // Display the student's information

            student.displayInfo();

        } else if (choice != '2') {

            std::cout << "\n\tInvalid choice. Please try again." << std::endl;

        }


    } while (choice != '2');

     std::cout << "\n\tEnd of Program. Thank you for using this program." << std::endl;

    return 0;

}


No comments:

Post a Comment