C Programming Linked List And Files

Posted Under: C

Ask A Question
DESCRIPTION
Posted
Modified
Viewed 22
i have 50-65% of the program done, I can send the code that i have already, about 250 lines. the first document is guidelines. second is my code i have so far. Implement a linked list to hold multiple organizations. write information to a file.

This order does not have tags, yet.

Attachments
// // HritzCannonIteration1.c // BookExample // // // #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <stdbool.h> #include <errno.h> #define SIZE 80 #define DMIN 1 #define DMAX 200 #define COSTMIN 50 #define COSTMAX 250 #define JCOSTMIN 50 #define JCOSTMAX 150 #define CHARITYMIN 5 #define CHARITYMAX 30 struct race { char organizationName[SIZE]; double raceDistance; double raceCost; double jerseyCost; double charityPercentage; double numOfJerseys; double numOfShirts; }; void displayRegistration(struct race organizationDetails); void displaySummary (struct race organizationDetails); void fgetsRemoveNewLine(char *string); void adminSetup(struct race *organization); char getValidChar(void); bool getValidDouble(char* charPtr, double* outNumberPtr, double min, double max); char validInput(void); bool validatePassword(void); void raceRegistration(struct race *organization); //Global const array of pointers to store the strings "(s)mall" "(m)edium" "(l)arge" "(x)tra-large" const char *shirtSize[] = {"(s)mall", "(m)edium", "(l)arge", "(x)tra-large"}; const char *validateAnswer[] = {"(y)es", "(n)o"}; int main(void) { struct race Organization; if(validatePassword() != false) { adminSetup(&Organization); displayRegistration(Organization); raceRegistration(&Organization); } else { printf("Exiting admin setup"); } //Call adminSetup function return 0; } void displayRegistration(struct race organizationDetails) { puts("You can register for one of the following bike races and a percentage will be raised for that organization"); // printf("You can register for one of the following races and %.2lf%% will be raised for %s\n",organizationDetails.charityPercentage, organizationDetails.organizationName); puts("Organization\t\tDistance\tCost\tPercentage\n"); printf("%s\t\t %.2lf\t%.2lf\t%.2lf", organizationDetails.organizationName, organizationDetails.raceDistance, organizationDetails.raceCost, organizationDetails.charityPercentage); puts("Enter the name of the organization you want to register"); // printf("You can purchase a jersey for $%.2lf", organizationDetails.jerseyCost); } void displaySummary (struct race organizationDetails) { printf("Organization: %s", organizationDetails.organizationName); printf("Distance: %.2lf", organizationDetails.raceDistance); printf("Race Cost: %.2lf", organizationDetails.raceCost); //printf("Registrants: %lf"); // printf("Total Race Sales: %.2lf"); printf("Jersey Cost: %.2lf", organizationDetails.jerseyCost); //printf("Jerseys Sold: %.2lf"); //printf("Total Jersey Sales: %.2lf"); //printf("Total Sales: %.2lf"); printf("Charity Percent: %.2lf", organizationDetails.charityPercentage); //printf("Charity Amount: %.2lf"); } //Function to read in a string using stdin fgets and replace the '\n' new line character void fgetsRemoveNewLine(char* buff) { //Read in a string using stdin fgets fgets(buff, SIZE, stdin); //Replace the '\n' new line character with '\0' null character if it exists if (buff[strlen(buff) - 1] == '\n') { buff[strlen(buff) - 1] = '\0'; } } //char *organizationName void adminSetup(struct race *organization) { //Call function from task 1 fgetsRemoveNewLine to read in the organization name, cost and distance printf("Enter fundraising organizations name:"); fgetsRemoveNewLine(organization->organizationName); char raceDistance[SIZE]; do { printf("Enter distance in miles for the bike course:\n"); fgetsRemoveNewLine(raceDistance); }while(!getValidDouble(raceDistance, &organization->raceDistance, DMAX, DMIN)); char raceCost[SIZE]; do { printf("Enter the registration cost of the bike ride for %s\n", organization->organizationName); fgetsRemoveNewLine(raceCost); } while (!getValidDouble(raceCost, &organization->raceCost, COSTMAX, COSTMIN)); char jerseyCost[SIZE]; do { printf("Enter the correct Jersey Cost:\n"); fgetsRemoveNewLine(jerseyCost); } while (!getValidDouble(jerseyCost, &organization->jerseyCost, JCOSTMAX, JCOSTMIN)); char charityPercentage[SIZE]; do { printf("Enter percentage of the bike race sales that will be donated to %s\n", organization->organizationName); fgetsRemoveNewLine(charityPercentage); } while (!getValidDouble(charityPercentage, &organization->charityPercentage, CHARITYMAX, CHARITYMIN)); } char getValidChar() { char input[SIZE]; //Character variable to store user input bool isValid = false; do { //Prompt for t-shirt size printf("Select your shirt size by entering the character in parenthesis: (s)mall (m)edium (l)arge (x)tra-large."); fgetsRemoveNewLine(input); char letter = tolower(input[0]); if(letter == shirtSize[0][1]) { printf("\nSmall shirt size was chosen"); isValid = true; } else if (letter == shirtSize[1][1]) { printf("\nMedium shirt size was chosen"); isValid = true; } else if (letter == shirtSize[2][1]) { printf("\nLarge shirt size was chosen"); isValid = true; } else if (letter == shirtSize[3][1]) { printf("\nXtra-Large shirt size was chosen"); isValid = true; } else { printf("\nNot a valid size. Returning to Menu"); } } while (!isValid); return input[0]; } //Function to get a valid double input from user bool getValidDouble(char* charPtr, double* outPtr, double max, double min) { char* end = NULL; double tempDouble = 0.0; bool validDouble = false; errno = 0; tempDouble = strtod(charPtr, &end); //Double variable to store user input if (end == charPtr) { puts("Error: input is NULL"); } else if (*end!='\0') { puts("Error!"); } else if(errno == ERANGE){ puts("Error!"); } else if (tempDouble > max ||tempDouble < min) { puts("Error: Enter a value within the parameters"); } else { *outPtr = tempDouble; validDouble = true; } return validDouble; } char validInput() { bool isInput = false; char input[SIZE]; char valid; printf("Please enter (y)es or (n)o.\n"); do { fgetsRemoveNewLine(input); valid = tolower(input[0]); // check return value if(valid == validateAnswer[0][1] || valid == validateAnswer[1][1]) { isInput = true; } else { printf("Error! Input needs to be a (y)es or (n)o"); } } while(!isInput); return valid; } bool validatePassword() { printf("Enter admin pin to set up race information\n"); bool isValid = false; int number = 0; int finalattempt = 3; char password[SIZE]; do { fgetsRemoveNewLine(password); number++; while (strcmp(password, "B!k34u") !=0) { if (number == finalattempt) { printf("Error: Too many incorrect attempts were made\n"); return isValid; } printf("Error: Password is incorrect\n"); printf("Enter admin pin to set up race information\n"); fgetsRemoveNewLine(password); number ++; } isValid = true; } while (!isValid); return isValid; } void raceRegistration(struct race *organization) { bool flag = false; int shirtNum = 0; int totalShirtNum = 0; char nameOfRegistrant[SIZE]; do { printf("Enter name to register\n"); fgetsRemoveNewLine(nameOfRegistrant); for(int i = 0; nameOfRegistrant[i]; i++) { nameOfRegistrant[i] = tolower(nameOfRegistrant[i]); } if(strcmp(nameOfRegistrant, "quit") == 0) { if(validatePassword() == true) { flag = true; } } else { printf("Do you want to purchase a jersey for %.2lf?\n",organization->jerseyCost); if (validInput() == 'y') { getValidChar(); shirtNum++; } } } while (!flag); } Iteration 2: Refactor and New Features Bike Race Fundraiser Purpose: Demonstrate the goals for the course · Implement structured programming using the C language and continue building a foundation in programming fundamentals · Understand and implement pointers and dynamically manage memory for data structures. · Use Software Development Life Cycle (SDLC) to design and implement modular solutions. · Develop a coding mindset where you implement modular secure code that is easy to read, understand, extend and maintain. Effort: Individual (Academic Integrity) Show show perseverance, pride and integrity Points: 100 pts (See Rubric) Deliverables: Upload your analysis and design document (1 or two files - word or pdf) and .c code. Do not upload a zip file. Description 1. Apply Software Development Life Cycle as you analyze, design, implement and test your solution that is · Functionally Complete and Correct · Maintainable: Easy to Read/Understand, Modular/Reusable/Testable · Secure 2. Refactor your code before adding new code. 3. Analyze and design 4. Implement and test Part 1: Analyze and Design These are the minimal design expectations for this iteration: Analyze the new iteration 02 requirements to support multiple organizations, write information to a file. Design a plan that includes a time estimate as if you were in industry. Include all of the following in your analysis and design document. 1. Before you build on top of your code you should refactor. Clean up that smelly code - fix at least two different types of problems in your code. Include a screenshot of the code before and then the code after. Write a summary explaining the refactoring of each. 2. List of new tasks/functions needed for iteration 02 3. Review your current code and list the existing functions that you think will need to be updated 4. Include a table of inputs and outputs that cover a range of test cases for the new tasks/functions. 5. Design Algorithm to handle searching for the inputted organization name when registering. Part 2: Implement new requirements. Problem Description A bike race registration application program is needed to support different fundraising events. For example, CU Boulder sponsors the Buffalo Bicycle Classic | University of Colorado Boulder to raise funds. A business wants to create a program to manage bike ride fundraisers for organizations to raise funds. The admin after logging in can set up the bike ride fundraiser by entering the organization name, race price and percentage of sales that goes to the organization. Next customers can register for the race by registering name, optional jersey and making a payment. The admin will be able to shut down the sales mode when login is correct to get a summary of the number of registrants and total funds raised for an organization. Requirements: User Stories and Acceptance Criteria User Story 1: Admin Set Up The admin will enter the correct pin to set up the race information. The admin can set up more than one fundraising organization where the information is stored in a structure. The admin will enter the information for the organization and continue adding more until they are done. 1.1 Login Admin enters login. Acceptance Criteria 1.1 Prompt “Enter admin pin to set up race information”. · When the passcode is not B!k34u, display error and repeat the prompt for the pin again but no more than three times. “Error: the password is incorrect” · After three incorrect attempts, give a message “Exiting admin set-up” and the program ends. · When valid passcode B!k34u display: “Set up the fundraising information for the organization. 1.1.1 Add Multiple Organizations Prompt for the information in 1.2 to 1.5. Then ask if they want to add another organization. Acceptance Criteria · Organization information should be stored alphabetically in a linked list by the name of the organization. · The admin will not be removing any organizations · Organizations can be added only during set-up · After the admin enters one organization prompt (y)es or (n)o if they want to add another. · You can use the same min and max values when validating input for each organizations. 1.2 Organization Name Admin enters the organization name. No need to do any validation. · Prompt Name: “Enter fundraising organizations name.” 1.3 RideDistance Set up race distance Acceptance Criteria · Prompt Miles: “Enter distance in miles for the bike course.” · If the distance in miles entered isn’t inclusively from 1 to 200. Repeat prompt and display error “Error: Enter a value from 1 to 200” 1.4 Ride Cost Set up ride cost Acceptance Criteria · Prompt Ride Cost: “Enter the registration cost of the bike ride for [NAME OF ORGANIZATION].” · If the race cost entered isn’t inclusively between $50 and $250. Repeat prompt and display error “Error: Enter a value from 50 to 250” · If a valid value entered, display “The bike race cost is $[COST OF RACE]” 1.5 Jersey Cost Set up jersey cost Acceptance Criteria · Prompt sales jersey price: “Enter sales price of jersey for [NAME OF ORGANIZATION].” · If the jersey cost entered isn’t inclusively between $50 and $150. Repeat prompt and display error “Error: Enter a value from 50 to 150” · If a valid value entered, display “The bike jersey cost is $[COST OF JERSEY]” 1.5 Charity Percentage Set up charity percentage Acceptance Criteria · Prompt to enter percentage: “Enter percentage of the bike race sales that will be donated to [NAME OF ORGANIZATION].” · If the race cost entered isn’t inclusively between %5and %30. Repeat prompt and display error “Error: Enter a value from 5 to 30” · If a valid value is entered, display “You entered [PERCENT] % of the bike race to go to charity.” 2. Bike Registration Mode The race registration mode will repeat until the admin quits and logins in to end registration mode. The registrant enters the organization name to register for the bike ride. Then they enter their name to register for a race, get a jersey, make payment and get a receipt. 2.0.1 Select Organization Registrant selects the organization they want to register for the bike ride. Acceptance Criteria · Display the following information for each organization and prompt the user to enter the organization name to register for that ride. You can register for one of the following bike races and a percentage will be raised for that organization. Organization Distance Cost Percentage Mattersville 100 miles $100.00 %10 ALS-Pedals 75 miles $80 %20 Enter the name of the organization you want to register. · If the name they enter doesn’t match any of the organizations, repeat the question. NOTE: I want you to focus on the new concepts with linked lists and files so the shutdown mode is still associated with a sentinel value when prompted to enter the registrant's name 2.1 Registration Name · Prompt “Enter your first name and last name to register for the ride”. · If “quit” is not entered for the name go to jersey selection 2.2 · If the admin enters “quit” ask for login, Prompt “Enter admin pin”. Handle all cases for entering QUIT. · When the passcode is not B!k34u, display error and repeat the prompt for the pin again but no more than three times. “Error: the password is incorrect” · After three incorrect attempts, go back to the registration and prompt for first and last name. · When valid passcode B!k34u entered, go to 3.1.1 Fundraiser Summary 2.2 Jersey Selection Display option to purchase jersey. Acceptance Criteria Prompt “Do you want to purchase a jersey for [COST OF JERSEY] ?” · When y/Y or n/N is not entered, repeat the prompt “Please enter y or n.” · When y/Y entered,ask for jersey size selection. · Prompt “Enter your size (s)mall, (m)edium, (l)arge, or (x)large.” · Repeat prompt if not valid input s/S, m/M, l /Lor x/X · When a valid size is entered, go to payment. · When n/N is entered, go to payment. 2.3 Payment Display the total cost and ask for the user to enter a credit card. The customer will enter a credit card for payment. You only need to validate a Discover credit card number in the following pattern. # - represents a number X – represents a letter Card Spacing Patterns Example Discover XXXX-####-##### FVMS-4832-93367 Acceptance Criteria · Prompt “Your total cost is [cost of race/jersey] Enter your credit card”. Repeat the question if the user didn’t enter a valid credit card. · When a valid credit card is entered, display “Thank you [Name of person] for your purchase. [Dollar amount] of the ticket sales will go to charity. Then go to 2.4 Receipt option 2.4 Receipt The registrant can get a receipt if they choose. Acceptance Criteria · Prompt “Do you want a receipt (y)es or (n)o?” · When y/Y or n/N is not entered, repeat the prompt “Please enter y or n.” · If n/N is entered, go back to 2.1 for the next person to register. · If Y/y is entered then display the receipt to include the following then prompt for the next user to purchase tickets. Then go back to 2.1 for the next person to register. 3.1 Display Summary When the admin shuts down the system each organization's information should be displayed and stored in separate files. Acceptance Criteria · Store the fundraiser summary for each organization in separate files using this naming convention org1.txt for the first, org2.txt. These will be stored in a folder where the path is able to be configured by updating a global constant to store a local file path to a folder This will be used to write each organization’s sales summary files to this folder. · Display the summary for each organization on the console and write to a file Example Summary Display for one organization that should also be written to a file such as org1.txt Organization: Mattersville Distance: 100 Race Cost: 80 Registrants: 4 Total Race Sales: 320 Jersey Cost: 50 Jerseys Sold: 3 Total Jersey Sales: 150 Total Sales: 470 Charity Percent: 10 Charity Amount: 47 · Deallocate the memory for all the organizations.
Explanations and Answers 0

No answers posted

Post your Answer - free or at a fee

Login to your tutor account to post an answer

Posting a free answer earns you +20 points.

Login

NB: Post a homework question for free and get answers - free or paid homework help.

Get answers to: C Programming Linked List And Files or similar questions only at Tutlance.

Related Questions