CSCI 1120 (Low-Level Computing), Fall 2021:
Homework 5

Credit:
10 points.

Reading

Be sure you have read, or at least skimmed, the assigned readings for classes through 9/22.

Programming Problems

Do the following programming problems. You will end up with at least one code file per problem. Submit your program source (and any other needed files) one of two ways:

You can develop your programs on any system that provides the needed functionality, but I will test them on one of the department's Linux machines, so you should probably make sure they work in that environment before turning them in.

  1. (10 points) Write a C program that prompts the user for a single line of text and prints whether it is a palindrome, i.e., whether it's “the same” backwards as forwards, according to the following rules: The program should also print an error message if the text supplied by the user doesn't fit into the array you use to represent the input string.

    Here are some sample executions:

    [bmassing@dias04]$ ./palindrome
    enter a line of text:
    abcd dcba
    input 'abcd dcba'
    a palindrome
    
    [bmassing@dias04]$ ./palindrome
    A man, a plan, a canal -- Panama!
    input 'A man, a plan, a canal -- Panama!'
    a palindrome
    
    [bmassing@dias04]$ ./palindrome
    enter a line of text:
    abcd 12 bcda
    input 'abcd 12 dcba'
    not a palindrome
    
    [bmassing@dias04]$ ./palindrome
    enter a line of text:
    abcd 1221 dcba
    input 'abcd 1221 dcba'
    a palindrome
    

    In Scala you might solve this problem by doing something that involves copying the string, or parts of it. I encourage you not to solve it that way in C: I think it's simpler and more C-idiomatic just to work with the string in place without changing it. One way to do this uses one index or pointer that starts at the beginning of the string and moves right and another that starts at the end and moves left.

    You will get extra credit (up to 2 points) for solutions that do not involve copying.

    Hints:

Essay and pledge

Include with your assignment the following information.

For programming assignments, please put it a separate file. (I strongly prefer plain text, but if you insist you can put it in a PDF -- just no word-processor documents or Google Drive links please.) For written assignments, please put it in your main document.

Pledge

This should include the Honor Code pledge, or just the word “pledged”, plus at least one of the following about collaboration and help (as many as apply). Text in italics is explanatory or something for you to fill in; you don't need to repeat it!

Essay

This should be a brief essay (a sentence or two is fine, though you can write as much as you like) telling me what if anything you think you learned from the assignment, and what if anything you found interesting, difficult, or otherwise noteworthy.




2021-09-28