1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include<iostream>
#include<fstream>
#include<limits>
using namespace std;
int main()
{
string c, s, t, u, b;
bool a = true;
char d, e;
char g;
system("TITLE Address Book Maker");
cout << "Welcome to the Address Book Maker!\nRules and Help Regarding Filenames\n 1. When naming a file you MUST put \".txt\" at the end.\n 2. To load a previous address book, type the EXACT name and put \".txt\" at the\n end(unless already there).\n";
cout << "Ok! Now, hit ENTER to start.";
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
system("cls");
cout << "What will you call your Address Book file/What Address Book will you load?\n";
getline(cin, c);
cout << "Erase all contents? [y/n] (n) ";
cin >> e;
if(e == 'y' || e == 'Y')
ofstream streamone(c.c_str(), ios::trunc);
else
ofstream streamone(c.c_str(), ios::app);
cout << "Excellent! ";
do
{
cout << "Now, enter a person's first and last name. ";
cin >> s >> t;
cout << "Input their full address (ex. 123 Road Rd. Boston, MA (insert zip code here)). ";
getline (cin, u);
getline (cin, u);
cout << "Enter their phone number: ";
cin >> b;
if( streamone.fail() ){
cout << "Failed to open " << c << endl;
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
cout << "Press ENTER to exit...\n";
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
return 0;}
streamone << s << " " << t << "'s address is" << endl;
streamone << u << " and his phone number is" << endl;
streamone << b << "." << endl << "---------------------------------------------------" << endl;
cout << "The program will show this:\n" << s << " " << t << "'s address is" << endl << u << " and his phone number is" << endl << b << "." << endl << endl;
do{
cout << "Restart? (y or n) ";
cin >> d;
if(d == 'y' || d == 'Y')
continue;
else if(d == 'n' || d == 'N')
a = false;
}while (d != 'y' && d != 'Y' && d != 'n' && d != 'N');
streamone.close();
}while(a);
}
|