Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// Your name here // CSE240 // READ BEFORE YOU START: // You are given a partially completed program that creates a list of students

// Your name here // CSE240 // READ BEFORE YOU START: // You are given a partially completed program that creates a list of students for a class. // Each student has the corresponding information: name, gender, class_standing, roll_number, and tuition. // To begin, you should trace through the given code and understand how it works. // Please read the instructions above each required function and follow the directions carefully. // If you modify any of the given code, the return types, or the parameters, you risk failing the automated test cases. // // The following will be accepted as input in the following format: "name:gender:class_standing:roll_number:tuition_fee" // Example Input: "Tom:M:freshman:10:2000.10" or "Emma:F:junior:15:2700" // Valid name: String containing alphabetical letters beginning with a capital letter // Valid gender: Char value 'M' or 'F' // Valid class_standing: String containing class standing // Valid roll_number: Positive integer value // Valid tuition fee: Float containing no more than 2 decimal value, for example: 1500.45 or 2000.7 or 2700 // All inputs will be a valid length and no more than the allowed number of students will be added to the list #include  #include  #include  #include  #pragma warning(disable: 4996) // for Visual Studio Only typedef enum { male = 0, female } gender; // enumeration type gender // linked list of students struct student { char name[30]; gender genderValue; char class_standing[10]; int roll_number; float tuition_fee; struct student* next; } *list = NULL; // forward declaration of functions void flush(); void branching(char); void registration(char); int add(char*, char*, char*, int, float); // 10 points void remove_student(); // 10 points char* search(int); // 5 points int count(); // 5 points void swap(struct student *, struct student *); // 5 points void display();// 15 points int main() { char ch = 'i'; do { printf("Please enter your selection: "); printf("\ta: add a new student to the list "); printf("\ts: search for a student on the list "); printf("\tr: remove a student from the list "); printf("\td: display list of students "); printf("\tq: quit "); ch = tolower(getchar()); flush(); branching(ch); } while (ch != 'q'); return 0; } // consume leftover ' ' characters void flush() { int c; do c = getchar(); while (c != ' ' && c != EOF); } // branch to different tasks void branching(char c) { switch (c) { case 'a': case 's': registration(c); break; case 'd': display(); break; case 'r': remove_student(); break; case 'q': break; default: printf("Invalid input! "); } } // The registration function is used to determine how much information is needed and which function to send that information to. // It uses values that are returned from some functions to produce the correct ouput. // There is no implementation needed here, but you should study this function and know how it works. // It is always helpful to understand how the code works before implementing new features. // Do not change anything in this function or you risk failing the automated test cases. void registration(char c) { char input[100]; if (c == 'a') { printf(" Please enter the student's information in the following format: "); printf("\tname:gender:class_standing:roll_number:tuition_fee "); fgets(input, sizeof(input), stdin); // discard ' ' chars attached to input input[strlen(input) - 1] = '\0'; char* name = strtok(input, ":"); // strtok used to parse string char* genderValueString = strtok(NULL, ":"); char* class_standing = strtok(NULL, ":"); int roll_number = atoi(strtok(NULL, ":")); // atoi used to convert string to int float tuition_fee = atof(strtok(NULL, ":")); // atof used to convert string to float int result = add(name, genderValueString, class_standing, roll_number, tuition_fee); if (result == 0) printf(" That student is already on the list "); else printf(" Student added to list successfully "); } else // c == 's' { printf(" Please enter the student's information in the following format: "); printf("\troll_number "); fgets(input, sizeof(input), stdin); int roll_number = atoi(input); // atoi used to convert string to int char* result = search(roll_number); if (result == NULL) { printf(" That student is not on the list "); } else printf(" Name & Class standing: %s ", result); } } // Q1 : add (10 points) // This function is used to insert a new student into the linked list. You can simply insert the new student to the end of list. // Do not allow for the same roll number for different students. // If the roll number already exists on the list, print an error message and return 0. If the student is added to the list, return 1. // // NOTE: You must convert the string "genderValueString to an enum type and store it in the list. This will be tested. // (You must store all of the required information correctly to pass all of the test cases) // NOTE: You should not allow for the same roll number to be added twice, you will lose points if you do not account for this. // (That means that students on the list are allowed to have the same name but not the same roll number). int add(char* name, char* genderValueString, char* class_standing, int roll_number, float tuition_fee) { } // Q2 : search (5 points) // This function is used to search for a student on the list by roll_number and returns the name and class_standing of that student // If the student exists in the list, return a String containing the name and the class_standing of the requested student. // If the student does not exist on the list, return NULL // As the output, you should return the char * containing both name and class standing. // You can use strcat(s1, s2) to concatenate two strings (arrays of char) with the space between using strcat function. char* search(int roll_number) { } // Q3: count (5 points) // This function should count the number of students on the linked list and returns the number. The function is used in display function. int count() { } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions

Question

3. Define the roles individuals play in a group

Answered: 1 week ago