Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.86 KB | None | 0 0
  1. /* Author: Zachariah Myers
  2. *  Date Created: 11/30/15
  3. *  Lab Number: CST 116 11.14 Programming Exercise #4
  4. *  Filename: 11.14 Exercise 4.cpp
  5. *
  6. *  Overview: This program contains a database of information sorted by persons.
  7. *            It displays a menu with options for users to find information, add information
  8. *            to the database, edit information in the database, and display all records in
  9. *            the database.
  10. *
  11. *  Input: This program recieves data from a database file, as well as allowing users to input
  12. *         a choice at the main menu and add or edit information in the database.
  13. *
  14. *  Output: If a display option is selected, this program will display either one person's information
  15. *          or the information of every person in the database.
  16. */
  17. #include<iostream>
  18. #include<fstream>
  19.  
  20. using std::cin;
  21. using std::cout;
  22. using std::endl;
  23. using std::ifstream;
  24. using std::ofstream;
  25.  
  26. //void findPerson();
  27. void addNewPerson(char FirstName[], char LastName[], char PhoneNum[], char BirthDate[]);
  28. //void editPerson();
  29. //void displayAll();
  30.  
  31. const int NAMELEN = 81;
  32. const int NUMLEN = 12;
  33.  
  34. int main() {
  35.  
  36.     int choice; //variable for menu choice
  37.  
  38.                 //main menu
  39.     cout << "\t--MainMenu--\n" << endl;
  40.     cout << "1. Find a person's information" << endl;
  41.     cout << "2. Add a person to the database" << endl;
  42.     cout << "3. Edit a person's information" << endl;
  43.     cout << "4. Display every person's information" << endl;
  44.     cout << "5. Quit\n" << endl;
  45.     cout << "\tPlease choose an option: ";
  46.     cin >> choice;
  47.  
  48.     //switch for user's choice at main menu
  49.     switch (choice) {
  50.         //find info choice
  51.     case 1: {
  52.  
  53.     }
  54.             break;
  55.             //add person choice
  56.     case 2:
  57.         char FirstName[NAMELEN]; //array for holding first name
  58.         char LastName[NAMELEN];   //array for holding last name
  59.         char PhoneNum[NUMLEN];  //array for holding phone number
  60.         char BirthDate[NUMLEN]; //array for holding date of birth
  61.  
  62.         //asks for names, ph #, and bday, then stores them in arrays
  63.         cout << "\nPlease enter a first name: ";
  64.         cin >> FirstName;
  65.         cout << "\nPlease enter a last name: ";
  66.         cin >> LastName;
  67.         cout << "\nPlease enter a phone number in format ###-###-####: ";
  68.         cin >> PhoneNum;
  69.         cout << "\nPlease enter a birth date in format MM-DD-YY: ";
  70.         cin >> BirthDate;
  71.  
  72.         addNewPerson(FirstName, LastName, PhoneNum, BirthDate);
  73.  
  74.         break;
  75.         //edit person choice
  76.     case 3: {
  77.  
  78.     }
  79.             break;
  80.             //display everyone choice
  81.     case 4: {
  82.  
  83.     }
  84.             break;
  85.             //quite choice
  86.     case 5: {
  87.  
  88.     }
  89.             break;
  90.             //default (invalid input)
  91.     default:
  92.         cout << "\nInvalid Input!" << endl;
  93.         break;
  94.  
  95.     }
  96.  
  97.     system("pause");
  98.  
  99.     return 0;
  100.  
  101. }
  102.  
  103. void addNewPerson(char First, char Last, char Phone, char Birth) {
  104.  
  105.     //creates database object and opens database text file
  106.     ofstream database;
  107.     database.open("database.txt", std::ios_base::app);
  108.  
  109.     database << Last << First << Phone << Birth;
  110.  
  111.     database.close();
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement