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
|
//#include <stdio.h>
#include "class.h"
//#include "equipment.h"
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
const int nameLength = 10; //Dictates the length of the name.
const int rfidLength = 10; //Dictates how long rfid char* is, can easily be changed to accomadate more info.
// Allows for sending of data using the extraction operator
ostream& operator<<(ostream& out, Card& other){
char* rfid;
rfid = new char[20];
char* name;
name = new char[20];
double balance = 0;
strcpy(rfid, other.getRFID());
for(int i =0; i < strlen(rfid); i ++)
{
out << rfid[i];
}
balance = other.checkBal();
out << " " << balance << " ";
strcpy(name, other.getName());
for(int i = 0; i <strlen(name); i ++)
{
out << name[i];
}
out << endl;
delete[] rfid;
delete[] name;
return out;
}
int rfidSearch( Card table[], char* goal, int size)
{
int count = 0;
for(int i = 0; i < size; i ++)
{
for(int j = 0; j <= strlen(goal); j ++)
{
if(table[i].RFID[j] == goal[j])
{
if(j == strlen(goal))
return count;
}
else if(table[i].RFID[j] != goal[j])
{
j = strlen(goal) + 1;
}
}
count++;
}
count = -1;
return count;
}
int main()
{
bool done = false;
char* input; //Receives the card number
char* temp1;
char* temp2; // Holds the information before it is stored in card database.
double holder;
char c; // Gets 1 letter at a time from account database.
ifstream inputFile;
int length = 0;
int size = 0;
int index = 0;
Card* data;
inputFile.open("accounts.txt", ifstream :: in);
inputFile.seekg(0L, ios :: end);
length = inputFile.tellg();
inputFile.seekg(0L, ios :: beg);
size = length/(sizeof(char)*rfidLength+sizeof(char)*nameLength+sizeof(double));
data = new Card[size];
temp1 = new char[rfidLength];
temp2 = new char[nameLength];
for(int i = 0; i < size; i ++)
{
temp1[0] = '\0';
temp2[0] = '\0';
inputFile.get(temp1 , 100, ' ');
data[i].setRFID(temp1);
inputFile >> holder;
data[i].setBal(holder);
inputFile.get(temp2, 100);
data[i].setName(temp2);
}
while(!done)
{
input = new char[rfidLength];
if(cin >> input)
index = rfidSearch(data, input, size);
done = true;
}
delete[] input;
return 0;
}
|