Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.53 KB | None | 0 0
  1.  
  2. #define _CRT_SECURE_NO_WARNINGS
  3.  
  4. #include <stdio.h>
  5.  
  6. // This source file needs to "know about" the structures you declared
  7. // in the header file before referring to those new types:
  8. // HINT: put the header file name in double quotes so the compiler knows
  9. //       to look for it in the same directory/folder as this source file
  10. // #include your contacts header file on the next line:
  11. #include "contacts.h"
  12.  
  13.  
  14.  
  15.  
  16. int main(void) {    //compiler looks for main function as a starting point. main returning 0 means everything is ok.
  17.     // Declare variables here:
  18.  
  19.     // Create a variable of type Contact and call it something self-describing like "contact"
  20.     // - HINT: Be sure to initialize the values to 0 and empty C strings
  21.     // Declare variables here:
  22.     Contacts contact = { {""}, {0,"",0,"",""},{""} };
  23.     int key = 0;    //declare flags
  24.                    
  25.     // Display the title
  26.     title();
  27.  
  28.     // Call the Contact function getName to store the values for the Name member
  29.     getName(&contact.contactName, &promptYN);
  30.  
  31.     // Call the Contact function getAddress to store the values for the Address member
  32.     getAddress(&contact.contactAddress, &promptYN, &key);
  33.     if (key == 1) {
  34.         return 0;   //if user wants to exit program return
  35.     }
  36.  
  37.     // Call the Contact function getNumbers to store the values for the Numbers member
  38.     getPhone(&contact.contactNumbers, &promptYN);
  39.  
  40.     // Display Contact summary details
  41.     displaySummary(contact);
  42.  
  43.     // Display Completion Message
  44.     completion();
  45.  
  46.     return 0;   //return 0 because function is type int.
  47. }
  48.  
  49.  
  50.  
  51. void displaySummary(Contacts contact) { //takes 3 parameters with struct values
  52.                                                                                         //print title of summary
  53.     printf("\nContact Details\n");
  54.     printf("---------------\n");
  55.     //print Name details
  56.     printf("Name Details\n");
  57.     printf("First name: %s\n", contact.contactName.firstName);  //get value from firstName member
  58.     printf("Middle initial(s): %s\n", contact.contactName.middleInitial);   //get value from middleInitial member
  59.     printf("Last name: %s\n\n", contact.contactName.lastName);  //get value from lastName member
  60.                                                         //print address details
  61.     printf("Address Details\n");
  62.     printf("Street number: %d\n", contact.contactAddress.streetNumber); //get value from streetNumber member
  63.     printf("Street name: %s\n", contact.contactAddress.street); //get value from street member
  64.     printf("Apartment: %d\n", contact.contactAddress.apartmentNumber);  //get value from apartmentNumber member
  65.     printf("Postal code: %s\n", contact.contactAddress.postalCode); //get value from postalCode member
  66.     printf("City: %s\n\n", contact.contactAddress.city);    //get value from city member
  67.                                                     // print number details
  68.     printf("Phone Numbers:\n");
  69.     printf("Cell phone number: %s\n", contact.contactNumbers.cell);//get value from cell member
  70.     printf("Home phone number: %s\n", contact.contactNumbers.home); //get value from home member
  71.     printf("Business phone number: %s\n\n", contact.contactNumbers.business);   //get value from business member
  72. }
  73.  
  74.  
  75. void title() {  //function prints title of program
  76.     printf("Contact Management System\n");
  77.     printf("-------------------------\n");
  78. }
  79. void completion() { //function prints completion message
  80.     printf("Structure test for Contact using functions done!\n");
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement