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
We can combine more than one variable on the same line i.e.   float number1,number2,number3; etc Sometimes we want to mix the variable types used on the same line, this could

Using the Constructor There are basically three ways of creating and initializing the object. The first way to call the constructor is explicitly as :


redirection in c++

Program to check even and odd numbers: int main() {                 int  your_number;                 cout                 cin >> your_number;

Within software engineering, software is very rarely written by a single software engineer. Usually a team of engineers write a program; therefore a formal structural design approa

#write a program that counts the number of occurances of the string in the n-th padovan string p(n)

Introduction to I/O interfacing, discuss microcontrollers applications in industry. Detailed product design specifications that have sections on both hardware and software inclu

Write a Program that illustrate Command Line Parameters? main(int argc, char *argv[]) { int i; for(i = 0; i printf("arg %d: %s\n", i, argv[i]); return 0; }

Program for calculate average of total marks: #include using namespace std; void print(int marks_arr[],int cnt) { int ind[cnt]; int i=0; int j=0; int k=0;