CS 010 - Introduction to Computer Science I
Assignment 2: Character Count

DUE: Friday, January 30 before 11:00pm


Collaboration Policy

This programming assignment is designed in part for us to determine how well you are able to program. Thus, every part of the program should be your own original work, and should not be substantially similar to other students' code, as well code from books, previous solutions, the web, etc. Like other skills (e.g., surgery), the only way to really learn programming is to do it yourself. Some collaboration is O.K., including discussing the general solution method, and some debugging assistance after a student has tried hard to solve the bug him/herself. We DO encourage you to work with others nearby, so if you get stuck, you can get help. But, you should not show your code to another student in order to help that student. For this assignment, copying code from another source (e.g., copy-and-paste, reading off of another's monitor, etc.) is not considered appropriate collaboration and will have severe consequences.


Turn in online to the appropriate folder for your lab section (e.g., as2_25 for students enrolled in lab section 25). Your assignment may not get graded if it gets turned into the wrong section.

Remember to add your name, login, SID (last 4 digits), lecture and lab section numbers, and email address, to the header of your program


Problem Definition:

Write a program that counts the number of a particular character found in a sentence entered by the user. The program should ask the user for a character (letter, single digit number, comma, or any other character commonly found in English sentences). Then the program should ask the user to input a sentence, ending it with a period or a question mark ('.' or '?'). When your program reads in a period or question mark, it should output a message telling the user how many times the character was found in the sentence.

The following are 2 different sample outputs to help you design your program. User input is bold.

Sample 1:

    Enter a character:
    g

    Enter a sentence followed by a period or question mark (. or ?):
    Can I use the lab machines to program my home programming assignments?

    Your sentence contained 4 g character(s).

Sample 2:

    Enter a character:
    x

    Enter a sentence followed by a period or question mark (. or ?):
    Lab machines are available 24 hours a day, 7 days a week except during scheduled lab sections.

    Your sentence contained 1 x character(s).