CS1101C Practical Exam
Session 4 (1600 - 1745 hours)
Poke
The name of your C program file must be called poke.c, files
with any other name will not be marked.
The deadline for this lab is Wednesday 14 November 2007, 17:45:59
hours. Strictly no submissions will be accepted after the
deadline.
Background
Facebook, the social networking website, is rapidly growing in
popularity. In Facebook, people can poke each other.
Pokes
Each person can only poke one person (including himself) at a time. For
each poke action, there is a sender and a receiver. It is also possible
to poke oneself.
Text File
The list of poke actions are stored in a sample text file called
“poke.txt” which has been copied into your directory by the
pesetup command. Each line in the text file consists of a
single poke action. Each person is indicated by a person number. There
are exactly 20 persons, and each person is numbered from Person #1 to
Person #20 inclusive.
The contents of the sample text file is shown below:
2 3
5 7
10 10
9 15
10 10
10 10
8 15
10 10
5 15
10 10
20 17
2 4
The first line in the text file indicates that Person #2 pokes Person
#3. The second line indicates that Person #5 pokes Person #7. The third
line is a self-poke, as Person #10 pokes himself / herself. You may
assume that there is at least one line in the text file, and all
integers in the text file are valid. The number of lines in the text
file are unknown.
Task
We wish to find out who are the most popular people (maximum number of
pokes received by people other than yourself; do not count self-pokes),
the people with the most free time on their hands (maximum number of
pokes sent to people other than yourself; do not count self-pokes), and
the people who are the most self-obsessed (the maximum number of
self-pokes).
After reading the list of pokes from the text file, print a list of
statistics which contain the following information:
- The maximum number of pokes received, excluding self-pokes.
- The list of persons who received this maximum number of pokes.
- The maximum number of pokes sent, excluding self-pokes.
- The list of persons who sent this maximum number of pokes.
- The maximum number of self-pokes.
- The list of persons who are the most self-obsessed.
Sample Output
The following is the sample output using the above sample file. Remember that
we will test your program with other input files. Do not print the lines
“Begin Sample Output” and
“End Sample Output”.
===== Begin Sample Output =====
Person #2 pokes Person #3.
Person #5 pokes Person #7.
Person #10 pokes Person #10.
Person #9 pokes Person #15.
Person #10 pokes Person #10.
Person #10 pokes Person #10.
Person #8 pokes Person #15.
Person #10 pokes Person #10.
Person #5 pokes Person #15.
Person #10 pokes Person #10.
Person #20 pokes Person #17.
Person #2 pokes Person #4.
Maximum number of pokes received by a person: 3
List of persons who received maximum pokes:
Person #15
Maximum number of pokes sent by a person: 2
List of persons who sent maximum pokes:
Person #2
Person #5
Maximum number of self-pokes by a person: 5
List of persons with maximum self-pokes:
Person #10
===== End Sample Output =====
You are reminded to follow the sample output exactly; else marks will
be deducted.
We will test your programs with other (more complicated) text input
files.
Do not use any structures or any form of dynamic memory allocation
(using malloc or calloc) in your program, else no
credit will be given.
Remember to submit your program frequently using the submit
poke.c command, and check your submission using the check
command.
All the best!
UNIX commands
Some useful UNIX commands (in case you forgot what you did in Lab 0):
- “dir”: lists all the files in the directory.
- “cp a.txt b.txt”: copies a.txt to b.txt.
- “mv a.txt b.txt”: moves / renames a.txt to b.txt.
- “cat a.txt”: shows the contents of a.txt.