Help on pointer File of class in BT

#include<fstream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
class Student
{
private: int ID,Hour; char Name[20],Sex[7]; float Rate,Salary,Amount;
public: Student(); Student(int ID,int Hour,char *st,char *s,float Rate,float Salary);
friend istream&operator>>(istream&,Student&);
friend ostream&operator<<(ostream&,Student&);
};
struct TreeType
{
Student Item;
TreeType *Left;
TreeType *Right;
};

TreeType *creatBT(int n)
{
TreeType *P;
Student NewItem;
int nl,nr;
if(n==0) return NULL;
else
{
cout<<"Input a Student information:"<<endl;
cin>>NewItem;
P=(TreeType*)malloc(sizeof(TreeType));
P->Item=NewItem;
P->Left=NULL;
P->Right=NULL;
nl=n/2;
nr=n-nl-1;
P->Left=creatBT(nl);
P->Right=creatBT(nr);
return P;
}
}
void main()
{
Student *Stu={(0,"yo","F",0,0)};
fstream fout,fin;
TreeType *P;
int n; char ch;
while(1)
{
ch=getch();
switch(ch)
{
case '1': {cout<<"Create list:"<<endl;
cout<<"Input Student's number:"; cin>>n;
P=creatBT(n);
fout.open("Pointer.bin",ios::binary|ios::out);
if(fout.fail())
{
cout<<"Error open file"; return;
}
fout.write((char*)&P,(sizeof(TreeType)));
fout.close();
break;}
case '2': {cout<<"Display all Item from file";
fin.open("Pointer.bin",ios::binary|ios::in);
if(fin.fail())
{
cout<<"Error open file"; return;
}
fin.seekp(0,ios::end);
fin.read((char*)&P,(sizeof(TreeType)));
cout<<P;
fin.close();
break;}
/*case '3': */
}
}
}
Student::Student()
{
ID=0;Hour=0;strcpy(Name,"yo");strcpy(Sex,"F");Rate=0;Salary=0;
}
Student::Student(int ID,int Hour,char *st,char *s,float Rate,float Salary)
{
this->ID=ID; this->Hour=Hour; strcpy(Name,st); strcpy(Sex,s); this->Rate=Rate;
this->Salary=Salary;
}
istream&operator>>(istream &in,Student &st)
{
cout<<"Input ID:"; in>>st.ID;
cout<<"Input Name:"; in.seekg(0,ios::end); in.clear(); in.get(st.Name,20);
cout<<"Input Sex:"; in.seekg(0,ios::end); in.clear(); in.get(st.Sex,7);
cout<<"Input Hour:"; in>>st.Hour;
cout<<"Input Rate:"; in>>st.Rate;
st.Amount=st.Salary+st.Hour*st.Rate;
return in;
}
ostream&operator<<(ostream &out,Student &st)
{
out<<"ID:"<<st.ID<<"\tName:"<<st.Name<<"\tSex:"<<st.Sex<<"\tHour:"<<st.Hour<<"\tRate:"<<st.Rate<<"\tAmount:"<<st.Amount<<endl;
return out;
}
I just... I can't even...
Topic archived. No new replies allowed.