Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.Please help me debugging my program. 2. Please help me with the makefile to li

ID: 3592336 • Letter: 1

Question

1.Please help me debugging my program.

2. Please help me with the makefile to link them together.

this is my Person.h

// Create header file Person.h with
#ifndef PERSON_H_
#define PERSON_H_
#include <string>
#include <iostream>

using namespace std;

class Person
{
   public:
       Person();
       Person(int p,string nam,string sd,string ed,string par,int by,int dy);
       //
       int getPresidency();
       int getBirthYear();
       int getdeceasedYear();
       string getname();
       string getstartDate();
       string getendDate();
       string getParty();
      
   private:
       int presidency, birthYear, deceasedYear;
       string name, startDate, endDate, party;
};

#endif

This is my Person.cpp below

#include "Person.h"
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>

using namespace std;

Person::Person()
{
  
}

Person::Person(int p,string nam,string sd,string ed,string par,int by,int dy)
{
   presidency=p;
   birthYear=by;
   deceasedYear=dy;
   name=nam;
   startDate=sd;
   endDate=ed;
   party=par;
}

//Ways to get the values

int Person::getPresidency()

{
   return presidency;
}

int Person::getBirthYear()

{
   return birthYear;
}

int Person::getdeceasedYear()

{
   return deceasedYear;
}

string Person::getname()

{
   return name;
}

string Person::getstartDate()

{
   return startDate;
}

string Person::getendDate()

{
   return endDate;
}

string Person::getParty()

{
   return party;
}

string trimSpace(const std::string& inStr,const
std::string& spaceChar = " ") //comment
{
   const auto beginOfString = inStr.find_first_not_of(spaceChar);
   if (beginOfString == std::string::string::npos)
       return "";
      
   const auto endOfString =
inStr.find_last_not_of(spaceChar);
   const auto rangeOfString = endOfString - beginOfString + 1;
  
   return inStr.substr(beginOfString, rangeOfString);//comment
}

//Ways to search by name
void searchByName(vector<Person*> &per)
{
   string name;
   cout<<"Please enter the name: ";
   cin.ignore();
   getline(cin,name);
   for(int=0;i<per.size();i++)
   {
       string str=per.at(i)->getname();
       std::size_t found = str.find(name);
       if (found!=std::string::npos)//comment
       {
           cout<<"Name: "<<per.at(i)->getname();
           cout<<"("<<per.at(i)->getBirthYear()<<"-";
          
           if(per.at(i)->getdeceasedYear()>0)
               cout<<per.at(i)->getdeceasedYear()<<")";
           else
               cout<<"Present )";
              
           int age;
          
           if(per.at(i)->getdeceasedYear()>0)
               age=per.at(i)->getdeceasedYear()-per.at(i)->getBirthYear();
           else
               age=2017-per.at(i)->getBirthYear();
              
               cout<<" Age: "<<age<<endl;
              
               cout<<"Presidency #"<<per.at(i)->getPresidency();
              
                   cout<<"from"<<per.at(i)->getstartDate();
                  
           if(per.at(i)->getendDate() !="0")
                  
                   cout<<" to "<<per.at(i)->getendDate();
                  
           else
               cout<<" to present";
              
               cout<<" Party: "<<per.at(i)->getParty()<<endl;
           }
       }
   }
  
//Ways to search by presidency

