HELP writing structure and class definition - Visual C++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2005
Posts: 7
Reputation: DaveSS is an unknown quantity at this point 
Solved Threads: 0
DaveSS DaveSS is offline Offline
Newbie Poster

HELP writing structure and class definition - Visual C++

 
0
  #1
Apr 13th, 2005
My assignment is to create a definition of the class Box and a structure definition.

The class definition needs the following:
Data Member Data Type
boxNumber int
boxType int
boxLength float
boxWidth float
boxHeight float

boxArea float
boxCost float
boxPrice float
boxProfit float

boxFile fstream //Dont include boxFile yet.

Member Functions
setBoxFile - sets the boxFile reference variable.
addBox - Adds a new box to the box file.
findBox - Updates records in the box file.
updateBox

and a get and set function for each of the class attributes.



My teacher said not to worry about the Member Functions yet. Not covered.

I used an example of a class called Time that i found in my textbook.
the set function example:
void setTime( int, int, int);

Im pretty sure i defined the get and set functions in the right way. Im confused about how using upper and lower case in the class and structure makes a difference.




  1. #ifndef BOX_CLASS
  2. #define BOX_CLASS
  3.  
  4. struct BoxData
  5. {
  6. int boxNumber; // Allow for up to 100 boxes
  7. int boxType; // box type (1 to 4).
  8. float boxLength;
  9. float boxWidth;
  10. float boxHeight;
  11.  
  12. }; // end struct Box
  13.  
  14. class Box {
  15.  
  16. public: //boxdata
  17.  
  18. Box( ); // constructor function
  19. //sets BoxData variables.
  20. void setBoxNumber(int);
  21. void setBoxType(int);
  22. void setBoxLength(float);
  23. void setBoxWidth(float);
  24. void setBoxHeight(float);
  25.  
  26. //gets BoxData ( 5 variables) and (4 functions) - used to return values.
  27. int getBoxNumber();
  28. int getBoxType();
  29. float getBoxLength();
  30. float getBoxWidth();
  31. float getBoxHeight();
  32. float getboxArea();
  33. float getboxCost();
  34. float getboxPrice();
  35. float getboxProfit();
  36.  
  37. bool findBox(int); // Finds a particular box in the box file.
  38. void setBoxFile(int); // sets the boxFile reference variable.
  39. bool addBox(int); // Adds a new box to the box file.
  40. bool updateBox(int); // Updates records in the box file.
  41. //boxFile fstream
  42.  
  43. private:
  44.  
  45. float boxArea;
  46. float boxCost;
  47. float boxPrice;
  48. float boxProfit;
  49.  
  50.  
  51. }; //end class Box
  52.  
  53.  
  54. #endif
  55.  
  56. //main.cpp starts here
  57.  
  58. #include <iostream>
  59. using std::cin;
  60. using std::cout;
  61. using std::endl;
  62.  
  63. #include "Box.h" //include definition of class
  64.  
  65. int main ()
  66. {
  67. Box x; // instantiate object x of class Box
  68.  
  69. x.setBoxType(1);
  70. x.setBoxType(2);
  71. x.setBoxType(3);
  72.  
  73. cout << "Choose a box type between ( 1 - 4 ) or 0 to exit: " << x.getBoxType;
  74.  
  75.  
  76. return 0;
  77.  
  78. }

i tried to create a file to test it in but i dont know what im doing wrong.

It showed 3 errors:
main.cpp
(21) : warning C4761: integral size mismatch in argument; conversion supplied
main.obj : error LNK2001: unresolved external symbol "public: int __thiscall Box::getBoxType(void)" (?getBoxType@Box@@QAEHXZ)
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Box::setBoxType(int)" (?setBoxType@Box@@QAEXH@Z)
main.obj : error LNK2001: unresolved external symbol "public: __thiscall Box::Box(void)" (??0Box@@QAE@XZ)
Debug/main.exe : fatal error LNK1120: 3 unresolved externals
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 63
Reputation: marinme is an unknown quantity at this point 
Solved Threads: 1
marinme marinme is offline Offline
Junior Poster in Training

Re: HELP writing structure and class definition - Visual C++

 
0
  #2
Apr 14th, 2005
Did you define the member functions? That looks like the problem to me...

something like:

  1. Box::Box()
  2. {
  3. //my constructor code here
  4. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 7472 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC