save data into "dat" file but....

i write data in binary mode " ios::binary "
but data comes in this form:

ìý" 2“yvÜŸ þÿÿÿÛsv³Ãßw €@èw · èw   èw ¬þ"


i dont understand
What are we supposed to do?
Explain your question, show your code.
i stuck here


void display_sp(int n)
{
node rec;
student st;
ifstream inFile;
inFile.open("student.txt",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
getch();
return;
}

int flag=0;
cur=start;
while(inFile.read((char *) &rec, sizeof(rec)))
{

if( cur->roll_no==n)

{



cout<<"\nRoll number of student : "<<cur->roll_no;
cout<<"\nStudentname of student : "<<cur->name;
cout<<"\nMarks in Physics : "<<cur->p_m;
cout<<"\nMarks in Chemistry : "<<cur->c_m;
cout<<"\nMarks in Maths : "<<cur->m_m;
cout<<"\nMarks in English : "<<cur->e_m;
cout<<"\nMarks in Computer Science :"<<cur->cs_m;
cout<<"\nPercentage of student is :"<<cur->per;
cout<<"\nGrade of student is :"<<cur->grade;


flag=1;

}
cur=cur->nxt;
}
inFile.close();
if(flag==0)
cout<<"\n\nrecord not exist";
getch();
}
my full code.. plz sort it makes me so angry


#include<fstream>
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<conio.h>

using namespace std;

struct node
{
node *pre;
int roll_no;
char name[40],grade,ch;
int p_m ,c_m,m_m,cs_m,e_m;
int num;
float per;

node *nxt;
};
node *start,*cur,*temp;

class student
{
public:

student()
{
start=NULL;
}

void calculate();
void getdata();
void showdata();
void show_tabular();
int retrollnumber();

};


void student::calculate()
{
node *percent;
percent->per=(percent->p_m + percent->c_m + percent->m_m + percent->e_m + percent->cs_m)/5;
if(percent->per>=60)
percent->grade='A';
else if(percent->per>=50)
percent->grade='B';
else if(percent->per>=33)
percent->grade='C';
else
percent->grade='F';
}



void student::showdata()
{

cur=start;
while( cur!=NULL)
{

cout<<"\nRoll number of student : "<<cur->roll_no;
cout<<"\nStudentname of student : "<<cur->name;
cout<<"\nMarks in Physics : "<<cur->p_m;
cout<<"\nMarks in Chemistry : "<<cur->c_m;
cout<<"\nMarks in Maths : "<<cur->m_m;
cout<<"\nMarks in English : "<<cur->e_m;
cout<<"\nMarks in Computer Science :"<<cur->cs_m;
cout<<"\nPercentage of student is :"<<cur->per;
cout<<"\nGrade of student is :"<<cur->grade;
cur=cur->nxt;
}
}

void student::show_tabular()
{

for(cur=start; cur!=NULL; cur=cur->nxt)

cout<<cur->roll_no<<setw(6)<<" "<<cur->name<<setw(10)<<cur->p_m<<setw(4)<<cur->c_m<<setw(4)<<cur->m_m<<setw(4)
<<cur->e_m<<setw(4)<<cur->cs_m<<setw(6)<<cur->per<<setw(6)<<" "<<cur->grade<<endl;
}

int student::retrollnumber()
{

while(cur->nxt!=NULL)
{
cur=cur->nxt;
}


return cur->roll_no;
}

void write_student();
void display_all();
void display_sp(int);
void modify_student(int);
void delete_student(int);
void class_result();
void result();
void intro();
void entry_menu();



int main()
{
char ch;
cout.setf(ios::fixed|ios::showpoint);
cout<<setprecision(2);

intro();
do
{
cout<<"\n\n\n\tMAIN MENU";
cout<<"\n\n\t01. RESULT MENU";
cout<<"\n\n\t02. ENTRY/EDIT MENU";
cout<<"\n\n\t03. EXIT";
cout<<"\n\n\tPlease Select Your Option (1-3) ";
cin>>ch;

switch(ch)
{
case '1': result();
break;
case '2': entry_menu();
break;
case '3':
break;
default :cout<<"\a";
}
}while(ch!='3');
return 0;
}

void write_student()
{
node rec;
ofstream outFile;

outFile.open("student.txt",ios::binary);

if(start==NULL)
{
start=new node;
start->pre=NULL;


cout<<"\nroll number of student ";
cin>>start->roll_no;
cout<<"\n\nStudentname of student ";
cin>>start->name;
cout<<"\nmarks in physics out of 100 : ";
cin>>start->p_m;
cout<<"\nmarks in chemistry out of 100 : ";
cin>>start->c_m;
cout<<"\nmarks in maths out of 100 : ";
cin>>start->m_m;
cout<<"\nmarks in english out of 100 : ";
cin>>start->e_m;
cout<<"\nmarks in computer science out of 100 : ";
cin>>start->cs_m;

start->nxt=NULL;
}else
{
node *p;
cur=start;
while(cur->nxt!=NULL)

{ cur=cur->nxt; }
p=temp;
temp=new node;
temp->pre=p;

cout<<"\nroll number of student ";
cin>>start->roll_no;
cout<<"\n\nStudentname of student ";
cin>>start->name;
cout<<"\nmarks in physics out of 100 : ";
cin>>start->p_m;
cout<<"\nmarks in chemistry out of 100 : ";
cin>>start->c_m;
cout<<"\nmarks in maths out of 100 : ";
cin>>start->m_m;
cout<<"\nmarks in english out of 100 : ";
cin>>start->e_m;
cout<<"\nmarks in computer science out of 100 : ";
cin>>start->cs_m;
temp->nxt=NULL;
cur->nxt=temp;
}
outFile.write((char *) &rec, sizeof(rec));
outFile.close();
cout<<"\n\nStudent record Has Been Created ";
getch();
}

