|
*executing problems
Hi, I'm really sorry about this question, because it is probably so simple, but I've just started C++ and some reason I cannot get my code to execute.
Like its a .cpp file, and it compiles, but when I try to execute it (in MS Visual C++) I get this error
--------------------
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/x.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
x.exe - 2 error(s), 0 warning(s)
--------------------
Am I suppose to do something with a .h file? If so how am I suppose to do it?
Here's my code
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include <iostream>
using namespace std;
class Junkyard
{
private:
int NumBusDoors;
int NumTruckDoors;
int NumCarDoors;
int NumWheels;
public:
Junkyard () {NumBusDoors = 0; NumTruckDoors = 0; NumCarDoors; NumWheels;}
void Junkyard::AddBusDoors(int numDoors) {
NumBusDoors = NumBusDoors + numDoors;
}
void JunkyardAddTruckDoors(int numDoors) {
NumTruckDoors = NumTruckDoors + numDoors;
}
void JunkyardAddCarDoors(int numDoors) {
NumCarDoors = NumCarDoors + numDoors;
}
void JunkyardAddWheels(int numWheels) {
NumWheels = NumWheels + numWheels;
}
void JunkyardAdvertise() { //print the content of the junkyard to the screen in order to show the stocks this junkyard has
cout << "Bus Doors: " << NumBusDoors << "\nTruck Doors: " << NumTruckDoors << "\nCar Doors: " << NumCarDoors << "\nWheels: " << NumWheels;
}
virtual ~Junkyard() {
delete this;
}
};
class Location
{
public:
int x,y;
Location() {
x = 0;
y = 0;
}
virtual ~Location() {
delete this;
}
Location(int a,int b) {
x = a;
y = b;
}
void Location::setLocation (int a, int b) {
x = a;
y = b;
}
};
class Road
{
public:
string RoadName;
Location EntryEndPoint;
Location ExitEndPoint;
enum Direction {East, South} Dir ;
Road() {
RoadName = '\0';
Location EntryEndPoint(0,0);
Location ExitEndPoint(0,0);
Direction Dir = East;
}
Road(string Rname, Location EntryEP, Location ExitEP, Direction aDir)
{
RoadName = Rname;
EntryEndPoint = EntryEP;
ExitEndPoint = ExitEP;
Direction Dir= aDir;
};
virtual ~Road() {
delete this;
}
void setDirEast() {
Dir = East;
}
void setDirSouth() {
Dir = South;
}
};
class Vehicle {
public:
string Name ;
int Speed ;
int LoopsPerM ;
int CurLoopCount ;
int NumWheels ;
int NumDoors ;
Location Position ;
Road* RoadPtr ;
Vehicle () {
Speed = 0;
LoopsPerM = 0;
CurLoopCount = 0;
NumWheels = 0;
NumDoors = 0;
RoadPtr = '\0';
}; //initializes all attributes to zero
Vehicle (string name, int speed, Road* rdPtr) {
LoopsPerM = (int) (3.6/Speed*100);
CurLoopCount = 0;
}
virtual ~Vehicle() {
cout << "vehicle " << Name << " is destroyed";
};
virtual JunkIt(Junkyard &jy) {};
void move (Road* R1, Road* R2) {
CurLoopCount++;
if (CurLoopCount == LoopsPerM) {
if (RoadPtr->Dir == 0) {
Position.x++;
if (Position.x == RoadPtr->ExitEndPoint.x) {
RoadPtr = R2;
Position.x = 500;
Position.y = 1000;
}
}
else { // South
Position.y--;
if (Position.y == RoadPtr->ExitEndPoint.y) {
RoadPtr = R1;
Position.x = 0;
Position.y = 500;
}
}
}
}
};
class Car: public Vehicle{
public:
bool MoonRoof;
Car (string name, int speed, bool MoonRoof, Road* rdPtr ) {
Name = name;
Speed = speed;
MoonRoof = MoonRoof;
RoadPtr = rdPtr;
NumWheels = 4;
NumDoors = 4;
}
Car (string name, int speed, Road* rdPtr) {
Name = name;
Speed = speed;
RoadPtr = rdPtr;
NumWheels = 4;
NumDoors = 4;
}
void JunkIt(Junkyard &jy, int);//update jy’s NumCarDoors and NumWheels using the correspongin public mehtod }
~Car() { cout << "Car " << Name << " is destroyed";} ;
};
void Car::JunkIt (Junkyard &jy, int x = 0) {
jy.JunkyardAddCarDoors(NumDoors);
jy.JunkyardAddWheels(NumWheels);
};
class Bus: public Vehicle{
public:
enum Style {Single, DoubleStories, Attached} BusType ;
Bus (string name, int speed, enum Style bType, Road* rdPtr) {
Name = name;
Speed = speed;
BusType = bType;
RoadPtr = rdPtr;
NumWheels = 6;
NumDoors = 3;
}
Bus (string name, int speed, Road* rdPtr) {
Name = name;
Speed = speed;
RoadPtr = rdPtr;
NumWheels = 6;
NumDoors = 3;
}
void JunkIt(Junkyard &jy, int); //update jy’s NumBusDoors and NumWheels using the correspongin public mehtod }
~Bus() { cout << "Bus " << Name << " is destroyed";} ;
};
void Bus::JunkIt (Junkyard &jy, int x = 0) {
jy.AddBusDoors(NumDoors);
jy.JunkyardAddWheels(NumWheels);
};
class Truck: public Vehicle {
public:
Truck(string name, int speed, Road* rdPtr) : Vehicle(name, speed, rdPtr) {NumWheels = 6; NumDoors = 2;} ;
void JunkIt(Junkyard &jy, int);//update jy’s NumTruckDoors and NumWheels using the correspongin public mehtod}
~Truck() { cout << "Truck " << Name << " is destroyed";} ;
};
void Truck::JunkIt (Junkyard &jy, int x = 0) {
jy.JunkyardAddTruckDoors(NumDoors);
jy.JunkyardAddWheels(NumWheels);
};
class Motorcycle: public Vehicle {
public:
Motorcycle (string name, int speed, Road* rdPtr) : Vehicle(name, speed, rdPtr) {} ;
void JunkIt(Junkyard &jy, int){}; //nothing to be junked }
~Motorcycle() { cout << "Motorcycle " << Name << " is destroyed";} ;
};
int main()
{
Location Epr11(0,500);
Location Epr12(1000,500);
Location Epr21(500,1000);
Location Epr22(500,0);
Road x,y;
x.setDirEast();
Road Road1("Road1", Epr11, Epr12, x.Dir);
y.setDirSouth();
Road Road2("Road2", Epr21, Epr22, y.Dir);
Junkyard MyJunkyard;
Vehicle* Vehicle[12];
Vehicle[0] = new Car("Car1", 30, &Road1);
Vehicle[1] = new Car("Car2", 120, &Road1);
Vehicle[2] = new Truck("Truck1", 51, &Road1);
Vehicle[3] = new Bus("Bus1", 90, &Road1);
Vehicle[4] = new Bus("Bus2", 45, &Road1);
Vehicle[5] = new Motorcycle("Motor1", 40, &Road1);
Vehicle[6] = new Car("Car3", 180, &Road2);
Vehicle[7] = new Truck("Truck2", 71, &Road2);
Vehicle[8] = new Truck("Truck3", 60, &Road2);
Vehicle[9] = new Bus("Bus3", 36, &Road2);
Vehicle[10] = new Motorcycle("Motor2", 10, &Road2);
Vehicle[11] = new Motorcycle("Motor3", 5, &Road2);
for (int loop = 0; loop < 1000000; loop++) {
for (int v = 0; v < 12; v++) {
(*Vehicle[v]).move(&Road1,&Road2);
for(int index = 0; index < 12; index++) {
if (((*Vehicle[v]).Position.x == 500) && ((*Vehicle[index]).Position.y == 500)) {
(*Vehicle[v]).JunkIt(MyJunkyard);
(*Vehicle[index]).JunkIt(MyJunkyard);
cout << (*Vehicle[v]).Name << " traveling at " << (*Vehicle[v]).Speed << "km/hr from the ";
if ((*Vehicle[v]).RoadPtr->Dir == 0)
cout << "East ";
else
cout << "South ";
cout << "Collided with " << (*Vehicle[index]).Name << " traveling at " << (*Vehicle[index]).Speed << " km/hr from the ";
if ((*Vehicle[index]).RoadPtr->Dir == 0)
cout << "East ";
else
cout << "South ";
cout << " during the " << loop << " th loop iteration";
delete Vehicle[v];
Vehicle[v] = '\0';
delete Vehicle[index];
Vehicle[index] = '\0';
}
}
}
}
cout << "This is the Junkyard's statistics after the loop";
MyJunkyard.JunkyardAdvertise();
return 0;
};
Thank you in advance
Matt
|