HW #8 - Fun With Strings

Due Monday March 26 at 3:30 PM

This assignment is designed to cover software engineering skills in addition to pointers and arrays. You are given a header file containing function prototypes and descriptions. (Short versions are below.) Your job is to produce the file "strfun.cpp", which implements the functions. You have some degree of freedom in deciding how to implement them, and you may write additional functions if you think it will help you (although I don’t think it will be necessary), but you may not change the behavior or the prototypes of the functions, or the name of the file. If you do, your piece will not fit properly into the rest of the project (in this case, my driver program).

The driver program and the header file are available for download on the web. (Notice that the names they have on the server are different from the names they're supposed to actually have; this was so I would know where they belonged on the server. Rename the header file as strfun.h (you should be fine with the driver program keeping its current name). Read the header file before coding the functions, as it describes the desired behavior. Notice that these functions are included in the namespace m330. I may change the driver program slightly before running your programs, but it will generally be the same.

// length finds the length of s
int length(const char * s);

// strpos returns the index of the first occurrence of b in s
int strpos(const char * s, char b);

// revstr returns the string s, reversed
void revstr(char * s);

// strrpos returns the position of the last occurrence of c in s
int strrpos(const char * s, char c);

// substr returns the substring from positions a through b
void substr(char * s, int a, int b);

// trim removes whitespace from the beginning and end of s
void trim(char * s);
 
// ucwords capitalizes the first character of each word in s
void ucwords(char * s);

You may use the assert and cctype libraries. You may not use any functionality of any string library.

A design document is required for this assignment; however, sample output is not. (I'll run your programs since part of the assignment is making them fit into my driver program properly.)


Back to Main Page