void searchByPresidency(vector<Person*> &per)
{
   int pre;
  
   cout<<"Please enter the presidency term: ";
   //cin.ignore();
   cin>>pre;
   for(int i=0;i<per.size();i++)
   {
       int prec=per.at(i)->getPresidency();
       if (pre==prec)
       {
           cout<<"Name: "<<per.at(i)->getname();
           if (pre==prec)
           {
               cout<<"Name: "<<per.at(i)->getname();
               cout<<"("<<per.at(i)->getBirthYear()<<"-";
              
           if(per.at(i)->getdeceasedYear()>0)
               cout<<per.at(i)->getdeceasedYear()<<")";
           else
               cout<<"Present )";
              
           int age;
           if (per.at(i)->getdeceasedYear()>0)
               age=per.at(i)->getdeceasedYear()-per.at(i)->getBirthYear();
           else
               age=2017-per.at(i)->getBirthYear();
              
           cout<<"Age: "<<age<<endl;
          
           cout<<"Precedency #"<<per.at(i)->getPresidency();
          
               cout<<" from "<<per.at(i)->getstartDate();
              
           if(per.at(i)->getendDate()!="0")
          
               cout<<" to "<<per.at(i)->getendDate();
           else
               cout<<" to present";
              
               cout<<" Party: "<<per.at(i)->getParty()<<endl;
              
           }
       }
   }
  
//Ways to search by party
void searchByParty(vector<Person*> &per)
{
   string party;
   cout<<"Please enter the party: ";
   cin>>party;
   for(int i=0;i<per.size();i++)
  
   {
       string par=per.at(i)->getParty();
       if (par==party)
      
       {
           cout<<"Name: "<<per.at(i)->getname();
           cout<<"("<<per.at(i)->getBirthYear()<<"-";
          
       if(per.at(i)->getdeceasedYear()>0)
           cout<<per.at(i)->getdeceasedYear()<<")";
       else
       cout<<"Present )";
      
       int age;
       if(per.at(i)->getdeceasedYear()>0)
           age=per.at(i)->getdeceasedYear()-per.at(i)->getBirthYear();
       else
           age=2017-per.at(i)->getBirthYear();
          
       cout<<" Age: "<<age<<endl;
       cout<<" Precedency #"<<per.at(i)->getPresidency();
       cout<<" from "<<per.at(i)->getstartDate();
      
               if(per.at(i)->getendDate() !="0")
                  
                   cout<<" to "<<per.at(i)->getendDate();
               else
              
                   cout<<" to present";
                  
               cout<<" Party: "<<per.at(i)->getParty()<<endl;
              
           }
       }
   }
  
// required way
int mai(int argc, char * argv[])
{
   vector<Person*>persons;
   if(argc<1)
   {
       cout<<"The file should pass as comman line argument"<<endl;
           return 0;
   }
   ifstream myfile;
   myfile.open(argv[1]);
   string str;
   string nam,stddy,enddy,pty;
   int pres,biry,decy
   int i=0;
  
//open and process the files
if(myfile.is_open())
{
   while(myfile)
   {
      
       if(!getline(myfile,str))
           break;
       istringstream split(str);
       string st="";
       vector<string>tokens;
       while(split)
       {
           string s;
           if(!getline(split,s,';'))
               break;
           else
           {
               string str1=trimSpace(s);
               token.push_back(str1);
           }
          
       }
       string pre=tokens.at(0);
       istringstream ss(pre);
       ss>>pres;
       nam=tokens.at(1);
       stddy=token.at(2);
       enddy=token.at(3);
       pty=token.at(4);
       string birthy=tokens.at(5);
       istringstream ss1(birthy);
       ss1>>biry;
       string decey=tokens.at(6);
       istringstream ss2(decey);
       ss2>>decey;
       Person *p=new
   Person(pres,nam,stddy,enddy,pty,biry,decy);
       persons.push_back(p);
      
      
       i++;
   }
}

int ch;

//do while loop to process the inputs
do
{
   cout<<"1. Search Person's information based on name"<<endl;
   cout<<"2. Search Person's information based on presidency"<<endl;
   cout<<"3. Search Person's information based on political party"<<endl;
   cout<<"4. Exit"<<endl;
   cout<<"Please enter the choice: ";
   cin>>ch;
   switch(ch)
   {
       case 1: searchByName(persons);
           break;
       case 2: SearchByPresidency(persons);
           break;
       case 3: searchByParty(persons);
           break;
       case 4: break;
   }
}
   while(ch!=4);
   system("pause");
   return 0;
  
}
           This is my Printmefirst.h

#ifndef PRINTMEFIRST_H_
#define PRINTMEFIRST_H_

#include <string>
#include <iostream>

void printMeFirst(std::string name,std::string courseInfor);

#endif

This is my PrintMeFirst.cpp

#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <iomanip>
#include <cmath>
#include <ctime>
#include "Printmefirst.h"
using namespace std;

/* Print out the programmer's information such as name, class information and dat/time when the program is run

@param name- the name of the programmer
@param couselnfor- the name of the course
@return- none
*/

void printMeFirst(string name,string courseInfor)
   {
   cout<<"Program written by:"<<name<<endl;
   cout<<"Course infor:"<<courseInfor<<endl;
   time_t now=time(0);
   char* dt= ctime(&now);
   cout<<"Date:"<< dt <<endl;
   }

Explanation / Answer

This is your make file.

CC=g++

all : PrintMeFirst.o Person.o

$(CC) -o all PrintMeFirst.o Person.o #put take is it is not there

------------------------------------------------------------------------------------------------

This is the code compiling properly . please go threw it. I did'nt check whole code. But i can say that it is working properly.

In code there is some small mistacks like token instad of tokens like that. some where there is not defined i .Please go threw code .  

Person.h

// Create header file Person.h with
#ifndef PERSON_H_
#define PERSON_H_
#include <string>
#include <iostream>
using namespace std;
class Person
{
public:
Person();
Person(int p,string nam,string sd,string ed,string par,int by,int dy);
//
int getPresidency();
int getBirthYear();
int getdeceasedYear();
string getname();
string getstartDate();
string getendDate();
string getParty();
  
private:
int presidency, birthYear, deceasedYear;
string name, startDate, endDate, party;
};
#endif

Person.cpp

#include "Person.h"

#include <string>

#include <iostream>

#include <fstream>

#include <sstream>

#include <vector>

#include <stdlib.h>

using namespace std;

Person::Person()

{

}

Person::Person(int p,string nam,string sd,string ed,string par,int by,int dy)

{

presidency=p;

birthYear=by;

deceasedYear=dy;

name=nam;

startDate=sd;

endDate=ed;

party=par;

}

//Ways to get the values

int Person::getPresidency()

{

return presidency;

}

int Person::getBirthYear()

{

return birthYear;

}

int Person::getdeceasedYear()

{

return deceasedYear;

}

string Person::getname()

{

return name;

}

string Person::getstartDate()

{

return startDate;

}

string Person::getendDate()

{

return endDate;

}

string Person::getParty()

{

return party;

}

string trimSpace(const std::string& inStr,const

std::string& spaceChar = " ") //comment

{

const auto int beginOfString = 0 ; // to find range directly take 0

if (beginOfString == NULL)

return "";

const auto int endOfString = spaceChar.size(); // spaceChar.sizewill give you last char number

const auto int rangeOfString =endOfString - beginOfString + 1; // substaract it and find the range

return inStr.substr((int )beginOfString,(int) rangeOfString);//pass it to find sub string

}

//Ways to search by name

void searchByName(vector<Person*> &per)

{

string name;

cout<<"Please enter the name: ";

cin.ignore();

getline(cin,name);

for(int i=0;i<per.size();i++)

{

string str=per.at(i)->getname();

std::size_t found = str.find(name);

if (found!=std::string::npos)//comment

{

cout<<"Name: "<<per.at(i)->getname();

cout<<"("<<per.at(i)->getBirthYear()<<"-";

if(per.at(i)->getdeceasedYear()>0)

cout<<per.at(i)->getdeceasedYear()<<")";

else

cout<<"Present )";

int age;

if(per.at(i)->getdeceasedYear()>0)

age=per.at(i)->getdeceasedYear()-per.at(i)->getBirthYear();

else

age=2017-per.at(i)->getBirthYear();

cout<<" Age: "<<age<<endl;

cout<<"Presidency #"<<per.at(i)->getPresidency();

cout<<"from"<<per.at(i)->getstartDate();

if(per.at(i)->getendDate() !="0")

cout<<" to "<<per.at(i)->getendDate();

else

cout<<" to present";

cout<<" Party: "<<per.at(i)->getParty()<<endl;

}

}

}

//Ways to search by presidency

void searchByPresidency(vector<Person*> &per)

{

int pre;

cout<<"Please enter the presidency term: ";

//cin.ignore();

cin>>pre;

for(int i=0;i<per.size();i++)

{

int prec=per.at(i)->getPresidency();

if (pre==prec)

{

cout<<"Name: "<<per.at(i)->getname();

if (pre==prec)

{

cout<<"Name: "<<per.at(i)->getname();

cout<<"("<<per.at(i)->getBirthYear()<<"-";

if(per.at(i)->getdeceasedYear()>0)

cout<<per.at(i)->getdeceasedYear()<<")";

else

cout<<"Present )";

int age;

if (per.at(i)->getdeceasedYear()>0)

age=per.at(i)->getdeceasedYear()-per.at(i)->getBirthYear();

else

age=2017-per.at(i)->getBirthYear();

cout<<"Age: "<<age<<endl;

cout<<"Precedency #"<<per.at(i)->getPresidency();

cout<<" from "<<per.at(i)->getstartDate();

if(per.at(i)->getendDate()!="0")

cout<<" to "<<per.at(i)->getendDate();

else

cout<<" to present";

cout<<" Party: "<<per.at(i)->getParty()<<endl;

}

}

}

}

//Ways to search by party

void searchByParty(vector<Person*> &per)

{

string party;

cout<<"Please enter the party: ";

cin>>party;

for(int i=0;i<per.size();i++)

{

string par=per.at(i)->getParty();

if (par==party)

{

cout<<"Name: "<<per.at(i)->getname();

cout<<"("<<per.at(i)->getBirthYear()<<"-";

if(per.at(i)->getdeceasedYear()>0)

cout<<per.at(i)->getdeceasedYear()<<")";

else

cout<<"Present )";

int age;

if(per.at(i)->getdeceasedYear()>0)

age=per.at(i)->getdeceasedYear()-per.at(i)->getBirthYear();

else

age=2017-per.at(i)->getBirthYear();

cout<<" Age: "<<age<<endl;

cout<<" Precedency #"<<per.at(i)->getPresidency();

cout<<" from "<<per.at(i)->getstartDate();

if(per.at(i)->getendDate() !="0")

cout<<" to "<<per.at(i)->getendDate();

else

cout<<" to present";

cout<<" Party: "<<per.at(i)->getParty()<<endl;

}

}

}

// required way

int main(int argc, char * argv[])

{

vector<Person*>persons;

if(argc<1)

{

cout<<"The file should pass as comman line argument"<<endl;

return 0;

}

ifstream myfile;

myfile.open(argv[1]);

string str;

string nam,stddy,enddy,pty;

int pres,biry,decy;

int i=0;

//open and process the files

if(myfile.is_open())

{

while(myfile)

{

if(!getline(myfile,str))

break;

istringstream split(str);

string st="";

vector<string> tokens;

while(split)

{

string s;

if(!getline(split,s,';'))

break;

else

{

string str1=trimSpace(s);

tokens.push_back(str1);

}

}

string pre=tokens.at(0);

istringstream ss(pre);

ss>>pres;

nam=tokens.at(1);

stddy=tokens.at(2);

enddy=tokens.at(3);

pty=tokens.at(4);

string birthy=tokens.at(5);

istringstream ss1(birthy);

ss1>>biry;

string decey=tokens.at(6);

istringstream ss2(decey);

ss2>>decey;

Person *p=new

Person(pres,nam,stddy,enddy,pty,biry,decy);

persons.push_back(p);

i++;

}

}

int ch;

//do while loop to process the inputs

do

{

cout<<"1. Search Person's information based on name"<<endl;

cout<<"2. Search Person's information based on presidency"<<endl;

cout<<"3. Search Person's information based on political party"<<endl;

cout<<"4. Exit"<<endl;

cout<<"Please enter the choice: ";

cin>>ch;

switch(ch)

{

case 1: searchByName(persons);

break;

case 2: searchByPresidency(persons);

break;

case 3: searchByParty(persons);

break;

case 4: break;

}

}

while(ch!=4);

system("pause");

return 0;

}

PrintMefirst.h

#ifndef PRINTMEFIRST_H_
#define PRINTMEFIRST_H_
#include <string>
#include <iostream>
void printMeFirst(std::string name,std::string courseInfor);
#endif

PrintMefirst.cpp

#include <iostream>

#include <stdio.h>

#include <ctype.h>

#include <iomanip>

#include <cmath>

#include <ctime>

#include "Printmefirst.h"

using namespace std;

/* Print out the programmer's information such as name, class information and dat/time when the program is run

@param name- the name of the programmer

@param couselnfor- the name of the course

@return- none

*/

void printMeFirst(string name,string courseInfor)

{

cout<<"Program written by:"<<name<<endl;

cout<<"Course infor:"<<courseInfor<<endl;

time_t now=time(0);

char* dt= ctime(&now);

cout<<"Date:"<< dt <<endl;

}