#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
struct UKStudent
{
char name [30];
int noTest;
float mark [10];
int final;
char grade [30];
};
struct OverseasStudent
{
char country [30];
char name [30];
int noTest;
float mark [10];
int final;
char grade [30];
};
union EveryStudent
{
UKStudent uks;
OverseasStudent oss;
};
struct Student
{
char type; //Not sure what is this?
EveryStudent st;
};
infile.txt
----------------------------------------------------------------------
UK Michael_Owen
O Australian David_Cooper
O Japanese Arikato
----------------------------------------------------------------------
My 1st task is to read the infile.txt. My 2nd task is to convert the content in infile.txt to a binary file format, outfile.dat
Qns: 1st task: Can advise whether my code is ok?
My attempt code:
void createfile (fstream& afile, char filename [])
{
afile.open (filename, ios::out);
char type; //From struct student, not too sure
for (int i=1; i <=10; i++)
{
type = rand () % 3; //Need to use rand?
switch (type)
{
case 'UK': afile << type << "\t" << (rand() % 30 + 1) << endl;
break;
case 'O': afile << type <<"\t" << (rand() % 30 + 1)
<<"\t" << (rand() % 30 + 1) << endl;
break;
}
}
afile.close( );
}