-1

こんにちは、最大 12 文字を処理し、isUpper、isLower、IsPunctuation の 3 つの個別のブール関数を呼び出すことができる c++ でパスワード関数を作成しようとしています。

開始するための提案やテンプレートはありますか? この部分を邪魔にならないようにして、プログラムを続けたいと思います。いつもお世話になっております。

これは私がこれまでに持っているものです:

#include<iostream.h>
#include<conio.h> 
#include<string.h> 

char enterPass(); 
void passFunc(); 

char enterPass() { 
    char numPass[12]; 
    char ch; 
    int i=0; 

    while((ch!='\r')||(ch!='\n')&&(i!=11)) { 
       cin>>ch; cout<<'*'; numPass[i]=ch; i++; 
    } 
    return numPass[12]; 
} 

void passFunc() { 
    char pass[12];

    cout<<"Enter password :- ";
    pass=enterPass(); 
    if(strcmp(pass,"myworld")==0) { 
        cout<<"Correct Password"; getch(); 
    } else { 
       cout<<"Wrong Password"; 
       exit(0); 
    } 
} 

int main() { 
    passFunc(); 
    getch(); 
    return 0; 
}
4

2 に答える 2

0

コードのわずかな (教訓的な) 変更から構築を開始することもできます。

#include <iostream> 
using namespace std;

void enterPass(char* numPass) 
{ 
  char ch; 
  int i=0; 

  while ((ch!=10)&&(i!=13)) // ch=10 is "return"
  { 
    ch=(char)getchar(); //input will not be hidden
    numPass[i++]=ch;
  } 
  numPass[--i]='\0';    //need to form a `string`
}; 


void passFunc() 
{ 
  char pass[13]; 
  cout<<"Enter password :- "; 

  enterPass(pass); 
  if(strcmp(pass,"myworld")==0) 
  { 
    cout<<"Correct Password\n"; 
  } 
  else 
  { 
    cout<<"\n|"<<pass<<"|\n";
    cout<<"Wrong Password\n"; 
    exit(0); 
  } 
};


int main() 
{ 
  passFunc(); 
  return 0; 
}

同様のことを行うコードがたくさんある可能性が高いため、彼らはあなたの質問に反対票を投じています。この質問から始めて、「重複の可能性」リストを掘り下げることをお勧めします。

于 2012-04-24T07:47:37.927 に答える