|
|
# include <iostream.h>
# include <fstream>
//array sizes
const int NAME_SIZE = 51 , ADDR_SIZE = 51 , PHONE_SIZE = 14 ,MAIL_SIZE=100 , FAC_SIZE=60;
//Declare a structure for the record
struct Info
{
char name[NAME_SIZE] ;
int age ;
char address1[ADDR_SIZE];
char address2[ADDR_SIZE];
char phone[PHONE_SIZE];
char email[MAIL_SIZE];
int ic ;
char faculty[FAC_SIZE];
};
int main ()
{
Info person ;
char again ;
//open a file for binary output .
fstream people("people.dat" , ios: ut|ios::binary) ;
do
{
// Get data about a person .
cout <<"Enter the following data about a person " <<endl;
cout <<"-----------------------------------------\n" ;
cout <<"Name : " ;
cin.getline(person.name,NAME_SIZE);
cout<<"Age : ";
cin>> person.age ;
cin.ignore(); //skip over the remaining newline .
cout << "Address line 1 : " ;
cin.getline(person.address1,ADDR_SIZE);
cout << "Address line 2 : " ;
cin.getline (person.address2,ADDR_SIZE);
cout<< " hone : " ;
cin.getline(person.phone, PHONE_SIZE);
cout<<"email : " ;
cin.getline(person.email,MAIL_SIZE);
cout <<"IC number : " ;
cin >>person.ic ;
cout >>"faculty : " ;
cin.getline(person.faculty,FAC_SIZE) ;
// Write the contents of the person structure to the file.
people.write(reinterpret_cast<char *>(&person),sizeof(person));
// Find out whether the user wants to write another record.
cout << "Do you want to enter another record? (Y/N)" ;
cin>> again ;
cin.ignore(); //Skip over the remaining newline.
}
while (again== 'Y' || again == 'y') ;
//close the file .
people.close() ;
return 0 ;
}
我不知哪里有错误。请帮忙我看以下。。
How can i do when the person enter the code beside Y ?
i means if they enter others word beside y and n , i wan my cout << "You have enter invalid code , pls type it again .."
For the next part , i dunno to verify the person in my database .
Like , When i enter the people name not in my database , how can i write the code ya ?
Thanks for helping me .. |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|