Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Justin Kirsche
- * 4002-210 Lab 1 Excercise 4
- */
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <iomanip>
- #include <algorithm>
- using namespace std;
- //prototype
- int openFile(ifstream &fin);
- //main
- int main ()
- {
- const int pos1=0;
- string filename;
- ifstream fin;
- string info;
- string name;
- string address;
- string city;
- string state;
- string zip;
- string full;
- //calling on the function
- openFile(fin);
- getline(fin,info);
- //formatting data
- for(int i=0;i<1;i++)
- {
- //Find Name
- if(info.find(',')>0)
- {
- int pos2=info.find(',');
- name=info.substr(pos1,pos2);
- info.erase(pos1,pos2+1);
- }
- //Find Address
- if(info.find(',')>0)
- {
- int pos2=info.find(',');
- address=info.substr(pos1,pos2);
- info.erase(pos1,pos2+1);
- }
- //Find City
- if(info.find(',')>0)
- {
- int pos2=info.find(',');
- city=info.substr(pos1,pos2);
- info.erase(pos1,pos2+1);
- }
- //Find State
- if(info.find(',')>0)
- {
- int pos2=info.find(',');
- state=info.substr(pos1,pos2);
- info.erase(pos1,pos2+1);
- }
- //Find Zip and validate
- if(info.find(',')>0)
- {
- int pos2=info.find(',');
- zip=info.substr(pos1,pos2);
- info.erase(pos1,pos2+1);
- }
- //Concatenate
- full= city + ", " + state + " " +zip;
- //output
- cout <<name<<"\n"<<address<<"\n"<<full<<endl;
- if((zip.length()==5)||(zip.length()==10))
- {
- cout << "Your zip code is valid."<<endl;
- }
- else
- cout << "Your zip code is invalid."<<endl;
- cout<<"----------"<<endl;
- getline(fin,info);
- }
- system("pause");
- return 0;
- }
- //Open File Function
- int openFile(ifstream &fin)
- {
- do{
- string filename;
- cout <<"Enter file name:";
- cin>>filename;
- fin.open(filename.c_str());
- if(!fin.is_open())
- {
- cerr <<"Unable to open file"<<endl;
- fin.clear();
- }
- }
- while(!fin.is_open());
- return 0;
- }
Add Comment
Please, Sign In to add comment