[SOLVED] C Java SQL database

$25

File Name: C_Java_SQL_database_.zip
File Size: 188.4 KB

5/5 - (1 vote)

Memory Management in C
Gitlab
Contact!
Overview
You must write a library of C code that manipulates something we will call a person database. The database has nothing to do with SQL or any other database system; rather our database is a singly-linked-list of Person structures. Your code is responsible for allocating and freeing memory related to such lists. The emphasis of this assignment is on how languages without automatic memory management require the programmer to explicitly manage memory.
Header File
C libraries declare types in header files. You must use the persons.h header file to complete this assignment. This file is available on the course web site. Included in this file are declarations for the PersonList, Person, and Node data types in addition to several methods that are necessary for using these types. You may not edit any item that is in the header file. You may, however, add additional items (function declarations and structures) if you find them necessary.
Implementation
The header file contains declarations only. It is similar to an interface in Java which means that the functions declared in the header must be implemented elsewhere. You must therefore implement each of the header functions in a file named persons.c. These functions are described in the following list.
1.struct Person *personCreate(char *first, char *last, int age, char *email) This function creates and returns a Person object. The function allocates memory for a person; copies the first name, last name, age and email into this allocated memory, and returns a pointer to the Person object. Returns NULL if such a person cannot be created.
2.void personDelete(struct Person *person) This method destroys the person object. All memory related to that object must be destroyed.
3.char *personFirstName(struct Person *person) Returns the persons first name.
4.char *personLastName(struct Person *person) Returns the persons last name.
5.char *personEmail(struct Person *person) Returns the persons email.
6.int personAge(struct Person *person) Returns the persons age.
7.struct PersonList *plCreate() This method creates a PersonList by allocating memory and initializing the values. The list is empty. A pointer to the list is returned. Returns NULL if the list cannot be created.
8.void plDelete(struct PersonList *db, enum deleteType dt) This method deletes a database (a PersionList) by freeing all memory associated with the list. If dt is PD_DEEP, the persons in the list are also deleted. If dt is PD_SHALLOW then only the list is deleted while the elements in the list are not deleted.
9.void plAdd(struct PersonList *db, struct Person *p) Adds the specified person object to the front of the list.
10.void plRemovePerson(struct PersonList *db, struct Person *p) Removes the specified person from the list. The person is not deleted.
11.struct PersonList *plFindByFirstName(struct PersonList *db, char *name) Returns a PersonList that contains all persons having the specified first name. Returns NULL if such a list cannot be constructed.
12.struct PersonList *plFindByLastName(struct PersonList *db, char *name) Returns a PersonList that contains all persons having the specified last name. Returns NULL if such a list cannot be constructed.
13.struct PersonList *plFindAtLeastAsOldAs(struct PersonList *db, int age) Returns a PersonList that contains all persons that are at least of the specified age. Returns NULL if such a list cannot be constructed.
14.struct Person *plGet(struct PersonList *db, int n) Returns the person at index n in the database. Returns NULL if there is no such person.
15.int plSize(struct PersonList *db) Returns the number of persons in the list.
Emphasized Requirements
1.You must put no restriction on how long the PersonList can be. My test harness will generate millions and billions (well, maybe not quite that many) of persons.
2.You must put no restriction on the length of a persons first name, last name, or email address. I will likely test your code using names and emails of unimaginably glorious length!
3.Your code must not exhibit any memory leaks, dangling pointers or any other pointer-related problems (at least, to the degree that your code is responsible for managing these objects).
Hints
1.This assignment is all about memory management and pointers. Be careful how you use malloc and especially free. Ensure that every malloc has a corresponding free written somewhere in your code.
2.printf is a function that corresponds to System.out in Java. It is a strange function that makes use of a formatting string. Make sure that you know how to use it for testing purposes.
3.C comes with a string-processing library that has functions defined in a header file named string.h. You should become familiar with strcpy and strlen.
4.The first lines you should type in your persons.c code are library imports. The first lines below allow your code to know about the standard C libraries named stdlib and strings. The second line allows your code to know about the persons.h declarations. #include #include #include persons.h
5.This assignment is all about memory management and pointers. Be careful how you use malloc and especially free. Ensure that every malloc has a corresponding free written somewhere in your code.
Submission
Sumbit your code via Gitlab under project CS421 in a folder named hw3.
CS 421 : Programming Languages
Kenny Hunt

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] C Java SQL database
$25