Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <istream>
- #include <string>
- #include <ostream>
- using namespace std;
- ifstream contactlist;
- void menu(string filename)
- {
- char choice;
- int count = 0;
- string firstname, lastname, address1, address2, email, number, giggles, search;
- string str = "";
- string next = "Next command?";
- contactlist.open(filename);
- cout << "Menu Options:" << endl << "1: Add contact" << endl << "2: Delete Contact" << endl
- << "3: Display All Contacts" << endl << "4: Search Contacts" << endl << "5: Create List" << endl << "6: End Program" << endl;
- cout << "Enter first choice twice. Sorry :/" << endl << "No spaces anywhere, please" << endl;
- cin >> choice;
- while (choice != '6')
- {
- cin >> choice;
- if (choice == '1') // create contact
- {
- cout << "Contact number " << count << endl;
- cout << "First name?" << endl;
- cin >> firstname;
- cout << "Last name?" << endl;
- cin >> lastname;
- cout << "First address line?" << endl;
- cin >> address1;
- cout << "Second address line?" << endl;
- cin >> address2;
- cout << "Phone number?" << endl;
- cin >> number;
- cout << "Email?" << endl;
- cin >> email;
- count++;
- cout << "Next command?" << endl;
- }
- else if (choice == '2') // delete
- {
- cout << "Delete contacts" << endl;
- cout << "Next command?" << endl;
- }
- else if (choice == '3') //display
- {
- while (getline(contactlist, giggles))
- {
- cout << "Shwoop!" << endl;
- }
- cout << "Next command?" << endl;
- }
- else if (choice == '4') // search
- {
- contactlist.open(filename);
- cout << "search contacts for a first or last name, street, phone number or email" << endl;
- cout << "Search input?" << endl;
- cin >> search;
- bool b(str == search);
- b = 0;
- while (contactlist >> str)
- {
- if (b == 1)
- {
- cout << "Item found" << endl << str << endl;
- break;
- }
- else
- cout << "Item not present" << endl;
- }
- contactlist.close();
- cout << "Next command?" << endl;
- }
- else if (choice == '5') // create list
- {
- cout << "blerg" << endl;
- cout << "Next command?" << endl;
- }
- else if (choice == '6') // end and close program
- {
- cout << "Program closed" << endl;
- contactlist.close();
- cout << "Next command?" << endl;
- }
- else
- cout << "You tripped, hahahaha" << endl;
- }
- cout << "Next command?" << endl;
- }
- int main()
- {
- char prompt;
- string filename;
- cout << "Name contact list filename" << endl;
- cin >> filename;
- filename += ".txt";
- fstream contactlist(filename);
- if (contactlist.is_open())
- cout << "Contact list present" << endl;
- else
- {
- ofstream contactlist(filename);
- cout << "Contact list created" << endl;
- }
- cout << "Display menu?" << endl;
- cin >> prompt;
- if (prompt == 'y' || prompt == 'Y')
- menu(filename);
- else
- cout << "Your loss" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement