Monash University >
CSSE >
CSE1303 >
Part A >
Tutorials > Tutorial A1
CSE1303 Computer Science
Summer Semester, 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 StudentRec
{
char name[MAXNAME];
int mark;
};
typedef struct StudentRec Student;
- Write a C function void sort(Student class[], int size) which takes an array of
structures of type Student and an integer, size, which
is the size of the array; and sorts the array into alphabetical order
according to the names of the students.
- Write a C function void printclass(Student class[], char* filename, int size) to
print that array to a file called classlist.txt.
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?
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 02 December 2003 22:29:33