Docsity

Practice Problem Set 1 - Software Practice | CS 3500, Assignments of Computer Science

Toggle sidebar
bg1
University of Utah
School of Computing
CS 3500/5010 Handout 2 August 28, 2009
Problem Set One
This problem set is due on Thursday, September 3 at 11:59 p.m. via electronic handin. No submissions
will be accepted after I disable handin sometime on the morning of Friday, September 4. Anything that
is handed in before I disable handin will be considered on time.
You are to create a zip file as detailed later and submit it with the command
handin cs3500 ps1 ps1.zip
from any CADE Lab computer. Alternatively, you can use web-based handin at
http://cgi.eng.utah.edu/webhandin
Problem
Afilter is a command-line program that reads lines of text from its standard input stream, processes
them in some way, and then writes lines of text to its standard output stream. Typically, a filter doesn’t
wait until it has read all of its input before it begins writing output; it begins producing output as soon
as possible.
In this assignment you will be getting used to Visual Studio and C++ by creating a single solution
(called PS1) that consists of three projects, each of which is a filter. The three filters are:
•LowerCase, which reads words from its standard input stream, converts them into lower case, and
writes the new words (one per line) to its standard output stream. When converting a word to
lower case, upper case letters should be replaced with the corresponding lower case letters. All
other characters should remain unmodified.
•Palindrome, which reads words from its standard input stream and determines whether or not
they are palindromes (identical when reversed). All words that are palindromes are written to the
standard output stream (one per line). Other words are discarded.
pf3
pf4

Partial preview of the text

Download Practice Problem Set 1 - Software Practice | CS 3500 and more Assignments Computer Science in PDF only on Docsity!

University of Utah

School of Computing

CS 3500/5010 Handout 2 August 28, 2009

Problem Set One

This problem set is due on Thursday, September 3 at 11:59 p.m. via electronic handin. No submissions will be accepted after I disable handin sometime on the morning of Friday, September 4. Anything that is handed in before I disable handin will be considered on time.

You are to create a zip file as detailed later and submit it with the command

handin cs3500 ps1 ps1.zip

from any CADE Lab computer. Alternatively, you can use web-based handin at

http://cgi.eng.utah.edu/webhandin

Problem

A filter is a command-line program that reads lines of text from its standard input stream, processes them in some way, and then writes lines of text to its standard output stream. Typically, a filter doesn’t wait until it has read all of its input before it begins writing output; it begins producing output as soon as possible.

In this assignment you will be getting used to Visual Studio and C++ by creating a single solution (called PS1) that consists of three projects, each of which is a filter. The three filters are:

  • LowerCase, which reads words from its standard input stream, converts them into lower case, and writes the new words (one per line) to its standard output stream. When converting a word to lower case, upper case letters should be replaced with the corresponding lower case letters. All other characters should remain unmodified.
  • Palindrome, which reads words from its standard input stream and determines whether or not they are palindromes (identical when reversed). All words that are palindromes are written to the standard output stream (one per line). Other words are discarded.
  • Format, which expects a positive integer n as a command line parameter. It reads words from its standard input stream and writes the words to its standard output stream (n per line). Each pair of adjacent words on a line should be separated by a single space.

For the purposes of this assignment, a word is a sequence of non white space characters delimited by white space.

Getting Started

As a starting point, I am giving you a solution called PS1 that contains the completed project Format. It is linked as ps1-skeleton.zip from the calendar on the class web page. To get started, unzip it into the directory of your choice and double click on the .sln file that it contains. That will bring up Visual Studio so you can work on the solution.

Implementation Hints

You should study Format to see how a filter can read and write words from and to standard input and standard output. You should then implement and test the projects LowerCase and Palindrome.

Here are a few hints beyond those you can glean from studying Format:

  • C++ string objects are vectors of characters. (Just as in Java, the character type is char. Java chars are two bytes; C++ chars are one byte.)
  • If s is a string, then s.length() is the length of the string and s[i] is character i of the string.
  • The function tolower, declared in ctype.h, takes a character as its parameter and returns the lower case equivalent. For example, tolower(’G’) returns ’g’ and tolower(’7’) returns ’7’.

Running in Visual Studio

To run one of the filters from Visual Studio, first make sure that the desired project is the default project. To do this, right click on the project name and select “Set as StartUp Project”. Then press the F5 key. A terminal window will appear.

Whatever you type into this window will be passed to the filter via its standard input stream, and whatever the filter writes to its standard output stream will appear in the terminal window. To end an interaction, enter CTRL-Z (the DOS end-of-file character).

Running Format requires an extra step because it requires a command line parameter. Right click Format, choose Properties, and then choose Debugging under Configuration Properties. Enter the desired command line parameter on the line labeled Command Arguments.

Running from a Terminal Window

Visual Studio is a development environment. Ultimately, you need to be able to run your three programs independently of VS.

To do this, open a terminal window and navigate to the folder that contains your three executables. You can run the one of your choice by entering one of these commands into the terminal:

Handing In

When you’re ready to hand in your solution, under the Build menu choose Clean Solution, which will delete temporary files. Exit Visual Studio. Use Windows Explorer to navigate to the directory in which you solution resides.

It will be very helpful if you’ll delete some unnecessary files before zipping up your work. Find and delete your .ncb file (but not your .sln file). You can also delete your Debug and Release folders.

Zip your solution into a file called ps1.zip by right clicking on the root folder of your solution and choosing “Send to Compressed Folder” or something similar. Your zip file should be a few kilobytes. If it’s anywhere near a megabyte you’ve left in some unneeded files.

We should be able to unzip all of your files into a directory, double click on your .sln file, and build the project without any errors.

You should be able to do this also! Try it before you hand it in!

You should be able to do this also! Try it before you hand it in!

You should be able to do this also! Try it before you hand it in!

You should be able to do this also! Try it before you hand it in!