Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

write a program to enter name, roll-number and marks of 10 students and store them in the file.

0 votes
asked Feb 16 by anonymous

1 Answer

0 votes
answered Feb 28 by Mohammad Danish
#include<iostream>
#include<string>
#include<fstream>
struct Student
{
    long int _StudentRoll;
    std::string _Name;
    double marks;
    
    void InsertDetails(int i)
    {
        std::cout << "\n" << i << "th Employee Details: \n";
        std::cout << "\nEnter the Student Roll No. : ";
        std::cin >> _StudentRoll;
        std::cin.ignore();
        std::cout << "\nEnter the Student Name: ";
        getline(std::cin, _Name);
        std::cout << "\nEnter the Marks: ";
        std::cin >> marks;
        
    }
    void DisplayDetails()
    {
        std::cout << "\nStudent ID-: " << _StudentRoll;
        std::cout << "\nStudent Name-: " << _Name;
        std::cout << "\nStudent Address-: " << marks;
    }
};
int main()
{
    int _numberOfStudent;
    std::cout << "\nEnter the Number of Students: ";
    std::cin >> _numberOfStudent;
    Student* _StudentObject = new Student[_numberOfStudent];
    for (int i = 0; i < _numberOfStudent; i++)
    {
        _StudentObject[i].InsertDetails(i);
    }
    std::cout << "\nNOW DISPLAYING THE DETAILS OF THE Students\n";
    ofstream f1("Student.txt", ios::app);
    for (int i = 0; i < _numberOfStudent; i++)
    {
        f1 <<"Student Roll: "<< _StudentObject[i]._StudentRoll << std::endl;
        f1 <<"Student Name: "<< _StudentObject[i]._Name << std::endl;
        f1 <<"Student Marks: "<< _StudentObject[i].marks << std::endl;
        _StudentObject[i].DisplayDetails();
    }

   
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...