0% found this document useful (0 votes)
8 views7 pages

Assignment Three

Uploaded by

askil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

Assignment Three

Uploaded by

askil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Assignment 3: Create a linked list library to provide services for a digital phone

book, enabling operations such as adding, deleting, or searching for a person’s


phone number. Ensure that dynamic memory allocation using `malloc()` is
utilized as needed for the application, and that memory is released back to the
system when data is deleted or the program finishes, in a Linux/Unix
environment.

Group number Member Names

A malloc function is a high-level memory management function provided by the C


standard library (implemented by glibc on Unix-like systems). An efficient memory
optimization program should only acquire memory when it is needed. For this
assignment, you are required to create a linked list library in a Linux system
programming environment using C. By the time you finish this assignment, you will gain
a deep understanding of memory management concepts and techniques, including
dynamic memory allocation and deallocation, pointer manipulation at user level.

Assignment descriptions:
This Assignment 3 will involve both individual and group evaluations. This setup mimics
real-world scenarios, where a team lead assigns different modules to team members.
Each team member follows the software specifications to implement their modules
(individual evaluation). Finally, all modules are integrated for testing purpose (a group
evaluation).
In this assignment, you will create five files: data.h, phonebook.c, linkedlist.h,
linkedlist.c, and makefile. data.h, linkedlist.h, linkedlist.c will define and implement a
simple singly linked list data structure in C. phonebook.c will utilize the defined linked list
library to implement a digital telephone book.
The data.h file defines the telephone book’s member information. phonebook.c is an
application designed to store your friends’ phone numbers, first names and last names.
linkedlist.h will contain the linked list node definition and function prototypes, while
linkedlist.c will implement these functions.
Finally, the makefile contains a set of instructions or rules to compile your program.
File Descriptions:
data.h:
This header file contains the following struct.
typedef struct {
int area_code;
int phone_number;
char firstName[50];
char lastName[50];
}data;
phonobook.c:
This is an application program. This program should provide a simple user menu similar
to Assignment 2, but with different content. Your team will have the freedom to design
how this user menu looks. However, it should contain a minimum of 4 options.
1. Add a new phone number
2. Delete a phone number
3. Search a phone number
4. Exit
linkedlist.h:
This file contains the definition of a linked list node, linked list, and the function
prototypes for the linked list operations.
linkedlist.c:
This file implements all the function prototypes listed in the header file. Helper functions
are declared as static to make them private.

linkedlist Node Structure:


Each node in the linked list consists of two components: the data and a pointer to the
next node in the list. The data part contains area code, phone number, first name and
last name. The pointer contains a node type pointer. The Figure 1 shows a singly linked
list.

data data data data data

Figure 1: A singly linked list


Functions in linkedlist.h:
void init(linkedlist*);
Description: Initializes the linked list.
Precondition: The linked list should be created, and its address should be passed to this
function in order to properly initialize all node members.
Postcondition: The linked list object has been initialized properly.
void add(linkedlist*, data*)
Description: Adds a new node with the given number to the end of the linked list
Precondition: The linked list and data are passed to the add function.
Postcondition: A new node containing the provided data is added to the end of the
linked list.

void delete(linkedlist*, int, int)


Description: Deletes the node containing the specified number from the linked list.
Precondition: The linked list, area code and phone number are passed to the delete
function.
Postcondition: If the targeted node exists, it is removed from the linked list, and the
memory is released back to the system.

int search(linkedlist*, char[], char[])


Description: Search a person’s phone number. If the person exists, display their phone
number including the area code and phone number, and return 1. Otherwise return 0.
Precondition: The linked list and a person’s first name and last name are passed to the
search function.
Postcondition: If the person’s phone number is found, it is displayed on screen, and 1 is
returned. Otherwise, 0 is returned.
Assignment Three Rubric
You have to prove the correctness of your program. The given inputs and outputs can
be found at the end of this document. If your program fails to generate the expected
output based on the provided example input, your group evaluation mark will be less
than 50%. Please see the rubric below for the breakdown of marks. If you submit a
faulty program, your grade will not exceed 50%.
Submission requirements
You need to upload a total of six files to the Moodle Dropbox.
1. data.h
2. linkedlist.h
3. linkedlist.c
4. phonebook.c
5. makefile – rename the makefile to makefile.txt
6. Teamwork breakdown – Each group member needs to specify exactly which
functions or files they worked on individually. Failure to do so will result in a zero
evaluation for the individual.

Coding 10%
Standard
Files
linkedlist.h Individual 50%
linkedlist.c
data.h
phonebook.c Group 50%
makefile
data.h/linkedlist.h/linkedlist.c
Coding Ignore coding Inconsistent Acceptable Good coding
Standard and standard coding coding standard
comments standard standard
10% 40% 70% 100% 10
Correctness The The Everything Everything
implementation implementation follows the follows the
does not follow is sort of requirements requirements
the following the for for
requirements requirements implementation implementation
with some
derivations

0% 50% 80% 100% 40


phonebook.c/makefile
Coding Ignore coding Inconsistent Acceptable Good coding
Standard and standard coding coding standard
comments standard standard

10% 40% 70% 100% 10


Correctness The The Everything Everything
implementation implementation follows the follows the
does not follow is sort of requirements requirements
the following the for for
requirements requirements implementation implementation
with some 40
derivations

0% 50% 80% 100%

The following are the example inputs and outputs. Make sure your program can
generate the same outputs.
****** My Phone Book ******
1: Add a new phone number
2: Delete a phone number
3: Search a phone number
4: Exit
***************************

Please select an option: 1

Area code: 416


Phone number: 1234567
First name: Jack
Last name: Bauer
Added!

****** My Phone Book ******


1: Add a new phone number
2: Delete a phone number
3: Search a phone number
4: Exit
***************************

Please select an option: 1


Area code: 519
Phone number: 2234567
First name: Tony
Last name: Almeida

Added!

****** My Phone Book ******


1: Add a new phone number
2: Delete a phone number
3: Search a phone number
4: Exit
***************************

Please select an option: 1


Area code: 705
Phone number: 3334567
First name: Nina
Last name: Myers
Added!

****** My Phone Book ******


1: Add a new phone number
2: Delete a phone number
3: Search a phone number
4: Exit
***************************

Please select an option: 3


First name: Tony
Last name: Almeida
The phone number is 519 2234567

****** My Phone Book ******


1: Add a new phone number
2: Delete a phone number
3: Search a phone number
4: Exit
***************************

Please select an option: 2


Area code: 519
Phone number: 2234567
Tony Almeida deleted!

****** My Phone Book ******


1: Add a new phone number
2: Delete a phone number
3: Search a phone number
4: Exit

***************************

Please select an option: 4


Bye!

You might also like