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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
#include <iostream.h>
#include <stdlib.h>
#include <fstream.h>
#include <iomanip>
using namespace std;
int write(void);
int write(void)
{
ofstream outfile;
char firstname[18],
lastname[25],
address[28],
city[18],
state[3],
zipcode[6],
phonenumber[11];
int index;
outfile.open("textfile2.txt.txt",ios::app);
cout<<"Enter your First Name: ";
cin>>firstname;
cin.ignore();
cout<<"Enter your Last Name: ";
cin>>lastname;
cin.ignore();
cout<<"Enter your Address: ";
cin.getline(address, sizeof(address));
cin.ignore();
cout<<"Enter your City: ";
cin.getline(city, 18);
cout<<"Enter your State: ";
cin.getline(state, sizeof(state));
cin.ignore();
cout<<"Enter your ZipCode: ";
cin.getline(zipcode, 6);
cout<<"Enter your Phone Number: ";
cin.getline(phonenumber, sizeof(phonenumber));
cin.ignore();
outfile<<firstname<<setw(2)<<lastname<<setw(2)<<address<<setw(2)<<city<<setw(2)<<state<<setw(2)<<zipcode<<setw(2)<<phonenumber<<endl;
outfile.close();
cout<<"Writing Completed."<<endl;
return 0;
}
int read(void);
int read(void)
{
ifstream input;
input.open("L:\\BU-521\\textfile2.txt.txt",ios::in);
char firstname[18],
lastname[25],
address[28],
city[18],
state[3],
zipcode[6],
phonenumber[11];
int counter =1;
while(!input.eof())
{
input>>firstname>>lastname>>address>>city>>state>>zipcode>>phonenumber;
cout<<"Information Required. "<<endl;
cout<<firstname<<setw(1)<<lastname<<endl;
cout<<address<<endl;
cout<<city<<setw(2)<<state<<setw(2)<<zipcode<<endl;
cout<<phonenumber<<endl;
counter++;
cout<<endl;
}
cout<<"Reading Completed. "<<endl;
input.close();
return 0;
}
int main()
{
int choice;
char ch;
do{
cout<<endl;
cout<<"Please choose from the following: \n";
cout<<"\t1. Read Data. \n";
cout<<"\t2. Write Data. \n";
cout<<"\t3. Quit. \n";
cout<<endl;
cout<<"Your choice: ";
cin>>choice;
switch(choice)
{
case 1:
read();
break;
case 2:
write();
break;
case 3:
break;
default:
cout<<"\tInvalid entry!"<<endl;
}
cout<<"\nWould you like to try again (y/n): ";
cin>>ch;
}while(ch == 'y' || ch == 'Y');
system("PAUSE");
return 0;
}
|