2017-01-22 5 views
-2

私は学校のプロジェクトのために作っている歯医者のアポイントメントシステムを持っており、患者の詳細を取り、アポイントメントを取らなければなりません。私は存在チェック、レンジチェックなどのための入力を検証しようとしています。新しい予定機能(int newApp())のアポイント番号でプレゼンスチェックを開始しましたが、これらのエラーが発生しています。私はそれが2D配列であり、正しく宣言していないが確信が持てないからだと思う。私の歯科医のアポイントメントシステムでテキストを検証することに固執しました

申し訳ありませんが、アノテーションがあまり良くない場合、私は時間が来ると思います。また、私はC++ビルダー6を使用しています。事前に感謝します。

編集 - 少ないコード。

//includes 
#include <conio.h> 
#include <fstream.h> 
#include <iostream.h> 
#include <clx.h> 
#include <string.h> 
#include <printers.hpp> 
#pragma hdrstop 

// Customer file definitions 
char FileName1[200]="PatientFile"; 
typedef struct tag_cr{ 
     char patNo[4]; 
     char patFName[15]; 
     char patSName[15]; 
     char patNum[12]; 
     char patBday[12]; 
     char patDateJoin[12]; 
     char addLine1[30]; 
     char addLine2[30]; 
     char city[15]; 
     char postcode[9]; 
     char flag[2]; 
} PATIENT_RECORD; 
int patNo; 
PATIENT_RECORD a_pat; 

//Global Variables for sequentialfileaccess 
char appFile[200] = "Appointment File";  // Name of data file 
char appPatNo[200][4];       // Patient number in appointment file 
char appNo[200][4];       // Appointment number 
char appDay[200][12];       // Appointment Date 
char appTime[200][6];       // Appointment Time 
char appDenName[200][25];      // Name of the dentist the appointment is with 
char appReason[200][30];      // Reason for appointment 
int nai;          // Number of appointments as an integer 
char nac[4];         // Number of apointments as a character array 

//Function Declaration 
int mainMenu();        // User Interface 

int newApp();         // New appointment 
int findApp();         // Find appointment 
int delApp();         // Delete appointment 
int newPat();         // Register a patient 
int delPat();         // Delete patient record 
int updPat();         // Update patient record 

int reWriteAppFile();       // Write the appointment file 
int readBackAppFile();       // Read the appointment file 
int createEmptyFileV();      // Verify if the user wants to create empty file for data 
int createEmptyFile();       // Create empty file for data 

bool validateAppNo(char *); 

//--------------------------------------------------------------------------- 

    int newApp() 
      { 
      int compare; 
      cout<< "\nAdd a new appointment"; 
      cout << "\nEnter patient number "; 
      cin>>patNo; 
      ifstream fin(FileName1, ios::binary); 
      fin.seekg(patNo * sizeof (a_pat)); 
      fin.read((char*)&a_pat,sizeof(a_pat)); 
      fin.close(); 
      compare = strcmpi(a_pat.flag, "0"); 
      if(compare != 0) 
      { 
        readBackAppFile(); 
        cin.get(); 

        cout << "\nEnter the appointment number "; 
        cin.getline(appNo[nai], sizeof(appNo)); 
        while(validateAppNo(appNo[nai]) == false) 
        { 
          cout << "\nPlease enter a valid appointment number"; 
          cin.getline(appNo[nai], sizeof(appNo)); 
        } 
        cout << "\nEnter the date of the appointment "; 
        cin.getline(appDay[nai], sizeof(appDay)); 
        cout << "\nEnter the time of the appointment "; 
        cin.getline(appTime[nai], sizeof(appTime)); 
        cout << "\nEnter the dentists name "; 
        cin.getline(appDenName[nai], sizeof(appDenName)); 
        cout << "\nAppointment reason "; 
        cin.getline(appReason[nai], sizeof(appReason)); 
        sprintf(appPatNo[nai], "%d", patNo); 
        nai=nai+1; 
        itoa(nai, nac, 10); 
        reWriteAppFile(); 
      } else { 
      cout << "\nNo patient found"; 
      } 
      return 0; 
      } 

      bool validateAppNo(appNo[nai]) 
      { 
        bool status = false; 
        if(appNo != NULL) 
        { 
          status = true; 
        } 
        return status; 
      } 
+5

これはかなりのコードです。実際、あまりにも多く。問題を再現するために最小限の額を投稿してください。 [mcve] – AndyG

+0

を参照してくださいまあ、私はここで新しいと別の投稿で私のコードを投稿するように誰かに教えてくれたでしょう。 – JohnT

+0

文字配列の代わりに 'std :: string'を使用することをお勧めします。文字配列にはバッファオーバーランの問題があります。 –

答えて

1

ユーザー入力を検証する方法は多数あります。

私の個人的なスタイルは、ブール変数で成功を実装し、1つのエントリ1つのリターンを使用することです:

bool Is_Valid(const tag_cr& record) 
{ 
    bool is_valid = true; 
    if (strlen(record.patNo) == 0) 
    { 
    is_valid = false; 
    } 
    if (is_valid && (strlen(record.patFName) == 0) 
    { 
    is_valid = false; 
    } 
    // And so on... 
    return is_valid; 
} 

もっと便利機能がレコードが無効である理由を説明するエラーテキストを返します:

bool Is_Valid(const tag_cr& record, std::string& reason) 
{ 
    bool is_valid = true; 
    if (strlen(record.patNo) == 0) 
    { 
    reason = "patNo field is empty"; 
    is_valid = false; 
    } 
    if (is_valid && (strlen(record.patFName) == 0) 
    { 
    reason = "patFName"; 
    is_valid = false; 
    } 

    // And so on... 
    return is_valid; 
} 
+0

ありがとう、これを私のコードにC++で実装する方法。私は行くとあなたの助けをいただきありがとう、研究を行います。 – JohnT

関連する問題