C++

C++ Project on Address Book

Address Book

#include
#include
#include
#include
#include
#include
#include
#include
#include

void welcome_screen();

void welcome_screen()
{
    clrscr();
    gotoxy(20,10);
    cputs("**************** W E L C O M E  *********************** ");
    gotoxy(25,12);
    cputs("*** C A M P I O N    S C H O O L *** ");
    gotoxy(20,14);
    textcolor(WHITE);
    cputs(" T E L E P H O N E  M A N A G E M E N T  S O F T W A R E  ");
    gotoxy(38,16);
    textcolor(WHITE);
    cputs(" D O N E  B Y :  ");
    gotoxy(50,18);
    cputs(" Navi ");
    gotoxy(50,20);
    cputs("");

    textcolor(WHITE+BLINK);
    gotoxy(40,30);
    cputs(" *** PRESS ANY KEY TO CONTINUE***");
    getch();
    return;
}

class directory
{
  public:
    int record;
    long pn1;
    char pn2[10];
    int age;
    char address1[50];
    char address2[50];
    char occupation[20];
    char name[20];
    char emailadd[25];
    char internetadd[25];
    void modification();
    void addition();
    void deleate();
    void menu();
    void search();
    void view1();
    void init();
    void display();
    void view();
    char check(char *);
    int test();
} obj;

void directory::addition()  // ADDING INFORMATION
{
    ofstream fout;
    fout.open("heera", ios::out|ios::app);
    init();
    fout.write((char*)&obj, sizeof(obj));
    fout.close();
}

int directory::test()    // FIND NO. OF RECORDS
{
    ifstream fin;
    fin.open("heera");
    fin.seekg(0, ios::end);
    int n;
    n = fin.tellg() / sizeof(obj);
    cout << " \n NUMBER OF RECORDS = " << n;
    return n;
}

void directory::search()
{
    char pn[10];
    int i;
    ifstream fin;
    fin.open("heera");
    cout << "\n ENTER PHONE NUMBER TO SEARCH : ";
    cin >> pn;
    int n;
    n = test();
    for (int i = 0; i < n; i++)
    {
        fin.read((char*)&obj, sizeof(obj));
        if (strcmp(pn2, pn) == 0)
        {
            view1();
        }
    }
    fin.close();
}

void directory::init()
{
    char ch;
    cout << " \n ENTER HOME PHONE NUMBER : ";
    cin >> pn1;
    cout << " \n ENTER OFFICE PHONE NUMBER : ";
    cin >> pn2;
    // ch=cin.get();
    cin.get(ch);
    cout << " \n ENTER NAME : ";
    cin.getline(name, 20, '\n');
    cout << " \n ENTER THE OCCUPATION : ";
    cin.getline(occupation, 20, '\n');
    cout << " \n ENTER HOUSE ADDRESS : ";
    cin.getline(address1, 50, '\n');
    cout << " \n ENTER OFFICE ADDRESS : ";
    cin.getline(address2, 50, '\n');
    cout << " \n ENTER EMAIL ADDRESS : ";
    cin.getline(emailadd, 25, '\n');
    cout << " \n ENTER INTERNET ADDRESS : ";
    cin.getline(internetadd, 25, '\n');
}

void directory::view1()  // TO DISPLAY ALL THE RECORDS
{
    cout << "\n";
    cout << " PHONE NUMBER1 : " << pn1 << "\n";
    cout << " PHONE NUMBER2 : " << pn2 << "\n";
    cout << " NAME : " << name << "\n";
    cout << " OCCUPATION : " << occupation << "\n";
    cout << " HOME ADDRESS : " << address1 << "\n";
    cout << " OFFICE ADDRESS : " << address2 << "\n";
    cout << " EMAIL ADDRESS : " << emailadd << "\n";
    cout << " INTERNET ADDRESS : " << internetadd << "\n";
}

void directory::view()  // TO DISPLAY ALL THE RECORDS
{
    ifstream fin;
    fin.open("heera");
    int n;
    n = test();
    for (int i = 0; i < n; i++)
    {
        fin.read((char*)&obj, sizeof(obj));
        view1();
    }
    fin.close();
}

void directory::deleate()  // TO DELETE A RECORD
{
    char pn[10];
    int i;
    ifstream fin;
    fin.open("heera");
    ofstream fout;
    fout.open("temp", ios::out);
    cout << "\n ENTER PHONE NUMBER TO DELETE : ";
    cin >> pn;
    int n;
    n = test();
    for (i = 0; i < n; i++)
    {
        fin.read((char*)&obj, sizeof(obj));
        if (strcmp(pn2, pn) != 0)
        {
            fout.write((char*)&obj, sizeof(obj));
        }
    }
    fout.close();
    fin.close();
    remove("heera");
    rename("temp", "heera");
}

void directory::modification()  // TO MODIFY A RECORD
{
    char pn[10];
    int i;
    ifstream fin;
    fin.open("heera");
    ofstream fout;
    fout.open("temp", ios::out);
    cout << "\n ENTER PHONE NUMBER TO MODIFY : ";
    cin >> pn;
    char ch;
    ch = cin.get();
    // cin.get(ch);
    for (i = 0; i < test(); i++)
    {
        fin.read((char*)&obj, sizeof(obj));
        if (strcmp(pn2, pn) == 0)
        {
            if (check("HOME PHONE NUMBER") == 'Y')
            {
                cout << " \n ENTER NEW PHONE NUMBER :";
                cin >> pn1;
                ch = cin.get();
                // cin.get(ch);
            }
            if (check("OFFICE PHONE NUMBER ") == 'Y')
            {
                cout << " \n ENTER NEW PHONE NUMBER :";
                cin >> pn2;
                ch = cin.get();
                // cin.get(ch);
            }
            if (check("NAME") == 'y')
            {
                cout << " \n ENTER NEW NAME : ";
                cin.getline(name, 20, '\n');
            }
            if (check("HOME ADDRESS") == 'y')
            {
                cout << "\n ENTER NEW ADDRESS :";
                cin.getline(address1, 50, '\n');
            }
            if (check("OFFICE ADDRESS") == 'y')
            {
                cout << "\n ENTER NEW ADDRESS :";
                cin.getline(address2, 50, '\n');
            }
            if (check("EMAIL ADDRESS:") == 'y')
            {
                cout << "\n ENTER NEW MAIL ADDRESS :";
                cin.getline(emailadd, 25, '\n');
            }
            if (check("INTERNET ADDRESS") == 'y')
            {
                cout << "\n ENTER NEW INTERNET ADDRESS :";
                cin.getline(internetadd, 25, '\n');
            }
        }
        fout.write((char*)&obj, sizeof(obj));
    }
    fout.close();
    fin.close();
}

char directory::check(char *s)
{
    cout << "\n MODIFY \t " << s << " ? (Y/N) : ";
    char ch;
    cin >> ch;
    return ch;
}

void directory::menu()
{
    char pn[10];
    int i;
    cout << "\n ENTER PHONE NUMBER TO SEARCH : ";
    cin >> pn;
    for (i = 0; i < test(); i++)
    {
    }
}
Share:

Comments from readers

Leave a Comment

Share your thoughts below. Comments appear after a quick review.

You may also want to see: