Training, Open Source
computer languages


PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
HELP ME on this code..y i can't run on it..

Posted by antzzz (antzzz), 18 March 2008
#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <stdio.h>


class AddressBook
{
   public:
       char name[50];
       char add[50];
       char tel[20];
};

int main ()
{
 AddressBook myAddBook[50];
 int ch, count=0, i, j;
 char myName[50], c;  
 do{
     flushall();
       clrscr();
       cout << "   MENU     " << endl;
       cout << " [1] Add    " << endl;
       cout << " [2] Edit   " << endl;
       cout << " [3] Delete " << endl;
       cout << " [4] View   " << endl;
       cout << " [5] Exit   " << endl;
       cout << " Enter Choice: ";
       cin >> ch;

       clrscr();
       if(ch == 1)
       {
           cout << "Name: ";
           cin >> myAddBook[count].name;
           cout << "Address: ";
           cin >> myAddBook[count].add;
           cout << "Telephone: ";
           cin >> myAddBook[count].tel;
           cout << "New Data Added...";
           getch();
           count++;
       }
       if(ch == 2)
       {
           cout << "Name: ";
           cin >> myName;
           for(i=0;i<count;i++)
           {
               if(strcmp(myName,myAddBook[count].name) == 0)
               {
                     clrscr();
                     cout << "Name: " << myAddBook[i].name << endl;
                     cout << "Address: " << myAddBook[i].add << endl;
                     cout << "Telephone: " << myAddBook[i].tel <<
endl;
                     cout << "Is this the one [n]? [y / n]";
                     c = getch();
                     if(c == 'y')
                     {
                           cout << "Name: ";
                           cin >> myAddBook[i].name;
                           cout << "Address: ";
                           cin >> myAddBook[i].add;
                           cout << "Telephone: ";
                           cin >> myAddBook[i].tel;
                           cout << "New Data Updated...";
                           getch();
                     }
               }
           }
       }
       if(ch == 3)
       {
           cout << "Name: ";
           cin >> myName;
           for(i=0;i<count;i++)
           {
               if(strcmp(myName,myAddBook[count].name) == 0)
               {
                     clrscr();
                     cout << "Name: " << myAddBook[i].name << endl;
                     cout << "Address: " << myAddBook[i].add << endl;
                     cout << "Telephone: " << myAddBook[i].tel <<
endl;
                     cout << "Is this the one [n]? [y / n]";
                     c = getch();
                     if(c == 'y')
                     {
                           for(j=1; j<count; j++)
                           {
                               strcpy(myAddBook[j].name,
myAddBook[j+1].name);
                               strcpy(myAddBook[j].add,
myAddBook[j+1].name);
                               strcpy(myAddBook[j].tel,
myAddBook[j+1].name);
                           }
                           cout << "Data has been delete...";
                           getch();
                     }
               }
           }
       }
       if(ch == 4)
       {
               j=0;
               for(i=0;i<count;i++)
               {
                   if(j==3)
                   {
                       cout << "Press any key tocontinue...";
                       getch();
                       j=0;
                       clrscr();
                   }
                   cout << "Name: " << myAddBook[i].name << endl;
                   cout << "Address: " << myAddBook[i].add << endl;
                   cout << "Telephone: " << myAddBook[i].tel << endl;
                   j++;
               }
       }
 }while(ch != 5);

 return 0;
}



Posted by admin (Graham Ellis), 18 March 2008
Thank you for the code.  Your question is unclear; can you please describe what the issue you have with this code is so that I can try to help you.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.


WELL HOUSE CONSULTANTS LTD.: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho