GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 13-Nov-2004, 10:55
mattchew008 mattchew008 is offline
New Member
 
Join Date: Nov 2004
Posts: 11
mattchew008 is on a distinguished road

*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
CPP / C++ / C 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
  #2  
Old 14-Nov-2004, 01:25
imbtf imbtf is offline
Junior Member
 
Join Date: Aug 2004
Posts: 41
imbtf will become famous soon enough
You've probably created a "Win32 Application" (looking for WinMain() as starting point of execution). What you've written is a "Win32 Console Application" (using main() ). There's some differences in includes/defines for the different project types and I suppose the by far easiest solution would be to create a new "Win32 Console Application" project and just copy your code to it.
 
 

Recent GIDBlogMeeting the populace by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
burning problems PLEASE PLEASE HELP kelticeire Computer Hardware Forum 4 01-Dec-2006 15:39
Problems in Counting Lines in Text File wc3promet C++ Forum 2 22-Oct-2004 19:12
Chaintech Geforce 5600 FX problems bartster74 Computer Hardware Forum 8 04-May-2004 13:16
Apache - problems using PHP outside the intranet ooandioo Apache Web Server Forum 6 04-Feb-2004 09:27
Installation problems arman Apache Web Server Forum 3 03-Feb-2004 12:02

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:32.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.