You are on page 1of 2

Q1: Use some of the C string library to develop a program that prints a one- month list of

daily reminders. The user will enter a series of reminders, with each prefixed by a day of the
month. When the user enters 0 instead of a valid day, the program will print a list of all
reminders entered, sorted by day. Here’s what a session with the program will look like:

Enter day and reminder: 24 Susan’s birthday


Enter day and reminder: 5 6:00 – Dinner with Marge and Russ
Enter day and reminder: 26 Movie – “Chinatown”
Enter day and reminder: 7 10:30 – Dental appointment
Enter day and reminder: 12 Movie – “Dazed and Confused”
Enter day and reminder: 5 Saturday class
Enter day and reminder: 12 Saturday class
Enter day and reminder: 0

The output should look like the following:

Day Reminder
5 Saturday class
5 6:00 – Dinner with Merge and Russ
7 10:30 – Dental appointment
12 Saturday class
12 Movie – “Dazad and Confused”
24 Susan’s birthday
26 Movie – “Chinatown”

The program should read a series of day-and-reminder combinations as a string, storing them in
order (sorted by day), and then display them. Store the strings in a two-dimensional array of
characters, with each row of the array containing one string. After the program read a day and its
associated reminder, it will search the array to determine where the day belongs, using strcmp to
do comparison. It will then use strcpy to move all strings below that point down one position.
Finally, the program will copy the day into the array and call strcat to append the reminder to
day. (The day and the reminder have been kept separate up to this point.)
In the program output, the days should be right-justified in a two-character field, so that
their ones digits will line up. Also, make sure that the user doesn’t enter more than two
digits.

Q2: Improve the program of Q1 in the following ways:


(a) Have the program print an error message and ignore a reminder if the
corresponding day is negative or larger than 31.
(b) Allow the user to enter a day, a 24-hour time, and a reminder. The printed
reminder list should be sorted first by day, then by time. (The program of Q1
allows the user to enter a time, but it’s treated as part of the reminder.)
(c) Have the program print a one-year reminder list. Require the user to enter days in
the form month/day.
Q3: Write the following functions:

1- bool test_extension (const char *file_name, const char *extension);


where file_name points to a string containing a file name. The function should return true if
the file’s extension matches the string pointed to by extension, ignoring the case of letters.
For example, the call test_extension (“memo.txt”, “TXT”) would return true.

2- void remove_filename(char *url);

where url points to a string containing a URL (Uniform Resource Locator) that ends with a
file name (such as “http://www.lakeheadu.com/index.html”). The function should modify
the string by removing the file name and the preceding slash. (In this example, the result
will be “ http://www.lakeheadu.com”.) Hint: Have the function replace the last slash in the
string by a null character.

3- void build_index_url(const char *domain, char *index_url);

where domain points to a string containing an Internet domain, such as “lakeheadu.com”.


The function should add http://www. to the beginning of this string and “/index.html” to
the end of the string, storing the result in the string pointed to by index_url. (In this
example, the result will be http://www.lakeheadu.com/index.html.) You may assume that
index_url points to a variable that is long enough to hold the resulting string. Keep the
function as simple as possible by having it use the strcat and strcpy functions. Write a main
method to test the function. Write a main method to test the three functions.

Q4: Write a program that finds the “smallest” and “largest” in a series of words. After the
user enters the words, the program will determine which words would come first and last if
the words were listed in dictionary order. The program must stop accepting input when the
user enters a four-letter word. Assume that no word is more than 20 letters long. An
interactive session with the program might look like this:
Enter word: dog
Enter word: zebra
Enter word: rabbit
Enter word: catfish
Enter word: walrus
Enter word: cat
Enter word: fish

Smallest word: cat


Largest word: zebra

Q5: Write a program that accepts a date from the user in the form mm/dd/yyyy and then
displays it in the form month dd, yyyy, For example:
Enter a date (mm/dd/yyyy) : 2/17/2011
You entered the date February 17, 2011
Store the month names in an array that contains pointers to strings.

You might also like