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

Assignment Help:

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();

   }


Related Discussions:- C program to create a file student.dat

Give example of the for loop, The for Loop For loop is the controlled f...

The for Loop For loop is the controlled form of loop. The general format of this : for( initialize ; test ; update)                  {                     statements;

Coding, A palindrome is a string that reads the same from both the ends. Gi...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Friend function, Ask question #Minimum 100 what is friend function is used ...

Ask question #Minimum 100 what is friend function is used in c++

File Input and Output, Given a bool variable isReadable write some statem...

Given a bool variable isReadable write some statements that assign true to isReadable if the file "topsecret" exists and can be read by the program and assigns false to isR

Explain call by reference, Call by Reference Passing variables(paramete...

Call by Reference Passing variables(parameters) to a function in C can be done in two ways - pass by value, also called as call by value and pass by address or also known as ca

Area, write a program to find area of curve y=f(x) between x and x=b,integr...

write a program to find area of curve y=f(x) between x and x=b,integrate between the limits a and b using c     #include float start_point, /* GL

Explain zero based addressing, Explain zero based addressing. - Array s...

Explain zero based addressing. - Array subscripts always start at zero. - These subscript values are used to identify elements in the array. - As subscripts start at 0, a

Plugging the memory leak, Problem #1: plugging the memory leak. When you em...

Problem #1: plugging the memory leak. When you employ the "normal" new operator, for example Foo* p = new Foo(), the compiler generates some special code to manage the case while t

Explain the function of five elements that are on a, explain the function o...

explain the function of five elements that are found on a motherboard#

C program for bank account, Aim: To implement a program for bank account u...

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

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd