In: Computer Science
Write a program that can check whether or not some string is a valid VUnet ID. A valid VUnet ID consists of 3 letters followed by 3 digits. The letters in the VUnet ID can be written as lower case letters as well as upper case letters.
Examples of valid VUnet IDs are 'ABC123', 'def456', and 'Ghi789'. An example of an invalid VUnet ID is 'ab123c'.
Define functions to structure your program. That is what this assignment is all about!
Hints:
Note: Use only basic coding like vector and so one. Do not use any complicated codes.As well explain evey step.
Correct executions of the program are shown below :
Please enter a vunet id: tKn200 The vunet id tKn200 is valid Please enter a vunet id: tkn2000 error: size incorrect (is 7, should be 6) Please enter a vunet id: ab22cc error: letter expected at position 3 Please enter a vunet id: abcdef error: digit expected at position 4
#include <iostream>
using namespace std;
int main()
{
string s;
cout<<"Please enter a vunet id: ";
cin>>s;
int co=0;
int si=s.size();
if(s.size()==6)
{
while(si>0){
if(co<3){
if( (s.at(co)>='A' && s.at(co)<='Z' ) ||
(s.at(co)>='a' && s.at(co)<='z' ))
co++;
else{
cout<<"error: letter expected at position
"<<co+1;
return 0;
}
}
else
{
if( s.at(co)>='0' && s.at(co)<='9' )
co++;
else{
cout<<"error: letter expected at position
"<<co+1;
return 0 ;
}
}
si--;
}
}
else{
cout<<"error: size incorrect (is "<<
s.size()<<",should be 6)";
return 0;
}
cout<<"The vunet id"<< s <<" is valid";
return 0;
}