Exercises - Week 3
Today's exercise is used the evaluate your actual learning level, and it will NOT considered for the final exam.
At the end of Lab hours you have to send an email to paolo.falcarin@polito.it with subject:
"[AP] id lastname firstname", and attached your C code.
In case you are not able to start today's exercise, you can complete and send
the exercises of Week 2 or the ones of Week 1.
1. Arrays
Given an array of int variables of predefined SIZE, realize a funtion invert() that invert the order of the array, e.g.:
if input array int v[6] = {1,2,5,9,0,4} then invert(v) will return {4,0,9,5,2,1}.
Do the same for an array of chars and for an array of predefined strings.
2.Dates and Strings
Write a program with some simple functions:
2a - A function converting an unsigned int variable into an array of 5 char, passed as parameter
2.b - A funtion that calculate the number of days between 2 dates
2.c - A function that convert a string in an int number
3. Phone Book
Read a text file containing contacts information and create a data
structure in memory.
You can choose to set a maximum size of the phonebook (to use arrays) or no size limits (to use a linked list).
Define functions for:
1. adding a contact to the existing structure in memory;
2. deleting a contact from memory given its number;
3. print on screen the current list of contacts;
4. reading the data structure from a file and create it in
memory.
5. saving the current phonebook with the same structure in another file.
6. sorting contacts by surname and name (if surnames are the same then compare names), with whichever sorting algorithm;
Each contact is one line of the input file and it contains data (phone
name surname email) of a contact separated by a blank (space):
34611111 Homer Simpson homer.simpson@springfield.org
123450099 Peter Griffin family.guy@fox.tv
333333325 Mickey Mouse mickey@disneyland.com
6666111 Eric Cartman eric.cartman@southpark.com
4. Sorting algorithms
Implement the code of insertion sort, bubble sort, counting sort , merge sort as seen during lesson.
-------------------------------------------
Note1: See C language C recap slides or the "C language
tutorial" for functions on files.
Note2: use the most recent C-99 standard on gcc compiler by
setting the command line parameter: -std=c99
Note3: use "int strcmp(char *s1, char *s2)" - in library string.h
- to compare 2 strings: it returns 0 if equals, a number <0 if
s1 <s2, a number >0 if s1>s2.