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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
Header:
#ifndef RECORDFILE_H
#define RECORDFILE_H
#include <string>
using namespace std;
//****************************************************************************************************
class Records
{
private:
string studentName;
double *quiz;
double *assignment;
int weeks;
public:
void load(ifstream& inf);
void store(ofstream& of);
Records ();
void setData ( string, int, double, double);
~Records ();
};
#endif
Main:
#include "RecordFile.h"
#include <string>
#include <iostream>
//****************************************************************************************************
Records::Records ()
{
studentName = " ";
weeks = 0;
quiz = 0;
assignment = 0;
}
//****************************************************************************************************
void Records::setData( string name, int size, double q[], double a[])
{
studentName = name;
weeks = size;
quiz = new q[];
assignment = new a[];
}
//****************************************************************************************************
void Records::store(ofstream& of)
{
of.write(&studentName, sizeof(studentName));
of.write(&weeks, sizeof(weeks));
of.write(&quiz, sizeof(quiz));
of.write(&assignment, sizeof(assignment));
}
//****************************************************************************************************
void Records::load(ifstream& inf)
{
inf.read(&studentName, sizeof(studentName));
inf.read(&weeks, sizeof(weeks));
inf.read(&quiz, sizeof(quiz));
inf.read(&assignment, sizeof(assignment));
}
//****************************************************************************************************
Records::~Records()
{
}
//****************************************************************************************************
Driver:
#include "RecordFile.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
//****************************************************************************************************
int main()
{
setData Record("Me", 2, 4, 5);
ofstream myfile;
myfile.open("Records.dat", ios::binary | ios::out);
Record.store(myfile);
myfile.close();
return(0);
}
| |