This is the end of the preview. Sign up
to
access the rest of the document.

Unformatted text preview: CSE 2031 Page 1 of 3 LAB TEST 1 Complete and submit the following two programs. Each is worth 50% of the total grade. Problem A A.1 Specification A palindrome is a word or string that can be read the same way forward and backward. A few examples are “mom”, “dad”, “ABBA”, “123454321”, “abc-cba”, “/* y-arra-y */”, etc. Write a C program that contains two functions, one to input a non‐empty string and the other to determine whether the input line of characters is a palindrome. A.2 Implementation The program is named palin.c. Use the given template palin.c and fill in your code. The first function to be implemented is myStrInput(). See file palin.c for its specification. Use getchar and a loop to read a line of characters, and store the input characters into the array. The loop terminates when a new line character ‘\n’ is entered. The new line character ‘\n’ is NOT part of the line (i.e., discard the new line character ‘\n’). The second function to be implemented is palindrome(). See file palin.c for its specification. The function returns 1 if the string passed to the function is a palindrome, and returns 0 otherwise. The palindrome property is case‐insensitive. That is “Dad” is a palindrome, like “dad”. In both functions, do not use array indexing such as s[i]. Use only pointers and address arithmetic to manipulate the array elements. If you use array indexing in your code, your program will not be marked and given zero point. A.3 Sample Inputs/Outputs indigo 352 % test1a mom YES indigo 353 % test1a Welcome NO indigo 354 % test1a CSE 2031 Page 2 of 3 Dad YES indigo 355 % test1a =abcd DCBA= YES indigo 356 % test1a Problem B B.1 Specification Write a C program that contains two functions, one to input a string in the form of a floating point number and the other to convert the string into an actual floating‐point number. B.2 Implementation The program is named convert.c. Use the given template convert.c and fill in your code. The first function to be implemented is myStrInput(). See file convert.c for its specification. Use getchar and a loop to read a line of characters, and store the input characters into the array. The loop terminates when a new line character ‘\n’ is entered. The new line character ‘\n’ is NOT part of the line (i.e., discard the new line character ‘\n’). The input line contains only characters ‘0’ to ‘9’, the dot character ‘.’ and the plus or minus sign in the form of a valid positive floating point number of the following format: [+/‐][integer part] . [fractional part] The plus or minus sign [+/‐] is optional. The integer and fractional parts are required in the input. Assume that the input line of characters represents a valid floating point number of the form: [+/‐] [integer part] . [fractional part] The second function to be implemented is str2float(). See file convert.c for its specification. The function converts the string passed to the function to a double floating‐point number and returns the floating‐point number to the caller. For this problem, you may use either array indexing or pointers or both in your code. B.3 Sample Inputs/Outputs indigo 360 % test1b CSE 2031 Page 3 of 3 24.5 24.500000 indigo 361 % test1b -76.24 -76.240000 indigo 362 % test1b 100.0 100.000000 indigo 363 % test1b +0.255 0.255000 indigo 364 % test1b -12.9999999999 -13.000000 indigo 365 % test1b +1.00000000099 1.000000 indigo 366 % test1b C. Common Notes Complete the header in each submitted file with your student and contact information. Do not modify the function definitions or the main() functions in the submitted files. Assume that all inputs are valid. No error checking is required on inputs. ...
View Full
Document