/*********************** 05-4-S.TXT ************************** *********** Prof. Dr. B. Bartning ***************************/ Hints to solve the exercise 05-4.CPP ------------------------------------ (a) Try to understand the program! -> Self! How does the program terminate converting the string? Does the null character have an effect? -> The program terminates with each character unequal decimal digit/space, so e. g. with a letter, point, or also null byte. (b) Input also (e. g.) the numbers 2 thousand million, 3 th.m., 4 th.m., 5 th.m. (digit + 9 zeros!). Effect? Why? -> 2 th.m. : possible 3 th.m., 4 th.m.: negative value ) because of range overflow, 5 th.m.: different positive value ) see (3.21.b) and (1.44) (c) What does the program output if there is at least one space before a number without sign? -> permissible What does happen if there is a number with sign AFTER one or several spaces? -> not allowed because after space(s) loop with check on decimal digits/space Alteration: an arbitrary number of leading spaces BEFORE an optional sign is to be allowed (within max chacters). -> Insert the following lines directly after "i = 0;" while (line[i]==' ') ++i; (d) Use a constant definition const ....; instead of the preprocessor directive for max. -> instaed of the line "#define max 80" the following definition: "const int max=80;" (e) What does the program output when encountering an empty string (i. e. only pressing the enter key)? -> value zero (program termination because of zero byte) ADDITIONAL EXERCISE: Alteration: If encountering an empty string, the program is to output a defined value (instead of the above behavior). It should be possible to alter this value very conveniently (in the program code), therefore defining this value should be done with a constant definition. -> Many possibilities, for example: insert constant definition (e. g. before "main"): const int valEmpty=-1492; // ... or another value insert directly after the line "cin.getline(..);": if (line[0]=='\0') { sign = 1; // necessary because output of "sign*value" value = valEmpty; } else { // and here insert the complete following program text // up to excluding the output "cout << ..." } ****************************************************