Need your help please

This is a discussion on Need your help please within the C++ Programming forums, part of the General Programming Boards category; I have got C++ programdesign book and i have just copy and past the following code then i get a ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    5

    Post Need your help please

    I have got C++ programdesign book and i have just copy and past the following code then i get a very strange error

    Code:
    //**************************************************************************
    //
    // Copyright (c) 1997.
    //      Richard D. Irwin, Inc.
    //
    // This software may not be distributed further without permission from
    // Richard D. Irwin, Inc.
    //
    // This software is distributed WITHOUT ANY WARRANTY. No claims are made
    // as to its functionality or purpose.
    //
    // Authors: James P. Cohoon and Jack W. Davidson
    // Date: 7/15/96
    // $Revision: 1.2 $
    // $Name: E2 $
    //
    //**************************************************************************
    
    // Program 3.5: Compute the time and cost required to mow
    // a lawn
    #include <iostream>
    #include <string>
    #include "rect.h"
    
    using namespace std;
    
    int ApiMain() {
    	// Mowing rate in square meters per second
    	const float MowRate = 1.0f;
    	// Pay rate desired
    	const float PayRate = 6.0f;
    
    	// Seconds in an hour
    	const int SecondsPerMinute = 60;
    	// Minutes in an hour
    	const int SecondsPerHour =
    	 SecondsPerMinute * 60;
    
    	// Length and width of display window
    	const float DisplayLength = 20.0f;
    	const float DisplayHeight = 20.0f;
    
    	// Scale factor for display. 100 meters equals
    	// 1 centimeter
    	const float ScaleFactor = 0.01f;
    
    	cout << "Please use meters for all input\n" << endl;
    
    	long LawnLength; // Length of the lawn in meters
    	cout << "Please enter the length of the lawn: ";
    	cin >> LawnLength;
    
    	long LawnWidth; // Width of the lawn in meters
    	cout << "Please enter the width of the lawn: ";
    	cin >> LawnWidth;
    
    	long HouseLength; // Length of the house in meters
    	cout << "Please enter the length of the house: ";
    	cin >> HouseLength;
    
    	long HouseWidth; // Width of the house in meters
    	cout << "Please enter the width of the house: ";
    	cin >> HouseWidth;
    
    	// Echo the input so they can be verified
    	cout << endl;
    	cout << "Yard size: " << LawnLength << " by "
    	 << LawnWidth << " meters" << endl;
    	cout << "House size: " << HouseLength << " by "
    	 << HouseWidth << " meters" << endl;
    
    	// Compute the mowable area
    	long MowableArea = (LawnLength * LawnWidth)
    	 - (HouseLength * HouseWidth);
    
    	// Compute the time to cut and display it
    	long MowTimeInSeconds = MowableArea / MowRate;
    	long Hours = MowTimeInSeconds / SecondsPerHour;
    	long Minutes = (MowTimeInSeconds
    	 - (Hours * SecondsPerHour)) / SecondsPerMinute;
    
    	cout << "Time to cut: " << Hours << " hour(s) "
    	 << Minutes << " minute(s)" << endl;
    	// Compute the cost and display it
    	float DollarCost = MowTimeInSeconds * PayRate
    	 / SecondsPerHour;
    	int Dollars = DollarCost;
    	int Cents = (DollarCost - Dollars) * 100;
    	cout << "Cost to cut: " << Dollars << " dollar(s)"
    	 << " and " << Cents << " cent(s)" << endl;
    
    	// Open the window and display the lawn
    	SimpleWindow Display("Lawn and House Plot",
    	 DisplayLength, DisplayHeight);
    	Display.Open();
    
    	RectangleShape Lawn(Display, DisplayLength / 2.0f,
    	 DisplayHeight / 2.0f, Green,
    	 LawnLength * ScaleFactor,
    	 LawnWidth * ScaleFactor);
    	 Lawn.Draw();
    	// Display the house
    	RectangleShape House(Display, DisplayLength / 2.0f,
    	 DisplayHeight / 2.0f, Yellow,
    	 HouseLength * ScaleFactor,
    	 HouseWidth * ScaleFactor);
    	House.Draw();
    
    	cout << "Type Ctrl-C to remove the display and exit" << endl;
    	char AnyChar;
    	cin >> AnyChar;
    	Display.Close();
    
    	return 0;
    }
    Configuration: k - Win32 Debug--------------------
    Compiling...
    k1.cpp
    Linking...
    k1.obj : error LNK2001: unresolved external symbol "public: __thiscall SimpleWindow::~SimpleWindow(void)" (??1SimpleWindow@@QAE@XZ)
    k1.obj : error LNK2001: unresolved external symbol "public: enum WindowStatus __thiscall SimpleWindow::Close(void)" (?Close@SimpleWindow@@QAE?AW4WindowStatus@@XZ)
    k1.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall RectangleShape:raw(void)" (?Draw@RectangleShape@@UAEXXZ)
    k1.obj : error LNK2001: unresolved external symbol "public: __thiscall RectangleShape::RectangleShape(class SimpleWindow &,float,float,enum color const &,float,float)" (??0RectangleShape@@QAE@AAVSimpleWindow@@MMABW4col or@@MM@Z)
    k1.obj : error LNK2001: unresolved external symbol "public: enum WindowStatus __thiscall SimpleWindow::Open(void)" (?Open@SimpleWindow@@QAE?AW4WindowStatus@@XZ)
    k1.obj : error LNK2001: unresolved external symbol "public: __thiscall SimpleWindow::SimpleWindow(char const *,float,float,class Position const &)" (??0SimpleWindow@@QAE@PBDMMABVPosition@@@Z)
    k1.obj : error LNK2001: unresolved external symbol "public: __thiscall Position::Position(float,float)" (??0Position@@QAE@MM@Z)
    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/k.exe : fatal error LNK1120: 8 unresolved externals
    Error executing link.exe.

    k.exe - 9 error(s), 0 warning(s)

    does any body know what is this error for.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Code:
    unresolved external symbol "public: __thiscall RectangleShape::RectangleShape(class SimpleWindow &,float,float,enum color const &,float,float)"
    RectangleShape::RectangleShape(/*...*/) doesn't exist.

    You probably need to link the file containing RectangleShape to this one. Or perhaps that function actually doesn't exist (along with 8 others). Let's see rect.h.

    You can turn off smileys if you want.
    Last edited by dwks; 09-19-2005 at 05:15 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    5
    how can i link file? sorry but i am just new to c++

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    5
    This is rect.h header

    Code:
    #ifndef RECTSHAPE_H
    #define RECTSHAPE_H
    #include "shape.h"
    class RectangleShape : public Shape {
    	public:
    		RectangleShape(SimpleWindow &Window,
    		 const Position &Center, const color &c = Red,
    		 float Length = 1.0f, float Width = 2.0f);
    		RectangleShape(SimpleWindow &w,
    		 float XCoord, float YCoord,
    		 const color &c = Red, float Length = 1.0f,
    		 float Width = 2.0f);
    		float GetWidth() const;
    		float GetHeight() const;
    		void GetSize(float &Width, float &Height) const;
    		void Draw();
    		void SetSize(float Width, float Height);
    		void Erase();
    	private:
    		float Width;
    		float Height;
    };
    
    #endif

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    I though you wrote the class "RectangleShape". If you didn't, you need to find its code.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    5
    does rect.h containes "RectangleShape" code?

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21