-
driver
driver
Code:
#include <string.h>
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include "building.h"
void main()
{
building b[12];
char userLocA[10];
char userLocB[10];
ifstream input_file;
input_file.open("paths.txt");
if(input_file.fail())
{
cout <<"Input file could not be opened.\n";
exit(1);
}
for(int index=0; index<12; index++)
{
b[index].intLocationOne(input_file.getline());
b[index].intLocationTwo(input_file.getline());
b[index].setPath(input_file.getline());
}
cout <<"\nCAMPUS DIRECTIONS!\n";
cout <<"Here are your building choices:\n";
cout <<"Student Center, Weaver, CTLM, and Coolbaugh\n";
cout <<"Where are you now?";
cin >> userLocA;
cout <<"Where do you want to go?";
cin >> userLocB;
for (int 12)
{
if ((strcmp(userLocA, r[index].getLocation1()))&&(strcmp(userLocB, r[index.getLocation2()))))
{
cout << "Here are your directions:" << b[index].getPath();
break;
}
}
}
-
Driver File
Ok I got my header and definition files finally worked out and now I just need help with the driver here is the driver.
Code:
#include <string.h>
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include "building.h"
void main()
{
building b[12];
char userLocA[10];
char userLocB[10];
ifstream input_file;
input_file.open("paths.txt");
if(input_file.fail())
{
cout <<"Input file could not be opened.\n";
exit(1);
}
for(int index=0; index<12; index++)
{
b[index].intLocationOne(input_file.getline(getPath,120));
b[index].intLocationTwo(input_file.getline());
b[index].setPath(input_file.getline());
}
cout <<"\nCAMPUS DIRECTIONS!\n";
cout <<"Here are your building choices:\n";
cout <<"Student Center, Weaver, CTLM, and Coolbaugh\n";
cout <<"Where are you now?";
cin >> userLocA;
cout <<"Where do you want to go?";
cin >> userLocB;
for (int i=0; index<12; i++)
{
if ((strcmp(userLocA, b[index].getLocationOne()))&&(strcmp(userLocB, b[index.getLocationTwo()))))
cout << "Here are your directions:" << b[index].getPath();
break;
}
}
-
your driver looks good as far as the logic goes (although you might want to add a cout << "cannot find buildings" or something if none of the entries match.
what you need to do now is check syntax. the getline function does not return the line, it puts the line into the variable passed...
getline(line); // the data read in will be stored in 'line'
you may need to use a temp variable to read the line into so you can pass it to your 'set' functions.
-
?
I can get this to compile but i am getting a segmentation fault error what do you think about the getline fxn now?
Code:
//Name: Joseph Valenzuela
//Date: 04/28/03
//Purpose: The driver for project2
#include <string.h>
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include "building.h"
void main()
{
building b[12];
char userLocA[10];
char userLocB[10];
ifstream input_file;
input_file.open("paths.txt");
if(input_file.fail())
{
cout <<"Input file could not be opened.\n";
exit(1);
}
char* buffer;
for(int index=0; index<12; index++)
{
input_file.getline(buffer,255);
b[index].intLocationOne(buffer);
input_file.getline(buffer,255);
b[index].intLocationTwo(buffer);
input_file.getline(buffer,255);
b[index].setPath(buffer);
}
cout <<"\nCAMPUS DIRECTIONS!\n";
cout <<"Here are your building choices:\n";
cout <<"Student Center, Weaver, CTLM, and Coolbaugh\n";
cout <<"Where are you now?";
cin >> userLocA;
cout <<"Where do you want to go?";
cin >> userLocB;
/*
for (int i=0; index<12; i++)
{
if ((strcmp(userLocA, b[index].getLocationOne()))&&(strcmp(userLocB, b[index.getLocationTwo()))))
cout << "Here are your directions:" << b[index].getPath();
break;
}
*/
}
-
What do you think? I have to turn this in by midnight and its getting nowhere. Do you have AOL instant messanger or yahoo or MSN or something, I could really use some one on one I am so close.
-
the getline() looks good. you just have to get the comparing right (which i noticed you have another thread for, that should come together ok) i would give you my icq and help one on one but im on my way out and wont be home untill later tonight. srry. im sure the others around here can give you a hand.