Skip to main content

Student data Program in C++



 #include <bits/stdc++.h>
using namespace std;
const int m = 50;
class student_data
{

    string name[m];
    int roll[m];
    int marks[m];
    int count = 0;

public:
    void nstudent(void) { count = 0; }
    void getdetails()
    {

        cout << "---- Enter the Details of Student ----" << endl;
        cout << "Enter the name of the student: ";
        cin >> name[count];
        cout << "Enter the Roll No of the student: ";
        cin >> roll[count];
        cout << "Enter the Total marks of the student: ";
        cin >> marks[count];
        count++;
    }
   
    void printdetails(){
      for (int i = 0; i < count; i++)
      {
           cout<<"Student Name: "<<name[i]<<endl;
        cout<<"Student Roll No: "<<roll[i]<<endl;
        cout<<"Student Marks: "<<marks[i]<<endl;
        ofstream s("student.txt",ios::app);
        s<<"Student Name is: "<<name[i]<<endl;
        s<<"Student Roll No: "<<roll[i]<<endl;
        s<<"Total Marks of Student: "<<marks[i]<<endl<<endl;
           
      }
     
     
   
       
    }
    void displayAlldetails(){

    ifstream in;
    string s;
    in.open("student.txt");
    while (in.eof()==0){
        getline(in, s);
        cout<<s<<endl;
    }
    }
 
   
};

int main()
{
    student_data a;
    a.nstudent();
    // a.printdetails();
    int x;
    do{
        cout<<"---Welcome to Student Data---"<<endl;
        cout<<"1. Add student data"<<endl;
        cout<<"2. display Student data"<<endl;
        cout<<"3. display All Student data"<<endl;
       
        cout<<"\nWhat U want to do: ";
        cin>>x;
        switch (x)
        {
        case 1:
            a.getdetails();
            break;
        case 2:
            a.printdetails();
            break;
        case 3:
            a.displayAlldetails();
            break;
       
        default:
            cout<<"Your input is wrong! Try Again!";
            break;
         }
    } while (x != 4);
    return 0;
}


Comments