Hi,
I have a c++ programming assignment that is driving me crazy. Below is the assignment.
A simple sequential file-based database is required to help people keep track of contacts. The system should be able to hold information about the following at least.
-Surname
-First name
-Email
-Telephone no.
-Type (work/personnel)
You may add more information if you wish!
The file is always ordered in increasing alphabetical order on Surname.
The following operations are required (at least)
� add new entry
� modify an entry
� delete an entry
� search for entry or entries
� list all contacts to a file for printing (the output should look �neat�)
Design and implement a simple C++ system maintaining all relevant information on file.
Please help. Here is some code I have done but I am unable to get it to work.
// Code to Add an entry
#include <iostream>
#include <fstream> // stream class to both read and write from/to files
#include <string>
using namespace std; // no need for .h after libraries when using this line
int main()
{
ifstream instream_1; // temporary
ofstream outstream_1; // contacts
ifstream instream_2; // temporary
ofstream outstream_2; // contacts
// the following six lines will create the contacts and temporary text files
ifstream instream_1; // declarations of streams instream_1 outstream_1
ofstream outstream_1;
instream_1.open\("temporary.txt", ios::in\); // open the streams
outstream_1.open\("contacts.txt", ios::out\);
instream_1.close\(\); // close the streams
outstream_1.close\(\);
string surname_1, first_name_1, email_1, telephone_1, type_1; // string for old contacts
string surname_2, first_name_2, email_2, telephone_2, type_2; // string for new contacts
/*
outstream.open ("contacts.txt");
outstream.close();
*/
instream_1.open\("temporary.txt",ios::in\); // open for input operations
outstream_1.open\("contacts.txt",ios::out\); // open for output operations.
instream\_1>>surname\_1>>first\_name\_1>>email\_1>>telephone\_1>>type_1;
cout<<"Enter Surname: ";
cin>>surname_1;
cout<<"\\nEnter First Name: ";
cin>>first\_name_1;
cout<<"\\nEnter Email Address: ";
cin>>email_1;
cout<<"\\nEnter Telephone Number: ";
cin>>telephone_1;
cout<<"\\nEnter Type\(Work / Personal\): ";
cin>>type_1;
capital Z as sentinel is used because of its ASCII value being more than all other letters
while \(surname_1 != "ZZZZZ"\) // 2 or more while loops are required
\{
instream\_1>>surname\_1>>first\_name\_1>>email\_1>>telephone\_1>>type_1;
outstream\_1<<surname\_1<<first\_name\_1<<email\_1<<telephone\_1<<type_1;
\}
while\(\(surname_2 > surname_1\)\)
\{
instream\_1>>surname\_1>>first\_name\_1>>email\_1>>telephone\_1>>type_1;
outstream\_1<<surname\_1<<first\_name\_1<<email\_1<<telephone\_1<<type_1;
\}
instream_1.close(); // the file is closed
outstream_1.close(); // the file is closed
return 0;
}