Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include "contacts.h"
using namespace std;
int main()
{
addressBook MyaddressBook;
ofstream outfile;
outfile.open("/Users/peterjocham/Desktop/textoutput.txt",ios::app);
ifstream infile("/Users/peterjocham/Desktop/textoutput.txt",ios::in);
if (outfile.fail()) {
cerr<<"File couldn't be opened";
exit(EXIT_FAILURE);
}
int userInput=0;
nodePtr temp=new node;
string NAME;
MyaddressBook.userPromptStatement();
while (!outfile.eof()) {
infile>>temp->name>>temp->last>>temp->age;
}
while(1)
{
cin>>userInput;
if (!cin || (userInput!=1 && userInput!=2 && userInput!=3 && userInput!=4 &&userInput!=5))
{
cin.ignore();
cout<<"Only enter a 1,2,3,4, or 5"<<endl;
cout<<"You have entered an incorrect value."<<endl;
cout<<endl<<endl;
MyaddressBook.userPromptStatement();
continue;
}
switch (userInput) {
case 1:
cout<<"NAME: ";
cin.ignore();
getline(cin,temp->name,'\n');
cout<<"\nLAST NAME: ";
getline(cin,temp->last,'\n');
cout<<"\nAGE: ";
cin>>temp->age;
outfile<<
"FIRST NAME: "<<setw(2)<<temp->name<<"\n"
<<setw(2)<<"LAST NAME: "<<temp->last<<"\n"
<<setw(2)<<"AGE: "<<temp->age<<"\n\n";
MyaddressBook.addContact(temp);
MyaddressBook.userPromptStatement();
cout<<"\n"<<"\n";
break;
case 2:
cout<<"Which contact would you like to delete?\n";
cin>>NAME;
MyaddressBook.deleteName(NAME);
MyaddressBook.userPromptStatement();
cout<<"\n"<<"\n";
break;
case 3:
MyaddressBook.editName(NAME);
break;
case 4:
MyaddressBook.printContactList();
MyaddressBook.userPromptStatement();
cout<<"\n"<<"\n";
break;
case 5:
outfile.close();
exit(EXIT_SUCCESS);
default:
break;
}
}
return 0;
}
Lines 29-32 I have a good feeling very wrong. Now I have never learned how to do this and my book covers nothing over this. I just took my final in C++ so this is not homework. I am trying to get better before Data Structures start next month.
Can I please have a pointer?