daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct Address{
  6.     int street_number; // street number
  7.     char street_name[20]; //street name
  8. };
  9.  
  10. struct Member{
  11.     int ID; //Member ID
  12.     char first_name[20]; // First name
  13.     char last_name[20]; // Last name
  14.     struct Address address; // address sub struct
  15.     int age; // member age
  16. };
  17.  
  18. struct Book{
  19.     char title[50]; //title of book
  20.     char author[30]; //author of book
  21.     char genre[20]; // genre of book
  22. };
  23.  
  24. int main(){
  25.     struct Member member[4] = {0}; // array that stores 4 members
  26.     struct Book library[4] = {0}; // array that stores 4 books
  27.     //struct Book *library_ptr; // book ptr to access library mem locations (might not need)
  28.     //library_ptr = library; // allows you to move through memory locations of library array
  29.     //struct Member *member_ptr;
  30.     //member_ptr = member;
  31.    
  32.     int menu_remove_member_ID;
  33.     int menu_continue = 1; // while loop condition to reuse the menu
  34.     int member_count = 0; // keeps track of the number of members to move through the array of members
  35.  
  36.     char clerk_name[30]; // name of the clerk who has registered the customer
  37.  
  38.     //building the library
  39.     strcpy(library[0].author, "JRR Tolkien");
  40.     strcpy(library[0].title, "Lord of The Rings");
  41.     strcpy(library[0].genre, "Fantasy");
  42.  
  43.     strcpy(library[1].author, "Douglas Adams");
  44.     strcpy(library[1].title, "Hitchhiker's Guide to the Galaxy");
  45.     strcpy(library[1].genre, "Science Fiction");
  46.  
  47.     strcpy(library[2].author, "Sebastian Junger");
  48.     strcpy(library[2].title, "Tribal");
  49.     strcpy(library[2].genre, "Non-fiction");
  50.  
  51.     strcpy(library[3].author, "Rupi Kaur");
  52.     strcpy(library[3].title, "The Sun and Her Flowers");
  53.     strcpy(library[3].genre, "Poetry");
  54.  
  55.     //testing library
  56.     for(int i = 0; i < 4; i++){
  57.         printf("Library book TEST! %s, %s, %s \n\n", library[i].author, library[i].title, library[i].genre);
  58.     }
  59.  
  60.     //psuedo-login for clerk
  61.     printf("Enter clerk name.\n");
  62.     scanf("%s", clerk_name);
  63.  
  64.     //menu and actions within the menu
  65.     while(menu_continue == 1){
  66.         int menu_option; // choice for menu navigation
  67.         printf("Welcome to the Libary Manager, %s \n", clerk_name);
  68.         printf(" 1: Add Member\n 2: Remove Member\n 3: Search Member\n 4: Search Book\n 5: Return Book\n 6: Exit\n");
  69.         scanf("%d", &menu_option);
  70.  
  71.         //this is where the menu selection is processed
  72.         switch(menu_option){
  73.             //add member
  74.             case 1:
  75.                 printf("First Name: \n");
  76.                 scanf("%s", member[member_count].first_name);
  77.                 printf("Last Name: \n");
  78.                 scanf("%s", member[member_count].last_name);
  79.                 printf("Age: \n");
  80.                 scanf("%d", &member[member_count].age);
  81.                 printf("Street Number: \n");
  82.                 scanf("%d", &member[member_count].address.street_number);
  83.                 printf("Streen Name: \n");
  84.                 scanf("%s", member[member_count].address.street_name);
  85.                 printf("User ID (10 digits): \n");
  86.                 scanf("%10d", &member[member_count].ID);
  87.                 fflush(stdin);
  88.                 member_count++;
  89.                 break;
  90.             //remove member    
  91.             case 2:
  92.                 printf("Enter the ID of the membership you wish to cancel. \n");
  93.                 scanf("%10d", &menu_remove_member_ID);
  94.                 for(int i = 0; i < member_count-1; i++){
  95.                     if(menu_remove_member_ID == member[i].ID){
  96.                         printf("Membership cancelled.");
  97.                     }
  98.                 }
  99.                 member_count--;
  100.                 fflush(stdin);
  101.                 break;    
  102.             case 3:
  103.                 printf("test\n");
  104.                 //stuff
  105.                 break;
  106.             case 4:
  107.                 printf("test\n");
  108.                 //stuff
  109.                 break;
  110.             case 5:
  111.                 printf("test\n");
  112.                 //stuff
  113.                 break;
  114.             case 6:
  115.                 printf("Goodbye!\n");
  116.                 exit(0);
  117.                 break;
  118.             default:
  119.                 printf("Please choose one of the available options from the menu using 1-6.\n");
  120.         }
  121.     }
  122.     return 0;
  123. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top