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 142 143 144 145 146 147 148 149 150 151 152 153
|
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cctype>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef struct
{
char code[5];
char name[30];
int quantity;
}MATERIAL;
typedef struct
{
char code[5];
char name[30];
int quantity;
}TOOL;
typedef struct
{
char name[50];
char id[20];
char ic[20];
char birthdate[20];
char address[50];
char phonenum[20];
}EMPLOYEE;
typedef struct
{
char empName[30];
char empID[20];
char toolName[30];
char toolID[5];
char date[15];
}CO;
void readData(MATERIAL [], TOOL [], EMPLOYEE [], CO [], int , int* , int* , int* , int*);
int main(void)
{
int matNum = 0, toolNum = 0, empNum = 0, coNum = 0;
TOOL tools[50];
MATERIAL mats[50];
EMPLOYEE emps[50];
CO cot[50];
readData(mats, tools, emps, cot, 50, &matNum, &toolNum, &empNum, &coNum);
for (int i = 0; i < coNum; i++)
{
cout << cot[i].empName << "," << cot[i].empID << "," << cot[i].toolName
<< "," << cot[i].toolID << "," << cot[i].date << endl;
}
system("PAUSE");
}
void readData(MATERIAL m[], TOOL t[], EMPLOYEE e[],CO cot[], int size, int* mNum, int* tNum, int* eNum, int *coNum)
{
ifstream inFile;
ifstream in_file;
*mNum = 0, *tNum = 0, *eNum = 0;
inFile.open("materials.txt");
system("CLS");
//Read Materials Data
if (!inFile)
{
cout << "Error opening file !\nCheck the name of the file !\n";
exit(1);
}
else
{
for (int i = 0; !inFile.eof(); i++)
{
inFile.getline(m[i].code, 5, ',');
inFile.getline(m[i].name, 30, ',');
inFile >> m[i].quantity;
inFile.ignore(255, '\n');
(*mNum)++;
}
inFile.close();
}
inFile.open("tools.txt");
system("CLS");
if (!inFile)
{
cout << "Error opening file!\nCheck the name of the file !\n";
exit(1);
}
else
{
for (int i = 0; !inFile.eof(); i++)
{
inFile.getline(t[i].code, 5, ',');
inFile.getline(t[i].name, 30, ',');
inFile >> t[i].quantity;
inFile.ignore(255, '\n');
(*tNum)++;
}
}
inFile.close();
inFile.open("employee.txt");
system("CLS");
if (!inFile)
{
cout << "Error opening file!\nCheck the name of the file !\n";
exit(1);
}
else
{
for (int i = 0; !inFile.eof(); i++)
{
inFile.getline(e[i].name, 30, ',');
inFile.getline(e[i].id, 20, ',');
inFile.getline(e[i].ic, 20, ',');
inFile.getline(e[i].birthdate, 20, ',');
inFile.getline(e[i].address, 30, ',');
inFile.getline(e[i].phonenum, 30);
(*eNum)++;
}
}
inFile.close();
in_file.open("checkout.txt");
system("CLS");
if (!in_file)
{
cout << "Error opening file!\nCheck the name of the file !\n";
exit(1);
}
else
{
for (int i = 0; !in_file.eof(); i++)
{
in_file.getline(cot[i].empName, 30, ',');
in_file.getline(cot[i].empID, 20, ',');
in_file.getline(cot[i].toolName, 30, ',');
in_file.getline(cot[i].toolID, 5, ',');
in_file.getline(cot[i].date, 15);
(*coNum)++;
}
}
in_file.close();
}
|