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
|
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
#define LEN1 100
#define LEN2 30
void sortingfunc(char[][LEN2], char[][LEN2], char [][LEN2], char [][LEN2],char [255], int);
void readfromfile(char firstn[LEN1][LEN2], char lastn[LEN1][LEN2], char phonen[LEN1][LEN2], char birthd[LEN1][LEN2], char [255]);
void searchfunc(char firstn[][LEN2], char lastn[][LEN2], char phonen[][LEN2], char birthd[][LEN2],char filename[255]);
void main()
{
int choice, n=0, i=0, j=0;
char filename[255]= "data.txt",
temp[LEN1][LEN2]={0}, search[30]={0}, firstn[LEN1][LEN2]={0}, lastn[LEN1][LEN2]={0}, phonen[LEN1][LEN2]={0}, birthd[LEN1][LEN2]={0};
readfromfile(firstn, lastn, phonen, birthd, filename);
cout << "Enter a number to choose an option:\n1. Find a person's information\n2. Add a person to the database\n3. Edit a person's information\n4. Display all records to the screen\n5. Quit\n";
cin >> choice;
switch (choice)
{
case 1:
{
}
case 2:
{
}
case 3:
{
}
case 4:
{
}
case 5:
{
sortingfunc(firstn, lastn, phonen, birthd, filename, n);
return;
}
}
}
void readfromfile(char firstn[LEN1][LEN2], char lastn[LEN1][LEN2], char phonen[LEN1][LEN2], char birthd[LEN1][LEN2], char filename[255])
{
int i=0, n=0;
string line;
ifstream file;
file.open(filename);
if (file.is_open())
{
while (!file.eof())
{
getline(file,line);
for (i=0;i<line.length();i++)
{
firstn[n][i] = line[i];
}
getline(file,line);
for (i=0;i<line.length();i++)
{
lastn[n][i] = line[i];
}
getline(file,line);
for (i=0;i<line.length();i++)
{
phonen[n][i] = line[i];
}
getline(file,line);
for (i=0;i<line.length();i++)
{
birthd[n][i] = line[i];
}
getline(file,line);
n++;
}
}
file.close();
}
void sortingfunc(char firstn[][LEN2], char lastn[][LEN2], char phonen[][LEN2], char birthd[][LEN2], char filename[255], int n)
{
int iol=0, i;
char temp[LEN1][LEN2]={0};
ofstream file;
file.open(filename);
if (file.is_open())
{
n=n-1;
do
{
iol=0;
for (i=0; i<=n; i++)
{
if (strcmp(lastn[iol],lastn[i])<0)
{
iol=i;
}
}
strcpy_s(temp[0],lastn[n]);
strcpy_s(lastn[n],lastn[iol]);
strcpy_s(lastn[iol],temp[0]);
strcpy_s(temp[0],firstn[n]);
strcpy_s(firstn[n],firstn[iol]);
strcpy_s(firstn[iol],temp[0]);
strcpy_s(temp[0],phonen[n]);
strcpy_s(phonen[n],phonen[iol]);
strcpy_s(phonen[iol],temp[0]);
strcpy_s(temp[0],birthd[n]);
strcpy_s(birthd[n],birthd[iol]);
strcpy_s(birthd[iol],temp[0]);
n--;
} while (n>0);
file.close();
}
}
|