اطلاعیه

Collapse
No announcement yet.

مشکل این برنامه چیه؟

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    مشکل این برنامه چیه؟

    سلام اساتید و بزرگان
    این برنامه ای که نوشتم 2 تا ارور میده لطفا راهنماییم کنید!
    #include <stdio.h>
    #include <conio.h>
    #include <process.h>

    struct bookinfo{
    addnew();
    private:
    char title[20];
    char author[15];
    char publisher[15];
    char stead[50];
    int history;
    int version_num;
    };
    int menu();
    void addnew();
    void quit();
    //************************************************** ****************************
    //Main Part Of The Program
    //************************************************** ****************************

    int main()
    { bookinfo inf;
    int choise;
    char wrd;
    for( ; ; )
    {
    clrscr();
    choise=menu();
    switch(choise)
    {
    case 1: //Entering new bookinf
    clrscr();
    inf.addnew();
    break;
    case 2: //searching a word
    printf("Enter a word to search:"
    scanf("%s",&wrd);
    break;
    case 3: //Reports

    case 4: //Exit the program
    quit();
    break;
    default: //Incorrect Value
    printf("Enter a valid number between 1_4!"
    printf("\a"
    getch();
    break;
    }
    }
    }

    //***********<<Main menu>>**********
    int menu()
    {
    int p;
    gotoxy(35,20);
    printf("1)Add record"
    gotoxy(35,21);
    printf("2)Search record"
    gotoxy(35,22);
    printf("3)Reports"
    gotoxy(35,23);
    printf("4)Exit"
    gotoxy(35,24);
    printf("Enter your select(1_4)"
    scanf("%d",&p);
    return p;
    }

    //*************<<Quit>>*************
    void quit()
    {
    char ans;
    gotoxy(28,28);
    printf("<<Quit>>"
    gotoxy(30,30);
    printf("Do u wanna to quit(Y/N)?"
    ans=getch();
    if(ans=='y' || ans=='Y&#039
    exit(0);
    else
    return;
    }

    //**************<<AddNew Bookinfo>>*************
    void bookinfo::addnew()
    {
    int col=35;
    gotoxy(col,20);
    printf("Title:"
    scanf("%s",inf.title);
    gotoxy(col,21);
    printf("Author:"
    scanf("%s",inf.author);
    gotoxy(col,22);
    printf("Publisher"
    scanf("%s",inf.publisher);
    gotoxy(col,23);
    printf("Stead"
    scanf("%s",inf.stead);
    gotoxy(col,24);
    printf("History"
    scanf("%d",inf.history);
    gotoxy(col,25);
    printf("Version_num"
    scanf("%d",inf.version_num);
    }

    #2
    پاسخ : مشکل این برنامه چیه؟

    سلام..............
    دوست عزیز بهتر بود خطا رو اینجا قرار می دادین تا کامل جوابتون رو بگیرین ولی تا اونجایی که من فهمیدم:
    اولا" تا اونجایی که یادمه توی ساختار تابع تعریف نمی کردیم :surprised:
    توی کلاس هم وقتی تابع تعریف می کردیم نوع تابع رو حتما" باید تعیین می کردیم
    ثانیا" فکر کنم این برنامه اون کاری که شما می خواهین رو انجام نده

    دیدگاه


      #3
      پاسخ : مشکل این برنامه چیه؟

      سلام



      #include <stdio.h>
      #include <conio.h>
      #include <process.h>


      struct bookinfo{
      void addnew();
      private:
      char title[20];
      char author[15];
      char publisher[15];
      char stead[50];
      int history;
      int version_num;

      };
      int menu();
      void addnew();
      void quit();
      //************************************************** ****************************
      //Main Part Of The Program
      //************************************************** ****************************

      int main()
      { bookinfo inf;
      int choice;
      char wrd;
      for( ; ; )
      {
      clrscr();
      choice=menu();
      switch(choice)
      {
      case 1: //Entering new bookinf
      clrscr();
      inf.addnew();
      break;
      case 2: //searching a word
      printf("Enter a word to search:"
      scanf("%s",&wrd);
      break;
      case 3: //Reports

      case 4: //Exit the program
      quit();
      break;
      default: //Incorrect Value
      printf("Enter a valid number between 1_4!"
      printf("\a"
      getch();
      break;
      }
      }
      }

      //***********<<Main menu>>**********
      int menu()
      {
      int p;
      gotoxy(35,20);
      printf("1)Add record"
      gotoxy(35,21);
      printf("2)Search record"
      gotoxy(35,22);
      printf("3)Reports"
      gotoxy(35,23);
      printf("4)Exit"
      gotoxy(35,24);
      printf("Enter your select(1_4)"
      scanf("%d",&p);
      return p;
      }

      //*************<<Quit>>*************
      void quit()
      {
      char ans;
      gotoxy(28,28);
      printf("<<Quit>>"
      gotoxy(30,30);
      printf("Do u wanna to quit(Y/N)?"
      ans=getch();
      if(ans=='y' || ans=='Y&#039
      exit(0);
      else
      return;
      }

      //**************<<AddNew Bookinfo>>*************
      void bookinfo::addnew()
      {
      int col=35;
      gotoxy(col,20);
      printf("Title:"
      scanf("%s",title);
      gotoxy(col,21);
      printf("Author:"
      scanf("%s",author);
      gotoxy(col,22);
      printf("Publisher"
      scanf("%s",publisher);
      gotoxy(col,23);
      printf("Stead"
      scanf("%s",stead);
      gotoxy(col,24);
      printf("History"
      scanf("%d",history);
      gotoxy(col,25);
      printf("Version_num"
      scanf("%d",version_num);
      }


      Upload your files Here. Great Azeri Resumable File Host: http://endir.az/index.php?lang=5

      دیدگاه


        #4
        پاسخ : مشکل این برنامه چیه؟

        سلام
        شما struct رو به class تبدیل کنید و تابع addnew رو توی public بنویسین جواب می ده
        بعد هم گفتم که error ها رو بذارین تا دقیق جوابتون رو بدم

        دیدگاه


          #5
          پاسخ : مشکل این برنامه چیه؟

          دوست عزیز اولا در قسمت زیر شما یک for پایان نپذیر گذاشتی که یجور خودکشی است!
          int main()
          { bookinfo inf;
          int choice;
          char wrd;
          for( ; ; )
          {
          clrscr();
          choice=menu();
          switch(choice)
          {
          case 1: //Entering new bookinf
          clrscr();
          inf.addnew();
          break;
          case 2: //searching a word
          printf("Enter a word to search:"
          scanf("%s",&wrd);
          break;
          case 3: //Reports

          case 4: //Exit the program
          quit();
          break;
          default: //Incorrect Value
          printf("Enter a valid number between 1_4!"
          printf("\a"
          getch();
          break;
          }
          }
          }

          ثانیا خارج شدن از این for منوط به switch و case است و شما در defualt این switch خروج رو نگذاشتید که امکان داره به for بینهایت منجر بشه!
          ثالثا در بعضی جاها بعد از فراخوانی تابع quite فرمان break رو بکار بردید حال آنکه در تابع مذکور از exit استفاده کردید
          رابعا بهتر بود بجای struct از class استفاده میکردید که انعطاف بیشتری دارد.
          خامسا اصلا نگفتید این برنامه قراره چیکار بکنه؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟

          امید وارم کمکی کرده باشم


          :nice: :nice: :nice: :nice: :nice: :nice: :nice: :nice: :nice:

          دیدگاه

          لطفا صبر کنید...
          X