I am trying to write a program for my C++ class, however, my teacher has failed to provide us with the proper materials to complete the project. We are suppose to write a program on the following:
--------------------------------------------------------------------------------
This program involves developing a menu-driven database application. You need to accept as input from a file a person's first name, last name, phone number, and birth date. This program will be menu driven with the following options:
1. Find a person's name.
2. Add a person to the database.
3. Edit a person's info.
4. Display all records to the screen.
5. Quit.
--------------------------------------------------------------------------------
It is required for this example that we using binary sorting to rearrange the strings/arrays in the file.
I really don't know what to do... I am at my whits end right now. If anyone could offer some helpful advice I would greatly appreciate it. Here is what I have come up with so far... but I don't know what to do next.
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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
#include <iostream>
#include <fstream>
using namespace std;
void find(char[]);
void add(char[]);
void edit(char[]);
void display(char[]);
int main()
{
char FILENAME[81];
int n = 0;
cout << "Enter filename: ";
cin >> FILENAME;
for (;n!=5;)
{
cout << "\nChoose your operation.";
cout << "\n1 - Find a person's information\n" << "2 - Add a person to the database\n" << "3 - Edit a person's information\n" << "4 - Display all of the records\n";
cout << "5 - Quit\n";
cout << "==> ";
cin >> n;
switch (n)
{
case 1:
find(FILENAME);
break;
case 2:
add(FILENAME);
break;
case 3:
edit(FILENAME);
break;
case 4:
display(FILENAME);
break;
case 5:
break;
}
}
}
void find(char FILENAME[])
{
string firstname, lastname;
string onename, lstname, phone, dob;
ifstream data;
data.open(FILENAME);
cout << "Who would you like to find?\n" << "First Name: ";
cin >> firstname;
cout << "Last Name: ";
cin >> lastname;
while (!data.eof())
{
data >> onename;
data >> lstname;
data >> phone;
data >> dob;
if (firstname == onename && lastname == lstname)
{
cout << endl << onename << " " << lstname << " " << phone << " " << dob << endl;
}
}
}
void add(char FILENAME[])
{
string onename, lstname, phone, dob;
ofstream data;
data.open (FILENAME);
data.eof();
cout << "Enter the information below\n" << "First Name: ";
cin >> onename;
cout << "Last Name: ";
cin >> lstname;
cout << "Phone Number: ";
cin >> phone;
cout << "DOB: ";
cin >> dob;
data << onename << " ";
data << lstname << " ";
data << phone << " ";
data << dob;
data.close();
}
void edit(char FILENAME[])
{
int f, line = 0, j = 0;
string firstname, lastname;
string onename, lstname, phone, dob;
cout << "Who would you like to edit?\n" << "First Name: ";
cin >> firstname;
cout << "Last Name: ";
cin >> lastname;
fstream data;
data.open(FILENAME);
while (!data.eof() && j == 0)
{
line = ++line;
data >> onename;
data >> lstname;
data >> phone;
data >> dob;
if (firstname == onename && lastname == lstname)
{
j = 1;
cout << endl << onename << " " << lstname << " " << phone << " " << dob << endl;
cout << "What would you like to edit?\n";
cout << "1 - First Name\n" << "2 - Last Name\n" << "3 - Phone Number\n" << "4 - DOB\n" << "==> ";
cin >> f;
switch (f)
{
case 1:
cout << "Enter new first name: ";
cin >> onename;
break;
case 2:
cout << "Enter new last name: ";
cin >> lstname;
break;
case 3:
cout << "Enter new phone number: ";
cin >> phone;
break;
case 4:
cout << "Enter new DOB: ";
cin >> dob;
break;
}
data << onename;
data << lstname;
data << phone;
data << dob;
data.close();
}
}
}
void display(char FILENAME[])
{
string output;
ifstream data;
data.open(FILENAME);
while (!data.eof())
{
for (int i = 0; i < 4; i++)
{
data >> output;
cout << output << " ";
}
cout << endl;
}
}
|