Assignment 1

Due: 4:00 PM on Wednesday, February 9, 2000


Question #1

Write a C program bitplay.c that accepts up to 10 integers from a user, stores these numbers in an int array, extracts the first 8 bits from each stored integer, interprets these 8-bit chunks as characters, and prints the resulting string. Input of numbers is terminated either by entering 10 numbers or by entering -1 (see sample output below). For example, given the input numbers 65, 66, 67, and 68, the resulting string is "ABCD".

Your program's output must have the following format:


Question #2

Write a C program pattern.c that accepts a string of non-blank characters from the user and determines if the following pattern occurs within that string: Examples of this pattern are acd, abbcd, and abccd. Sample strings including this pattern are Your program's output must have the following format:

Question #3

Write a C program stack.c that implements a module for the integer stack abstract data type as an int array of length MAX_STACK_DEPTH, where MAX_STACK_DEPTH is a constant (for the purposes of this assignment, MAX_STACK_DEPTH will be set to 3). All associated stack variables will be stored in a struct-record type called stack. This module should have the following functions: The last two functions access an operation status variable associated with a stack. This variable can have three values: Attempts to push an element on a full stack cause the operation status to be set to 2; attempts to pop or read the top element of an empty stack cause the operation status to be set to 1; all other operations cause the operation status to be set to 0. For printing error messages, you may also find it useful to store a code indicating the most recently requested operation, e.g., Finally, write a main function that takes stack-manipulation commands from a user (see sample output below for command format), performs these commands using the functions in the module described above, and displays the results. Your program will initialize the stack before processing the first of these commands. The list of commands is terminated by the command end.

Your program's output must have the following format:


Additional Notes:


This page is adapted from that for CS3710 (Winter 1999) created by Mike Rendell.


Created: January 18, 2000
Last Modified: February 7, 2000