May 17, 2014 at 6:39am UTC
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
//Header Files
#include "Car.h"
/***********Class String of Cars*****************/
class StringOfCars
{
private:
Car** vehicle;
static const int ARRAY_MAX_SIZE = 10;
int currentSize;
public:
//constructor
StringOfCars()
{
vehicle = new Car*[ARRAY_MAX_SIZE];
currentSize = 0;
}
StringOfCars(Car **obj)
{
for(int i = 0; i < ARRAY_MAX_SIZE; i ++)
{
vehicle[i] = new Car;
vehicle[i] = obj[i];
}
}
//destructor
~StringOfCars()
{
};
//output
void output();
//push
void push(Car *);
//pop
void pop();
};
void StringOfCars::push(Car * car1)
{
cout << "******PUSH FUNCTION******\n";
cout << "Inputing contents in to vehicle[" << currentSize << "]\n";
vehicle[currentSize] = car1;
vehicle[currentSize]->output();
cout << "what is the current size? " << currentSize << endl;
currentSize++;
//testing
int i = 0;
cout << "\n\nTESTING---------\n\n";
while (i < currentSize)
{
cout << "\nvehicle[" << i << "]: \n";
vehicle[i]->output();
i++;
}
cout << "\n\nEND TESTING---------\n\n";
}
void StringOfCars::pop()
{
delete vehicle[currentSize--];
}
void StringOfCars::output()
{
for(int i=0; i < currentSize; i++)
{
cout << "Current size is : " << currentSize << endl;
cout << "Car " << i+1 << ":" << endl;
//if( )
//{
//vehicle[0]->output(); //fix this
cout << vehicle[i]->getRep() << endl;
cout << vehicle[i]->getCarNumber() << endl;
cout << vehicle[i]->getKind() << endl;
cout << vehicle[i]->getLoaded() << endl;
cout << vehicle[i]->getDestination() << endl;
//}
//else
//{
// cout << "NO cars" << endl;
//}
}
}
//function prototypes
void input(StringOfCars&);
/*********************************Main*********************
*/
int main()
{
//input();
//Tests
cout << "Print: TEST 1" << endl;
Car car1("SP", 34567, "box", true, "Salt Lake City");
Car car2(car1);
car2.output();
cout << "Print: TEST 2" << endl;
StringOfCars string1;
input(string1);
string1.output();
return 0;
}
void input(StringOfCars &string1)
{
string rep;
string type;
string dest;
string loadString;
int carNum;
bool load;
ifstream inputFile;
inputFile.open("input.txt");
if(inputFile.fail())
{
//Error Message
cerr << "Error: File not found" << endl;
exit(EXIT_FAILURE);
}
string typeCar;
while(inputFile.peek() != EOF)
{
while(inputFile.peek() == ' ')
{
inputFile.get();
}
inputFile >> typeCar;
inputFile >> rep;
inputFile >> carNum;
inputFile >> type;
inputFile >> loadString;
getline(inputFile, dest);
Car temp(rep, carNum, type, load, dest);
Car *carptr = &temp;
string1.push(carptr); //fix this
}
inputFile.close();
}
bool operator== (const Car &car1, const Car &car2)
{
return (car1.getRep() == car2.getRep() && car1.getCarNumber() == car2.getCarNumber());
}
Last edited on May 17, 2014 at 8:26am UTC
May 17, 2014 at 8:29am UTC
|8|fatal error: Car.h: No such file or directory|
#include "Car.h" give the error here and It does not show me output?
May 17, 2014 at 8:52am UTC
Do you have a file named Car.h?
May 25, 2014 at 8:01am UTC
I could not understand can you fix my error? what should do Right know.
Last edited on May 25, 2014 at 8:01am UTC
May 25, 2014 at 10:02am UTC
can anyone correct for me
May 25, 2014 at 10:38am UTC
You are including a file called "Car.h ", yet it doesn't exist. We can't write this header file for you - for one, we can only guess what it is supposed to do. We won't do your work for you.
May 27, 2014 at 9:01pm UTC
can anyone tell me what should i do in header i have NO idea?
please help me.
still Give error
May 27, 2014 at 10:32pm UTC
My solution is to not use header files, if you aren't certain of how to.
Below is your source code and header merged(from your multiple posts):
Code is large, so I've posted it on pastie: http://pastie.org/9226015
(If you do not wish to share the code, simply click the copy/repaste button, delete everything, and click create paste; it'll delete everything or inform me through post and i'll delete it asap)
Other than that, with your provided code, the output is:
Print: TEST 1
reportingMark SP
carNumber 34567
kind box
loaded true
destination Salt Lake City
Print: TEST 2
Error: File not found
Process returned 1 (0x1) execution time : 0.019 s
Press any key to continue.
Last edited on May 27, 2014 at 10:33pm UTC
May 28, 2014 at 3:45am UTC
Aww Thank you . I look at and you really really help me. I have nothing to say just thanks .