Create a linked list of self referential structures

Assignment Help C/C++ Programming
Reference no: EM131310153

Assignment

This assignment gives you the opportunity to practice array of pointers, linked lists and self referential structures.

Write a program that initializes two parallel arrays as follows:

char * String[] = { "Abbie", "Oakley", "Sylvia", "Uwe", "Ken", "Aaron", "Fabien" };
double GPA[] = {3.8, 3.0, 3.9, 2.0, 2.5, 4.0, 3.2};

Then the program takes the strings and GPAs from the arrays one by one, starting from element index 0, populates the studentRecord structure below and inserts the structure in a linked list which is initially empty. The structure should be inserted in the right location, so as to maintain the lexicographic order of the strings. The structures in the linked list are printed after every insertion, with the structures being printed in the order they appear in the list. Finally, after all the array elements are inserted, the program should print again the complete content of the linked list, with the structures being printed in the order they appear in the list. If your program is correct, the order in which the strings and GPAs are printed should be:

Aaron, 4.0, Abbie, 3.8, Fabien, 3.2, Ken, 2.5, Oakley, 3.0, Sylvia, 3.9, Uwe, 2.0.

Additional requirements - Make sure you meet all the requirements to avoid losing points

1. Follow the requirements in the "Homework Notes".

2. To ensure consistency in the submissions, your program must do the following:

Use this self referential structure

struct studentRecord // Self referential structure used in linked list
{
char name[NAME_LENGTH + 1]; // set NAME_LENGTH to 10 double GPA;
struct studentRecord * nextPtr;
};

For convenience, it is recommended you use typedefs:
typedef struct studentRecord Student; // Student is an alias for struct studentRecord
typedef Student * studPtr; // studPtr is a pointer to Student

3. To create the Student self referential structures, your program must use malloc()

4. You must populate the linked list through a loop. You are not allowed to create the 7 Students of the list by writing 7 assignment statements, one for each Student in the list

5. Your program must work for any set of strings used as input, not just the ones given

6. You are allowed to use the strcmp() and strcpy() functions from the C library (see section 8.6,

8.7 of textbook or the Internet for details). You are only allowed to use functions and features of C that have already been taught in class, or in the hints provided. You will not get credit if you use existing functions in the C library not taught in class, unless you are explicitly told you are allowed.

Suggestions for implementation

1 - Your program can implement the functions whose prototypes are given below
// Function prototypes

/**********************************************************/
/* This function inserts newName and newGpa into the linked list pointed by *sPtr

Walks through the list to find the right location for insertion Insertion is done in lexicographic order of the student's name Note: sPtr is a pointer to a pointer, and *sPtr

points to the first Student of the list, or is NULL if the list is empty */

/**********************************************************/ void insert(studPtr *sPtr, char * newName, double newGpa);

/**********************************************************/
/* Print the Student pointed by myPtr
/**********************************************************/ void printStudent(studPtr myPtr);

/**********************************************************/
/* Prints the elements of the linked list pointed by myPtr */
/**********************************************************/ void printList(studPtr myPtr);

2. Pseudocode for the program

1 - Create a linked list of self referential structures (each self referential structures is called Student) and initialize the list to empty

2 - Take the strings from String[] and the GPA from GPA[] one by one, and for each (string, GPA) do the following

Call insert Call printList

3 - Call printList

Reference implementations

You are allowed to use and adapt as needed the example implementations for a linked list (insert, printList, etc.) in the Unit7-1 lecture slides.

Lexicographic order of character strings

Let a and b two strings of characters. Assume first that they have the same number of characters:

a1a2 ... ak
b1b2 ... bk

Rule 1 - If at the first i where ai and bi differ, the character ai < bi, then a < b. Rule 2 - If at the first i where ai and bi differ, the character ai > bi, then a > b. Rule 3 - If ai = bi for all i <= k, a = b.

Now let us consider the case where the strings do not have the same number of characters. Assume a has k
characters and b has m characters, where m > k.

Rule 1 - If at the first i where ai and bi differ, the character ai < bi, and i <= k, then a < b. Rule 2 - If at the first i where ai and bi differ, the character ai > bi, and i <= k, then a > b. Rule 3 - If ai = bi for all i <= k, then a < b

For example, consider the strings "Thomas" and "Thompson". The 5th character is the first that is different in the two strings ('a' vs. 'p'). Because 'a' < 'p', "Thomas" < "Thompson".

Another example is "Thomas" and "Thom". Since all the first four characters match and "Thom" is shorter, "Thom" < "Thomas".

You are allowed to use the strcmp() function from the C library that compares two strings according to the lexicographic order.

You may earn up to 10 points extra credit if, in addition to the above, you implement the following. Your program should display a menu asking the user to choose (1, 2, 3, or 4). Option 4 is to quit. As long as the user does not choose to quit, the program loops over displaying the menu. Your program must also do input validation and print an error message if the user types anything other than 1, 2, 3 or 4, then display the menu again and ask the user to reenter the user's choice.

1) Add a student to the list: The user is prompted to type a name and a GPA, then the program builds a structure, then inserts it in the list in the right location, according to the lexicographic ordering - The list is then printed for verification

