1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#include <iostream>
#include <fstream>
using namespace std;
const int MAX = 80;
const int MAXNO = 10;
struct Date
{
int day;
char month [MAX];
int year;
};
struct Student
{
char name [MAX];
char nationality [MAX];
Date birthDate;
int no;
char wishMessage [MAXNO] [MAX];
};
void myInfo (fstream&, char[], Student&, Date&);
void printmyInfo(fstream&, char[], Student&, Date&);
int main()
{
srand(time (NULL));
fstream afile;
char filename [MAX];
cout << "Enter your info file name: ";
cin >> filename;
Student a;
Date b;
myInfo(afile,filename,a,b);
printmyInfo(afile,filename,a,b);
}
void myInfo(fstream& afile, char filename [], Student& a, Date& b)
{
afile.open(filename, ios::in);
if (!afile)
{
cout << "file opened for reading failed" << endl;
exit (-1);
}
afile.getline(a.name, MAX);
afile.getline(a.nationality, MAX);
afile >> b.day;
afile >> b.month;
afile >> b.year;
switch(b.month[])
{
case 'May':
strcpy(b.month,"05");
break;
default :
strcpy(b.month,"10");
break;
}
afile >> a.no;
afile.clear ();
afile.ignore (100, '\n');
int MAXNO=1;
while(MAXNO<8)
{
afile.getline(a.wishMessage[MAXNO], MAX);
MAXNO++;
}
afile.close ();
}
void printmyInfo(fstream& afile, char filename [], Student& a, Date& b)
{
cout << "My name is " << a.name << endl;
cout << "My nationality is " << a.nationality << endl;
cout << "MY date of birth is " << b.day << " - " << b.month << " - " << b.year << endl;
cout << "I have " << a.no << " wishes:" << endl;
for(int MAXNO=1;MAXNO<8;MAXNO++)
{
cout << " " << MAXNO << ": " << a.wishMessage[MAXNO] << endl;
}
}
|