proper order in a program using classes

I have a problem with arrangement on a program. I can't seem to put the pieces in the correct order.  I want to keep it short so here is a code snippet.  the program reads in an input file, does some sanity checks on the variables and outputs to the outfile. I have only included one of the variables(title).  I'm new to this game, please be considerate.  
#include <iostream>
#include <fstream>
#include <string>

using namespace std;
const int max = 10;
int count = -1;
int i,j;
string data [max];
string colon = ":";
ifstream infile;
ofstream outfile;

class Address{
public:
string title,newstring;
      
public:
Address () {
title = "Mr. or Mrs.";   //default constructor
      }
Address (string myTitle) {
               setTitle(myTitle) ;
                          }

void setTitle (string myTitle) {
if(myTitle == "Mr." || myTitle =="Dr." ||
 myTitle == "Miss" || myTitle =="Mrs." )
title = myTitle;
else
cout<<"you have entered an incorrect title \n";
cout << title;
      }

string gettitle () {
return title;
      }
      };
cout << endl;

int main () {
      infile.open ("strings.txt");
      if (!infile){
      cout <<"Cannot access the input file.\n";
      exit(-1);
      }
      while ( count < max && infile >> data [++ count ]);
      infile.close();

      cout<<"the addresses from the input data file are: " << "\n\n";
      for (i=0;i<count;i++) {
            cout << data[i] << endl;
            j= data[i].find(colon);
            title = data[i].substr(0,j);
            cout << title << endl;
            newstring = data[i].erase(0,j+1);

            j= data[i].find(colon);
            name = data[i].substr(0,j);
            cout<<name<<endl;
            newstring = data[i].erase(0,j+1);

            j= data[i].find(colon);
            street = data[i].substr(0,j);
            cout<<street<<endl;
            newstring = data[i].erase(0,j+1);

            j= data[i].find(colon);
            city = data[i].substr(0,j);
            cout<<city<<endl;
            newstring = data[i].erase(0,j+1);

            j= data[i].find(colon);
            state = data[i].substr(0,j);
            cout<<state<<endl;
            newstring = data[i].erase(0,j+1);

            zip = (0,j);
            cout<<zip<<endl;
            
      }
      outfile.open("outfile.txt");
      if(!outfile) {
      cout<<"cannot open the output file.\n";
      exit(-2);

      for (i=0;i<count;i++)
      outfile << data[i]  << endl;
      outfile.close();

      return 0;
}
police45sAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AxterCommented:
Exactly what is your question?
0
police45sAuthor Commented:
putting this puzzle in the proper order so it can run
0
AxterCommented:
That's not a question.

Your post is vaque and ambiguous.

Please post a specific question.

0
police45sAuthor Commented:
my question would be the following:  how can the above program be restructured so to allow it to be executed properly?  The confusion presents itself when class address is added.    
0
HendrikTYRCommented:
It at least compiles if you go this route:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;
const int MAX = 10;
int count = -1;
int i,j;
string data [MAX];
string colon = ":";
ifstream infile;
ofstream outfile;

class Address{
public:
string title,newstring;
     
public:
Address () {
title = "Mr. or Mrs.";   //default constructor
     }
Address (string myTitle) {
               setTitle(myTitle) ;
                         }

void setTitle (string myTitle) {
if(myTitle == "Mr." || myTitle =="Dr." ||
 myTitle == "Miss" || myTitle =="Mrs." )
title = myTitle;
else
cout<<"you have entered an incorrect title \n";
cout << title;
     }

string gettitle () {
return title;
     }
     };

int main () {
     infile.open ("strings.txt");
     if (!infile){
     cout <<"Cannot access the input file.\n";
     exit(-1);
     }
     while ( count < MAX && infile >> data [++ count ]);
     infile.close();

     cout<<"the addresses from the input data file are: " << "\n\n";
     for (i=0;i<count;i++) {
         Address addr;
          cout << data[i] << endl;
          j= data[i].find(colon);
          addr.setTitle(data[i].substr(0,j));
          cout << addr.gettitle() << endl;

         
     }
     outfile.open("outfile.txt");
     if(!outfile) {
     cout<<"cannot open the output file.\n";
     exit(-2);
     }

     for (i=0;i<count;i++)
     outfile << data[i]  << endl;
     outfile.close();

     char ch;
     cin.get(ch);

     return 0;
}


Regards
Hendrik
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.