Thread: Help me!!Please!!!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    8

    Help me!!Please!!!

    Please help me how to convert this C code to C++ with Class:
    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <mem.h>
    #include <string.h>
    #include <conio.h>
    
    #define MAX 100
    
    struct congnhan {
      char hoten[35];
      } danhsach[MAX];
    int n = 0;
    
    void nhapmoi()
    {
      char hoten[35], tmp[3];
      int i;
      do {
        printf("\nNhap ho ten CN : ");
        gets(hoten);
        if (strlen(hoten))
        {
          strcpy(danhsach[n].hoten,hoten);
          gets(tmp);
          n++;
        }
      } while (strlen(hoten));
    }
    
    void timkiem()
    {
      char hoten[5];
      int i = 0, found = 0;
      printf("\nCho ho ten CN can tim : ");
      gets(hoten);
      if (strlen(hoten))
        while (i<n)
          if (strcmp(danhsach[i].hoten,hoten) == 0)
          {
             printf("\nHo va ten : %s", danhsach[i].hoten);
             found = 1;
             break;
          }
          else
            i++;
      if (!found)
        printf("\nKhong tim thay!!!");
    }
    
    
    void menu()
    {
      printf("\n**QUAN LY CONG NHAN**");
      printf("\n* [1]. Them     *");
      printf("\n* [2]. Tim kiem *");
      printf("\n* [3]. Thoat    *");
      printf("\n***************");
      printf("\n Chon lua ? ");
    }
    
    void main()
    {
      char traloi;
      do {
        menu();
        do {
          traloi = getch();
        } while (traloi < '1' || traloi > '2');
        putc(traloi, stdout);
        switch (traloi)
        {
           case '1' : nhapmoi();
                      break;
           case '2' : timkiem();
                      break;
        }
      } while (traloi != '3');
    }
    It have got some errors,please help me to check it.Thanks.I'm newbie
    Last edited by KySiRo; 11-05-2006 at 01:30 AM.

Popular pages Recent additions subscribe to a feed