void display_all()
{
node rec;
ifstream inFile;
inFile.open("student.txt",ios::binary);
if(!inFile)
{
cout<<"File could not be open ! Press any Key...";
getch();
return;
}
cout<<"\n\n\n\t\tDISPLAY ALL RECORD !\n\n";
while(inFile.read((char *) &rec, sizeof(rec)))
{
cur=start;
while(cur->nxt!=NULL)
{


cout<<"\nRoll number of student : "<<cur->roll_no;
cout<<"\nStudentname of student : "<<cur->name;
cout<<"\nMarks in Physics : "<<cur->p_m;
cout<<"\nMarks in Chemistry : "<<cur->c_m;
cout<<"\nMarks in Maths : "<<cur->m_m;
cout<<"\nMarks in English : "<<cur->e_m;
cout<<"\nMarks in Computer Science :"<<cur->cs_m;
cout<<"\nPercentage of student is :"<<cur->per;
cout<<"\nGrade of student is :"<<cur->grade;


cur=cur->nxt;
}
cout<<"\n\n======\n";
}
inFile.close();
getch();
}

void display_sp(int n)
{
node rec;
student st;
ifstream inFile;
inFile.open("student.txt",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
getch();
return;
}

int flag=0;
cur=start;
while(inFile.read((char *) &rec, sizeof(rec)))
{

if( cur->roll_no==n)

{



cout<<"\nRoll number of student : "<<cur->roll_no;
cout<<"\nStudentname of student : "<<cur->name;
cout<<"\nMarks in Physics : "<<cur->p_m;
cout<<"\nMarks in Chemistry : "<<cur->c_m;
cout<<"\nMarks in Maths : "<<cur->m_m;
cout<<"\nMarks in English : "<<cur->e_m;
cout<<"\nMarks in Computer Science :"<<cur->cs_m;
cout<<"\nPercentage of student is :"<<cur->per;
cout<<"\nGrade of student is :"<<cur->grade;

flag=1;
}
cur=cur->nxt; }
inFile.close();
if(flag==0)
cout<<"\n\nrecord not exist";
getch();
}


void class_result()
{
node rec;
student st;
ifstream inFile;
inFile.open("student.txt",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
getch();
return;
}
cout<<"\n\n\t\tALL STUDENTS RESULT \n\n";
cout<<"==========================================================\n";
cout<<"R.No Studentname P C M E CS %age Grade"<<endl;
cout<<"==========================================================\n";


while(inFile.read((char *) &rec, sizeof(rec)))
{

for(cur=start; cur!=NULL; cur=cur->nxt)
{

cout<<cur->roll_no<<setw(6)<<" "<<cur->name<<setw(10)<<cur->p_m<<setw(4)<<cur->c_m<<setw(4)<<cur->m_m<<setw(4)
<<cur->e_m<<setw(4)<<cur->cs_m<<setw(6)<<cur->per<<setw(6)<<" "<<cur->grade<<endl;
}

}
getch();
inFile.close();
}


void result()
{

char ch;
int rno;
cout<<"\n\n\n\tRESULT MENU";
cout<<"\n\n\n\t1. Class Result";
cout<<"\n\n\t2. Student Report Card";
cout<<"\n\n\t3. Back to Main Menu";
cout<<"\n\n\n\tEnter Choice (1/2/3)? ";
cin>>ch;

switch(ch)
{
case '1' :class_result(); break;
case '2' :cout<<"\n\n\tEnter Roll Number Of Student : ";
cin>>rno;
display_sp(rno); break;
case '3' :break;
default :cout<<"\a";
}
}
void intro()
{

cout<<"\n\n\t\tSTUDENT REPORT CARD SYSTEM ";
getch();
}
void entry_menu()
{
int num;
char ch;
cout<<"\n\n\n\tENTRY MENU";
cout<<"\n\n\t1.ADD STUDENT RECORD";
cout<<"\n\n\t2.DISPLAY ALL RECORDS";
cout<<"\n\n\t3.SEARCH STUDENT RECORD ";
cout<<"\n\n\t4.EDIT STUDENT RECORD";
cout<<"\n\n\t5.DELETE STUDENT RECORD";
cout<<"\n\n\t6.BACK TO MAIN MENU";
cout<<"\n\n\tPlease Enter Your Choice (1-6) ";
cin>>ch;

switch(ch)
{
case '1': write_student(); break;
case '2': display_all(); break;
case '3': cout<<"\n\n\tPlease roll number "; cin>>num;
display_sp(num); break;
/* case '4': cout<<"\n\n\tPlease roll number "; cin>>chose->num;
modify_student(chose->num);break;
case '5': cout<<"\n\n\tPlease roll number "; cin>>num;
delete_student(num);break;*/
case '6': break;
default: cout<<"\a"; entry_menu();
}
}

Topic archived. No new replies allowed.