what is Input Validation
The Process In which We put the validation in any software
By Input Validation Mean Put the limitations in any software or programm
Why We Use Input Validation In C++
By Using Input validation our programm or software can make valueable Bcz By using Validation In Software the Software give or take the accurates values or things
For Examples
input validation c++ integer
input validation c++ integer
We Make the Student Management System Software in which we put the name age class date of birth :etc,
Input validation mean programm accept only value or data type which we give
For Example :
we Take int id then c++ programm accept only integer type :
If we give character for id then Programm Not Accept this Data
(With out input validation)
char name ;
int birth;
We entered the name: 45
we entered the birth date :Ali
input validation c++ strings
input validation c++ strings
(With Input Validation)
Int birth;
char name;
int age;
cout<<"Plz Enter the Name ";
cin>>name;
while(!cin)
{
cout<<"Plz Enter the Name";
cin>>name;
}
cout<<"Plz Enter the Age " ;
cin>>age;
if(age>1&&age<=100)
{
}
else
cout<<"Plz Enter the Age";
cin>>age;
if(age>1&&age<=100)
{
cout<<"Age correct";
}
Complete Example of Input Validation In C++
#include<conio.h>
#include<iostream.h>
void main()
{
int id;
char name;
int age;
cout<<"Plz Enter the Id";
cin>>id;
while(!cin)
{
cout<<"Plz Enter the ID";
cin>> id;
}
cout<<"Plz Enter The name ";
cin>>name;
while(!cin)
{
cout<<"Plz Enter the Correct Name";
cin>>name;
}
cout<<"Plz Enter the Age";
cin>age;
if(age>0&&age<=100)
{
cout<<"Plz Enter The Age";
cin>>age;
}
getch();
}
(Let,s Try on Your Own Compiler)
Good Luck !!!
No comments:
Post a Comment