2) Delete a student from the list: The user is then prompted to type a name, and the program searches for the name. If the name is found, the program deletes the structure from the list - The program prints a message: "Deleted" or "Student not found". The list is then printed for verification. Delete is case insensitive. For example, if the user types "fabien", "Fabien" will be deleted.

3) Search for a student: The user is then prompted to type a name, and the program searches for a student of that name - The program prints a message: "Found at location x in the list", where x is the location of the structure in the list (The first structure is at location 1) or "Student not found". The list is then printed for verification. Search is case insensitive. For example, "Uwe" will be found if the user types "UWE".

4) Quit

For the extra credit, you may want to implement these additional functions:

/**********************************************************/
/* Displays the menu and returns the user's choice as an int */
/**********************************************************/ int getUserChoice();

/**********************************************************/
/* Searches for Student in the list by name and deletes it

If student not found, return 0. Else, if deletion successful, return 1*/

/**********************************************************/ int delete(studPtr *sPtr, Student myStud);
/**********************************************************/
/* Searches for Student in the list by name

If student is found, return the location of the student. For example, returns 2 if the student is second in the list. If the student is
not found, returns 0. If the list is empty, returns -1 */

/**********************************************************/ int search(studPtr curPtr, char *name);

Note: You are allowed to use the toupper() and tolower() functions from the C library. Google or refer to section 8.3 of the textbook for details.

Reference no: EM131310153

Questions Cloud

Discuss seven criteria of defining a robot : I need a report on what is a robot and also discuss seven criteria of defining a robot ( using the book robot programming a guide of programming autonomous robots) I need 4 pages not including references.
Review the case study - a love triangle : Review the Case Study: A Love Triangle, Next, determine the two (2) most serious issues that the administrator of this facility is presented with in this complicated case
How could chances of such an attack succeeding be minimimise : What should be done instead to alert the staff to the attempted intrusion, and how could the chances of such an attack succeeding be minimized?
Create a job description for a retail sales associate : Create a job description for a retail sales associate, which includes the most significant components necessary to describe the job both internally and externally
Create a linked list of self referential structures : CS1325 - F16 Assignment: Create a linked list of self referential structures (each self referential structures is called Student) and initialize the list to empty. Take the strings from String[] and the GPA from GPA[] one by one.
How issue creates a performance problem for the organization : Describe a performance issue which resulted from a motivational problem (what, why, who).Use a content theory of motivation (e.g., Maslow, Alderfer, Herzberg, or McClelland) or a process theory (i.e., Adams, Locke, or Heider and Kelley) to explain..
Evaluate compound return on overall portfolio of investment : Evaluate the compound return on the overall portfolio of investments for each existing investor. This will be one number per investor.
Examine two major hr ethical issues : Examine two (2) of the major HR ethical issues multinational corporations face when operating globally. Recommend two (2) preventative actions that HR departments can take in order to lessen the occurrence of these ethical issues. Provide a rationale..
Convertible bond is currently selling : A bond with a coupon rate of 6.5%, maturing in 10 years at a value of $1,000 and current market price of $695 will have a current yield of. A convertible bond is currently selling for $1,125. It is convertible into 20 shares of common which presently..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a program that skip s leading whitespace character

a) Write a program that skip s leading whitespace character s in each line of the pro vided data file CPPHumor .txt . Save the results in a new file

  Write a program that creates an array of 200 random numbers

Write a program that creates an array of 200 random real numbers between 0 and 200.  Using the statistics library, calculate and output the following: mean, median, variance, standard deviation, maximum value, and minimum value.

  Research paper on dynamic arrays

Create codes for the following problem/s. Compile, test run, and edit them if necessary. Include your original .cpp and related file(s) (if any) in a single folder. Compress (zip) the folder and submit the single zipped folder.

  Design a c++ program containing a class fraction.

Test your class in the main() method by creating several fractions, adding them, subtracting them, and printing the result by using the / sign (e.g., 2/3), not as decimal fractions. Also demonstrate usage of the overloaded operators.

  What is the output of the program below

What is the output when the following code fragment is executed?

  Dimensional array of integers and fill it with data

Create a 2-by-3 two-dimensional array of integers and fill it with data. Loop through the array and locate the smallest value stored. Print out the smallest value as well as its row and column position in the array

  Review of object oriented software development methodologies

Review of Object Oriented Software Development Methodologies

  Modify the c program so that user inputs the purchase amount

Modify the C program so that the user inputs the purchase amount. Check the user's input for validity. In addition to calculating the sales tax for each location, calculate and display the total sale amount for each location.

  Implement a time class that represent a specific time of day

Implement a Time class. Each object of this class will represent a specific time of day, storing the hours, minutes, and seconds as integers.

  Write a program that reads letters from a file

This program should open an inputLet.txt file , read in one character at a time and repeat this for the number of games the user wants to play.

  Concepts of the object-oriented programming paradigm

Review structured programming concepts -  Describe the main concepts of the object-oriented programming paradigm.

  Addition of two matrices

Write a C program that uses functions to perform the following: i) Addition of Two Matrices. ii) Multiplication of Two Matrices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd