Monash University >
CSSE >
CSE1303 >
Part A >
Tutorials > Tutorial A1
CSE1303 Computer Science
Semester 2, 2003
Part A
Tutorial A1 : Revision
This tute covers material from lectures A01 to A02.
There may not be time in the tutorial to cover all of these
questions. Attempt at least the ones marked with an asterisk
before the tutorial; these are the ones that will be
focussed on during the class. If you have specific
questions about unmarked questions, you can ask the tutor about them
during the tutorial. If you want further revision questions, suggestions of
questions from the textbooks are provided at the end of the tutorial sheet.
Note: The purpose of tutorials is not simply to give you the answers to
these questions! (Solutions will be released in about a week online,
so if all you want is the answers, there are easier ways.)
Exercise 1
Describe the contents of array a after the following code is executed.
* Exercise 2
- Write a C function
which is given a positive number of seconds, and returns the
equivalent hours, minutes and seconds. The values of the minutes and
seconds returned must be non negative and less than 60.
- Write a main function in C which implements a menu that prompts the user to chose
to enter a positive number of seconds or exit the program.
* Exercise 3
Write fragments of C code showing how you might use the string
library functions strcmp(),
strcpy() and strlen().
Exercise 4
Write a C function void reverse(char* s) which reverses the order of the
characters in the character string s, and does not call any
function from the string library.
Exercise 5
* Exercise 6
Given the following C code.
#include <string.h>
#define MAXNAME 80
struct CDRec
{
char title[MAXNAME];
float price;
};
typedef struct CDRec CD;
- Write a C function void sort(CD collection[], int size) which takes an array of
structures of type CD and an integer, size, which
is the size of the array; and sorts the array into alphabetical order
according to the titles of the CDs.
- Write a C function void printCollection(CD collection[], int size) to
print the contents of that array to a file called collection.txt.
- Write a C function void sumPrice(CD collection[], int size)
to add up the prices of the CDs in the array and print them to the screen.
Exercise 7
The following function strcmp(s, t), compares two character strings s
and t, and returns a negative value, zero, or a positive value
if s is lexicographically less than, equal to, greater than t,
respectively. Write a pointer version of this function, which doesn't
use a variable of type int.
Exercise 8
-
What is the difference between an array of characters and a string?
- Can you use the functions contained in <string.h>
to manipulate arrays of characters (not strings)? Why or why not?
- What will the following line print if list is an
array of characters (not a string)?
- Given the following lines of C code:
And the input "Unfinished Tales", what will happen to the
variable word and the memory around that variable?
* Exercise 9
Write a C function void allcaps(char* s) which capitalises all of the
characters in the character string s, and does not call any
function from the string library or the functions toupper()
and tolower().
Note: this type of question will not be asked in the exam unless a copy of the ascii table is provided.
Hints:
The ascii value of 'A' is 65
The ascii value of 'a' is 97
Exercise 10
Write a C function int strlen which takes a string
s and returns the length of that string. You are
not allowed to use any function in <string.h>.
ADDITIONAL EXERCISES
Deitel & Deitel, Chapter 5
Self-Review Exercises: 5.1 (a to p), 5.2, 5.3, 5.5, 5.7 (a, b, d and e),
Exercises: 5.8, 5.9, 5.10, 5.11, 5.15, 5.16, 5.17, 5.18, 5.19, 5.20, 5.21
Deitel & Deitel, Chapter 7
Self-Review Exercises: 7.1, 7.4, 7.5(a)
Exercises: 7.10
Deitel & Deitel, Chapter 8 (2e)
Self-Review Exercises: 8.1 (a , b, e, f, h, i, o, q, t)
Exercises: 8.9, 8.22, 8.23, 8.24, 8.25
[ Top | Home ]
Last modified: Tuesday 29 July 2003 14:32:14