C++ Problem Program

Discussion in 'Software' started by Rayzipan, Jan 16, 2008.

  1. Rayzipan

    Rayzipan Specialist

    Hi,
    I have a program to do - the brief is below in red text. Below that in dark blue text is the code i have done so far. The program does not work. Please help.

    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

    Design and implement a simple C++ system maintaining all relevant information on file.



    // 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::eek:ut);
    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::eek:ut); // 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;

    }
     
  2. Wookie

    Wookie Sergeant Major

    What are the compile errors? I see some lines that should be commented but I don't know if thats just a copy and paste issue
     
  3. Rayzipan

    Rayzipan Specialist

    Thank you for your help Wookie. Also thank you very much for helping me on other threads also.

    Here are the errors.

    Error 1 error C2086: 'std::ifstream instream_1' : redefinition c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 27
    Error 2 error C2086: 'std::eek:fstream outstream_1' : redefinition c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 28
    Error 3 error C2065: 'capital' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 4 error C2146: syntax error : missing ';' before identifier 'Z' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 5 error C2065: 'Z' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 6 error C2146: syntax error : missing ';' before identifier 'as' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 7 error C2065: 'as' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 8 error C2146: syntax error : missing ';' before identifier 'sentinel' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 9 error C2065: 'sentinel' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 10 error C2146: syntax error : missing ';' before identifier 'is' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 11 error C2065: 'is' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 12 error C2146: syntax error : missing ';' before identifier 'used' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 13 error C2065: 'used' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 14 error C2146: syntax error : missing ';' before identifier 'because' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 15 error C2065: 'because' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 16 error C2146: syntax error : missing ';' before identifier 'of' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 17 error C2065: 'of' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 18 error C2146: syntax error : missing ';' before identifier 'its' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 19 error C2065: 'its' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 20 error C2146: syntax error : missing ';' before identifier 'ASCII' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 21 error C2065: 'ASCII' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 22 error C2146: syntax error : missing ';' before identifier 'value' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 23 error C2065: 'value' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 24 error C2146: syntax error : missing ';' before identifier 'being' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 25 error C2065: 'being' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 26 error C2146: syntax error : missing ';' before identifier 'more' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 27 error C2065: 'more' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 28 error C2146: syntax error : missing ';' before identifier 'than' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 29 error C2065: 'than' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 30 error C2146: syntax error : missing ';' before identifier 'all' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 31 error C2065: 'all' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 32 error C2146: syntax error : missing ';' before identifier 'other' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 58
    Error 33 error C2065: 'other' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 59
    Error 34 error C2146: syntax error : missing ';' before identifier 'letters' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 59
    Error 35 error C2065: 'letters' : undeclared identifier c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 59
    Error 36 error C2143: syntax error : missing ';' before 'while' c:\documents and settings\raymond.white\my documents\visual studio 2005\projects\aaaaa\aaaaa\aaaaa.cpp 59
     
  4. Wookie

    Wookie Sergeant Major

    Ah simple one, you declared a variable twice :)


    Code:
     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;


    Just get rid of the second instream_1 and outstream_1 or rename them
     
  5. Rayzipan

    Rayzipan Specialist

    thanks again Wookie
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds