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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
//ItemType.cxx
#include "ItemType.h"
ItemType::ItemType()
{
id = -100;
major = "zzzzzzz";
exam1 = -100;
exam2 = -100;
exam3 = -100;
gender = 'x';
}
ItemType::ItemType(int inId, string inMajor, int inExam1, int inExam2, int inExam3, char inGender)
{
id = inId;
major = inMajor;
exam1 = inExam1;
exam2 = inExam2;
exam3 = inExam3;
gender = inGender;
}
RelationType ItemType::ComparedTo(ItemType otherItem) const
{
if (id < otherItem.id)
return LESS;
else if (id > otherItem.id)
return GREATER;
else
return EQUAL;
}
void ItemType::GetItemFromFile(ifstream& inFile)
{
inFile >> id >> exam1 >> exam2 >> exam3 >> major >> gender;
}
void ItemType::GetIdFromFile(ifstream& inFile)
{
inFile >> id;
}
void ItemType::WriteItemToFile(ofstream& outFile) const
{
outFile.setf(ios::left);
outFile << setw(13) << id << setw(14) << exam1 << setw(11) << exam2
<< exam3 << major << setw(12) << gender << endl;
}
void ItemType::WriteInvalidItemToFile(ofstream& outFile) const
{
outFile.setf(ios::left);
outFile << setw(13) << id << setw(14) << exam1 << setw(11) << exam2
<< exam3 << major << setw(12) << gender
<< " *** Invalid data" << endl;
}
bool ItemType::ValidItem()
{
return ((id >= MIN_ID) &&
(id <= MAX_ID)&&
(exam1 >= MIN_EXAM)&&
(exam1 <= MAX_EXAM)&&
(exam2 >= MIN_EXAM)&&
(exam2 <= MAX_EXAM)&&
(exam3 >= MIN_EXAM)&&
(exam3 <= MAX_EXAM))&&
((gender == MALE) || (gender == FEMALE));
}
//ItemType.h
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int MAX_ITEMS = 10;
const int MAX_ID = 999;
const int MIN_ID = 111;
const int MAX_EXAM = 100;
const int MIN_EXAM = 0;
const char MALE = 'M';
const char FEMALE = 'F';
enum RelationType {LESS, EQUAL, GREATER};
class ItemType
{
public :
ItemType();
ItemType(int inId, string inMajor, int inExam1, int inExam2, int inExam3, char inGender);
RelationType ComparedTo(ItemType otheritem) const;
void GetItemFromFile(ifstream& inFile);
void GetIdFromFile(ifstream& inFile);
void WriteItemToFile(ofstream& outFile) const;
void WriteInvalidItemToFile(ofstream& outFile) const;
bool ValidItem();
private :
int id;
int exam1;
int exam2;
int exam3;
string major;
char gender;
} ;
//SortedLinkedList.h
#include "ItemType.h"
struct NodeType
{
ItemType info;
NodeType* next;
};
// SortedType.h
class SortedType
{
public:
SortedType();
~SortedType();
SortedType(const SortedType& otherList);
bool IsFull() const;
int LengthIs() const;
void MakeEmpty();
void RetrieveItem(ItemType& item, bool& found);
void InsertItem(ItemType item);
void DeleteItem(ItemType item);
void ResetList();
void GetNextItem(ItemType& item);
void Print(ofstream& outFile);
private:
NodeType* listData;
int length;
NodeType* currentPos;
};
|