0% ont trouvé ce document utile (0 vote)
49 vues4 pages

Liste d'anniversaires d'amis en C

CS 262 Spring 2024 Lab 1

Transféré par

Jumana Eissa
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd

Thèmes abordés

  • allocation dynamique,
  • structure de programme,
  • type défini,
  • Valgrind,
  • programmation C,
  • exécution de Valgrind,
  • tri de données,
  • compilation,
  • contrôle d'erreur,
  • débogage
0% ont trouvé ce document utile (0 vote)
49 vues4 pages

Liste d'anniversaires d'amis en C

CS 262 Spring 2024 Lab 1

Transféré par

Jumana Eissa
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd

Thèmes abordés

  • allocation dynamique,
  • structure de programme,
  • type défini,
  • Valgrind,
  • programmation C,
  • exécution de Valgrind,
  • tri de données,
  • compilation,
  • contrôle d'erreur,
  • débogage

CS262, Lab 10:

Friends Birthday List


Due: Sunday, Apr 14 at 11:59 pm ET
Description:
In this Lab you will write a program to create a "Friends birthday list" sorted by month, day,
year, name (ascending).

Preparation:
In preparation for this assignment, you should review: Structures, Pointers and dynamic memory
allocation and Linked list. Use Valgrind to help you check for memory errors in your code. Note
that your submission doesn’t have to show any issue when using Valgrind.

Instructions:
Define a structure appropriate for holding the data to create a node list
name (string) /* Length of 50 */
dob (int) /* Day of birth */
mob (int) /* Month of birth */
yob (int) /* Year of birth */
next (pointer) /* A "next" pointer to the same struct type

Do not forget to use thee typedef to create new type of the structure.

The program will use a pointer to the head of the linked list.
• The head of the list will be accessed through a pointer, and the data contained in the head
of the list will be used for sorting purposes.
• Don't forget (mandatory) to free the memory when you exit your program.

Your program should display a menu as follows:


************ Friends birthday list ************
Friends in the list: 0
(1) Insert data
(2) Delete data
(3) Print List
(4) Quit
*****************************************
Enter your choice

Each time that data is inserted, the number of Friends in the List shown in the menu is updated.

Don't forget to validate the user's input:


Assume the input for menu choice is an int, validate that it is in the range [1-4]; otherwise, display
an error message and ask to re-enter a valid option.
Assume the input for dob, mob, yob is an int, validate that in in range: dob=[1-31]; mob=[1-12];
yob=[1930-2022]; display an error message and ask to re-enter a valid option when the input is
out of range.

1/4
Functions:
The program must contain at least the following functions:

int insertNode(Data *firstData, Data data) – This function inserts the given
data to the list pointed by firstData. The function returns 1 if the insertion is successful, 0 otherwise.
If the data already exists in the list, the function should fail (checking for name equality is enough).

Data * deleteNode(Data *firstData, Data data) – This function deletes the


given data from the list pointed by firstData. The function returns the deleted data if the deletion
is successful, NULL otherwise. If the data does not exist in the list, the function should fail.

void printList(Data *firstData) – This function takes the head of the list as its only
parameter, traverses the list, printing out the data in sorted order. Use formatting to
display dob, mob with 2 digits, so that value <10 is displayed as 01, 02, 03 … etc. (See a sample
run below)

You could define additional functions to keep your code more organized, for instance, a findnode()
function could be useful to return the position on which you need to insert the new node. You
could also code a function to “free” the memory allocation.

Testing using Valgrind


Valgrind is a suite of programs that you can use to improve your programs.
• Read a quick-start tutorial at this link: [Link]
• Read the Overview for Memcheck at this link: [Link]
[Link]

When compiling your program with gcc don’t forget to use the -g option and run your exe as:
valgrind --leak-check=yes ./exe

Makefile:
Modify the Makefile you used on your previous lab so that it works for this assignment.

Submission:
You will submit a typescript file similar to the one of previous Labs:
1. Create a typescript file named lab10_typescript_<username>_<labsection>
2. Show that you are logged onto Zeus.
3. Show the content of your source code.
4. Compile the code using your Makefile
5. Run the code using the data of the Sample run.
6. Remove the executable using your Makefile.
7. End the typescript.
8. Be sure your directory ONLY contains the source file, script and Makefile
9. Create a tarfile of your lab10_<username>_<labsection> directory
10. Submit the tarfile to Blackboard.
11. Verify that your submitted tarfile can be extracted and it’s the right tarfile.

Congratulations! You have completed your assignment :)

2/4
Sample run:
************ Friends birthday list ************
Friends in the list: 0
(1) Insert data
(2) Delete Data
(3) Print list
(4) Quit
*****************************************
Enter your choice: 1
*** Insert data ***
Name: Yossi Mata
Month of birth: 9
Day of birth: 4
Year of birth: 1999

************ Friends birthday list ************


Friends in the list: 1
(1) Insert data
(2) Delete Data
(3) Print list
(4) Quit
*****************************************
Enter your choice: 1

*** Insert data ***


Name: Anne Chow
Month of birth: 1
Day of birth: 1
Year of birth: 1979

************ Friends birthday list ************


Friends in the list: 2
(1) Insert data
(2) Delete Data
(3) Print list
(4) Quit
*****************************************
Enter your choice: 3

************ List content ************


01/01/1979 Anne Chow
09/04/1999 Yossi Mata

************ Friends birthday list ************


Friends in the list: 2
(1) Insert data
(2) Delete Data
(3) Print list
(4) Quit
*****************************************
Enter your choice: 2

*** Delete data ***


Name: Anne Chow
Month of birth: 1
Day of birth: 1
Year of birth: 1979

3/4
************ Friends birthday list ************
Friends in the list: 1
(1) Insert data
(2) Delete Data
(3) Print list
(4) Quit
*****************************************
Enter your choice: 3

************ List content ************


09/04/1999 Yossi Mata

************ Friends birthday list ************


Friends in the list: 1
(1) Insert data
(2) Delete Data
(3) Print list
(4) Quit
*****************************************
Enter your choice: 2

*** Delete data ***


Name: Anne Chow
Month of birth: 1
Day of birth: 1
Year of birth: 1979

################ Data Does not exist ###############

************ Friends birthday list ************


Friends in the list: 1
(1) Insert data
(2) Delete Data
(3) Print list
(4) Quit
*****************************************
Enter your choice: 4

Memory free successfully!

4/4

Vous aimerez peut-être aussi