var inputString: string var copy: string put "Enter a string. " .. get inputString copy := inputString put "Original string is ", "\"", inputString, "\"" put "Copied string is ", "\"", copy, "\""
Try running this program with various input.
var inputString: string var copy: string put "Enter a string. " ... get inputString for i: 1 .. length(inputString) copy := copy + inputString(i) end for put "Original string is ", "\"", inputString, "\"" put "Copied string is ", "\"", copy, "\""
The program given here contains two errors. Correct these and then test the program to make sure its input/output behavior is the same as that of the first program.
for i: 1 .. length(inputString) if inputString(i) not= " " then copy := copy + inputString(i) end if end for
A run of this program should then look something like this:
Enter a string. "Here is a test string." Original string is "Here is a test string." Copied string is "Hereisateststring."
Try writing different versions of this program to do the following:
Enter a string. "Alaska is large." Original string is "Alaska is large." Copied string is "AlAskA is lArge."
Enter a string. "Here is a test string." Original string is "Here is a test string." Copied string is ".gnirts tset a si ereH."
Enter a string. "Here is a test string." Original string is "Here is a test string." Copied string is "Her isatng."
Enter a string. "Here is a test string." Original string is "Here is a test string." Copied string is "HERE IS A TEST STRING."