In: Computer Science
Using the windows32 framework, write a procedure to
read a string and
shift each character of the string by one. As an example, if your
input string is Abcz,
your output should be Bcda. Note that you must test your string for
non-alphabetic
characters (such as numbers and special characters). If there are
non-alphabetic characters, you should terminate your program with
an appropriate message. You should
display your converted string using the output macro.
Hint: Let your procedure returns an empty string, if the parameter
is not valid. Then
depending on the return value, print an appropriate message in your
main procedure.
Using Assembly language windows 32 framework
Given a string S of only small English letters. We need to transform the string by making some number of moves (any number of times) to get the string “abcdefghijklmnopqrstuvwxyz” as a subsequence in that string. In one move, you can replace any character of the string to next character in alphabetical order i.e. ‘a’ can be replaced by ‘b’, ‘b’ can be replaced by ‘c’ and so on. Letter ‘z’ cannot be replaced by any character. If it is not possible to get the subsequence out of that string, then print “Not Possible”.
Examples:
Input : aaaaaaaaaaaaaaaaaaaaaaaaaa Output : abcdefghijklmnopqrstuvwxyz Explanation: Second occurrence of letter 'a' will be replaced by 'b', third occurrence of letter 'a' will be first replaced by 'b' and then by 'c' and so on.
using
namespace
std;
// function to transform string with string
// passed as reference
bool
transformString(string&
s)
{
// initializing the
variable ch to 'a'
char
ch
=
'a'
;
// if the length of
string is less than
// 26, we can't
obtain the required
//
subsequence
if
(s.size() < 26)
return
false
;
for
(
int
i = 0; i < s.size(); i++)
{
//
if ch has reached 'z', it means we have
//
transformed our string such that required
//
subsequence can be obtained
if
(
int
(ch) >
int
(
'z'
))
break
;
//
current character is not greater than ch,
//
then replace it with ch and increment ch
if
(s[i] <= ch) {
s[i]
= ch;
ch
=
char
(
int
(ch)
+ 1);
}
}
if
(ch
<=
'z'
)
return
false
;
return
true
;
}
// Driver Code
int
main()
{
string str =
"aaaaaaaaaaaaaaaaaaaaaaaaaa"
;
if
(transformString(str))
cout
<< str << endl;
else
cout
<<
"Not Possible"
<<
endl;
return
0;
}