Question

In: Computer Science

Write a program that can check whether or not some string is a valid VUnet ID....

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:

  • you can get a character from a string by using the member function at:
    • std::string s; std::cin >> s; std::cout << s.at(0);
  • you can convert an int to a string like this:
    • std::string s = std::to_string(42);

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

Solutions

Expert Solution

#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;
}


Related Solutions

Write a Java method to check whether a string is a valid password. Password rules: A...
Write a Java method to check whether a string is a valid password. Password rules: A password must have at least ten characters. A password consists of only letters and digits. A password must contain at least two digits. There are at least SIX functions/methods as the following: 1. menu() – to print the password’s rules. 2. getString() – to get the password from the user. 3. isPassword() – to check either the password is valid based on the given...
(10 marks) Write a function to check whether string s1 is a substring of string s2....
Write a function to check whether string s1 is a substring of string s2. The function returns the first index in s2 if there is a match. Otherwise, return -1. For example, the function should return 2 if s1 is "to" and s2 is "October". If s1 is "andy" and s2 is "candy", then the function should return 1. The function prototype is as follows: int indexOf(const char *s1, const char *s2).
Write a program that determines whether an input string is a palindrome; that is, whether it...
Write a program that determines whether an input string is a palindrome; that is, whether it can be read the same way forward and backward. At each point, you can read only one character of the input string; do not use an array to first store this string and then analyze it (except, possibly, in a stack implementation). Consider using multiple stacks. In Pseudocode please
Write a program to check given expression is valid or not.The expression consists of paranthsis like  [{(...
Write a program to check given expression is valid or not.The expression consists of paranthsis like  [{( if valid then convert into postfix expression and after conversion then evaluate postfix expession(using stack) and do not use build in stack. Use the c++ laguage.
2. Write a Java program to read a string (a password)from the user and then   check...
2. Write a Java program to read a string (a password)from the user and then   check that the password conforms to the corporate password policy.   The policy is:   1) the password must be at least 8 characters   2) the password must contain at least two upper case letters   3) the password must contain at least one digit   4) the password cannot begin with a digit   Use a for loop to step through the string.   Output “Password OK” if the password...
Using python: Given a string x, write a program to check if its first character is...
Using python: Given a string x, write a program to check if its first character is the same as its last character. If yes, the code should output "True"
Write a program that inputs a string that represents a binary number. The string can contain...
Write a program that inputs a string that represents a binary number. The string can contain only 0s and 1s and no other characters, not even spaces. Validate that the entered number meets these requirements. If it does not, display an error message. If it is a valid binary number, determine the number of 1s that it contains. If it has exactly two 1s, display "Accepted". Otherwise, display "Rejected". All input and output should be from the console. Examples of...
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
Write a program in JAVA using the BigInteger library that can be used to check a...
Write a program in JAVA using the BigInteger library that can be used to check a RSA signature, based on the signer's RSA public key pair. To test your program, take the following information about a message Alice signed and use the verify signature to reproduce the message Alice signed and convert it back to String format. n = 68236588817658935156357212288430888402056854883696767622850112840388111129987 e = 65537 signature = 46612763171375975923246342580942010388414761162366281695045830390867474569531
(Use the string class to solve the problem) Write a program (in c++) that can be...
(Use the string class to solve the problem) Write a program (in c++) that can be used to train the user to use less sexist language by suggesting alternative versions of sentences given by the user. The program will ask for a sentence, read the sentence into a string variable, and replace all occurrences of masculine pronouns with gender-neutral pronouns. For example, it will replace “he” with “she or he”, and “him” with “her or him”. Be sure to preserve...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT