C program to create a file student.dat, C/C++ Programming

Program is to create a file student.dat:

Program is to create a file student.dat which contains all name, roll_no,marks(5 sub) and percentage

  class student

   {

   private:

    char name[20];

    int roll;

    int marks[5];

    int total;

    float perc;

   public:

    student()

     {

     total=0;

     }

     void input();

     void output();

     };

 

 void student::input()

  {

  clrscr();

  cout<<" enter your name ";

  gets(name);

  cout<<" enter your roll no. ";

  cin>>roll;

  cout<<" enter the marks of five subjects "<<"\n";

  for (int i=0;i<5;i++)

    {

    cout<<" enter marks";

    cin>>marks[i];

    total=total + marks[i];

    }

   }

 void student::output()

   {

   clrscr();

   perc=total/5;

    if (perc>=60)

      {

     cout<<" the name is "<

     cout<<" the total marks obtained out of (500) "<

     cout<<" the percentage "<

     }

    else

     cout<<" the percten tage is less then 60 ";

   }

 

  void main()

    {

    clrscr();

   student info;

   fstream file;

   file.open("student.dat",ios::in|ios::out);

   int n;

   cout<<" enter the number for which u want to enter data";

   cin>>n;

   for(int i=1;i<=n;i++)

     {

     info.input();

     file.write((char *)& info,sizeof(info));

     }

     file.close();

     file.open("student.dat",ios::in);

     while(file)

      {

    file.write((char *)& info,sizeof(info));

    info.output();

    }

   file.close();

   }

Posted Date: 10/19/2012 5:39:41 AM | Location : United States







Related Discussions:- C program to create a file student.dat, Assignment Help, Ask Question on C program to create a file student.dat, Get Answer, Expert's Help, C program to create a file student.dat Discussions

Write discussion on C program to create a file student.dat
Your posts are moderated
Related Questions
Friend function in c++: class miles; class km  {    float value;    public :   // void input();     km convert(km  ,int a ) ;    void output()    {

Object Oriented Programming Paradigm: For OOP, Paradigm is a standard set.  The OOP will help to develop software in modules, which will be integrated later as a full packag

Aim: To implement a program for bank account using static data type. Code: class bank {             static int acc_no;             int acc;             float b

Of course it is C[i] = A[i] + B[i].It was a typing mistake,never mind. You just understand the concept. 27-1 b. for grain-size=1 n=A.length grain-size=1 r=n for

pseudocode for gregorian calendar

how c program starts executing?

C Program for FUNCTION OF DIVIDER int gcd(int , int); void main() {           int m=0,n=0,k=0;           clrscr();           printf("ENTER THE FIRST DIGIT: ");

Ask queCreate an object oriented application with C# that computes the area of a rectangle, and the area and the volume of a cuboid. Based on the inheritance concept, create a bas

(a) Write a procedure (count-even n) that counts the number of even digits in the decimal representation of the number n. For example, (count-even 234) should return 2. (b) Writ

What are  P r im a r y D a t a T y p es? Integer can be defined according to the size of the data and it can be modified further by using keyword unsigned and si