Thread: I Need Help

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    1

    Exclamation I Need Help

    hi there I am a newbie

    could you please convert this c++ program into a C program

    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<stdio.h>
    #define NULL 0
    
    class address
    {
        private:
        struct info
        {
          char nickname[20],name[30],mail[35];
          int id_no;long int phone;
          info *next;
        };
        info *head,*temp,*disp;
        public:
        address();
        ~address();
        void addrecord();
        void deleterecord();
        void modifyrecord();
        void displayrecord();
    };
    void address::address()
    {
        head=NULL;
        temp=NULL;
        disp=NULL;
    }
    address::~address()
    {
        while(head!=NULL)
        {
          info *t1;
          t1=head;
          head=head->next;
          delete t1;
        }
    }
    
    void address::addrecord()
    {
        info *add;
        char proceed='y';
        while(proceed=='y')
        {
          clrscr();
          add=new info;gotoxy(25,10);
          cout<<"\n\tEnter item entry number  :";
          cin>>add->id_no;
          fflush(stdin);
          cout<<"\n\t\tEnter name  :";
          scanf("%s",add->name);
          fflush(stdin);
          cout<<"\n\t\tEnter e-mail address  :";
          scanf("%s",add->mail);
          fflush(stdin);
          cout<<"\n\t\tEnter phone number  :";
          cin>>add->phone;
          fflush(stdin);
          cout<<"\n\t\tEnter nickname  :";
          scanf("%s",add->nickname);
          fflush(stdin);
    
          if(head==NULL)
          {
    	head=add;
    	add->next=0;
    	temp=add;
          }
          else
          {
    	temp->next=add;
    	add->next=NULL;
    	temp=add;
          }
          cout<<"\n\n\t\tWant to proceed[y/n]:";
          cin>>proceed;
          fflush(stdin);
        }
    }
    
    void address::deleterecord()
    {
        info *del;
        int tex,present=0;clrscr();
        if(head==NULL)
        {
          gotoxy(25,20);
          cout<<"\n No record found to delete";getch();
          return;
        }
        gotoxy(25,20);
        cout<<"\n Enter item number to delete:";
        cin>>tex;
        fflush(stdin);
        for(del=head;del!=NULL;del=del->next)
        {
          if(del->id_no==tex)
          {
    	if(head->id_no==tex)
    	{
    	  del=head;
    	  head=head->next;
    	  delete del;
    	  return;
    	}
    	else
    	{
    	  for(disp=head;disp!=NULL;disp=disp->next)
    	  if(disp->next==del)
    	  {
    	    disp->next=del->next;
    	    delete del;
    	    if(disp->next==NULL) temp=disp;
    	    return;
    	  }
    	}
          }
        }
        if(present==0)
        cout<<"\n No such entry found";
        else
        cout<<"\n Entry deleted.";getch();
    }
    
    void address::modifyrecord()
    {
        info *modify;
        int tex,present=0;clrscr();gotoxy(25,20);
        cout<<"\n Enter entry number to edit ";
        cin>>tex;
        fflush(stdin);
        for(modify=head;modify!=NULL;modify=modify->next)
        {
          if(modify->id_no==tex)
          {
    	cout<<"\n\t\t Enter nickname to change:";
    	scanf("%s",modify->nickname);
    	fflush(stdin);
    	cout<<"\n\t\t Enter name to change:";
    	scanf("%s",modify->name);
    	fflush(stdin);
    	cout<<"\n\t\t Enter e-mail to change:";
    	scanf("%s",modify->mail);
    	fflush(stdin);
    	cout<<"\n\t\t Enter phone number to change";
    	cin>>modify->phone;
    	fflush(stdin);
    	return;
          }
        }
        if(present==0)
        cout<<"\n Entry not found";getch();
    }
    
    void address::displayrecord()
    {
        if(head==NULL)
        {
          clrscr();
          cout<<"\n No record to display";getch();
          return;
        }
        for(disp=head;disp!=NULL;disp=disp->next)
        {
          clrscr();gotoxy(25,20);
          cout<<"\n\t entry no:"<<disp->id_no;
          cout<<"\n\t nickname:"<<disp->nickname;
          cout<<"\n\t name:"<<disp->name;
          cout<<"\n\t e-mail address:"<<disp->mail;
          cout<<"\n\t phone number:"<<disp->phone;
          getch();
        }
    }
    
    void main()
    {
        int choice;
        address addressobj;
        while(1)
        {
          clrscr();
          gotoxy(25,20);
          cout<<"ADDRESS BOOK \n\n\n\n";
          cout<<"\n\t\t 1.ADD NEW ENTRY";
          cout<<"\n\t\t 2.DELETE ENTRY";
          cout<<"\n\t\t 3.MODIFY RECORD";
          cout<<"\n\t\t 4.DISPLAY RECORD";
          cout<<"\n\t\t 5.EXIT\n";
          cout<<"\n\t\t Enter your choice [1-5]:";
          cin>>choice;
          fflush(stdin);
          switch(choice)
          {
    	case 1:
    	  addressobj.addrecord();
    	  break;
    	case 2:
    	  addressobj.deleterecord();
    	  break;
    	case 3:
    	  addressobj.modifyrecord();
    	  break;
    	case 4:
    	  addressobj.displayrecord();
    	  break;
    	case 5:
    	  return;
          }
        }
    }
    I really need help.. please do if you can


    thanks in advance

    Nb

    &#91;code]&#91;/code]tagged by Salem

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    What is the problem that you don't do it yourself?

  3. #3
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    as im having amnesia i'm not very sure about this but there are converters who can convert c code to c++ and i guess there will be some apps who do the reversed thing....this is a c to c++ converter
    i think you should be able to find a reversed prog by using this "awsome link"
    Last edited by GanglyLamb; 12-14-2002 at 10:08 AM.

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    cout --> printf
    cin --> scanf / fgets
    class methods --> functions
    class data --> variables and/or structures
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed