simple code not working

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

Join Date: Jun 2009
Posts: 8
Reputation: cplusplusfool is an unknown quantity at this point 
Solved Threads: 0
cplusplusfool cplusplusfool is offline Offline
Newbie Poster

simple code not working

 
0
  #1
Jul 3rd, 2009
Please find the details of the code in attachment.

I am new c++ student. Please let me know the fault.

Regards,
Shivi
Attached Files
File Type: zip Archive.zip (8.6 KB, 8 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1462
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: simple code not working

 
0
  #2
Jul 3rd, 2009
Please describe the problem -- what does the code not do correctly? Or are there compiler errors, post some of the errors.

And what operating system/compiler are you using?
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 628
Reputation: daviddoria is a jewel in the rough daviddoria is a jewel in the rough daviddoria is a jewel in the rough 
Solved Threads: 46
daviddoria daviddoria is offline Offline
Practically a Master Poster

Re: simple code not working

 
0
  #3
Jul 3rd, 2009
Shivi, it may also be easier to post the very smallest compilable example that produces an error directly on the forum using 'code' tags rather than creating an attachment. This way some users can potentially see the problem right away without having to download anything.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 8
Reputation: cplusplusfool is an unknown quantity at this point 
Solved Threads: 0
cplusplusfool cplusplusfool is offline Offline
Newbie Poster

Re: simple code not working

 
0
  #4
Jul 3rd, 2009
Originally Posted by cplusplusfool View Post
Please find the details of the code in attachment.

I am new c++ student. Please let me know the fault.

Regards,
Shivi
errors:

g++ -c brick.cc
g++ -o my.out:shape.o brick.o Exo.o
brick.o: In function `Brick::Volume() const':
brick.cc:(.text+0x1db): undefined reference to `Rectangle::getLength() const'
brick.cc:(.text+0x1e9): undefined reference to `Rectangle::getWidth() const'
brick.o: In function `Brick::Display()':
brick.cc:(.text+0x21e): undefined reference to `Rectangle::getLength() const'
brick.cc:(.text+0x24f): undefined reference to `Rectangle::getWidth() const'
brick.cc:(.text+0x280): undefined reference to `Rectangle::Area() const'
brick.o: In function `Brick::setDimensions(double, double, double)':
brick.cc:(.text+0x388): undefined reference to `Rectangle::setLength(double)'
brick.cc:(.text+0x39a): undefined reference to `Rectangle::setWidth(double)'
collect2: ld returned 1 exit status
make: *** [my.out] Error 1
Last edited by Ancient Dragon; Jul 3rd, 2009 at 5:44 pm. Reason: dsable smilies in text
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1462
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: simple code not working

 
0
  #5
Jul 3rd, 2009
Those errors mean you either failed to code those functions or you didn't include the *.o file in the makefile.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 8
Reputation: cplusplusfool is an unknown quantity at this point 
Solved Threads: 0
cplusplusfool cplusplusfool is offline Offline
Newbie Poster

Re: simple code not working

 
0
  #6
Jul 4th, 2009
I have checked everything but did not getting error !!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1462
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: simple code not working

 
0
  #7
Jul 4th, 2009
post the header file that defines Rectangle class and the code brick.cc
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 8
Reputation: cplusplusfool is an unknown quantity at this point 
Solved Threads: 0
cplusplusfool cplusplusfool is offline Offline
Newbie Poster

Re: simple code not working

 
0
  #8
Jul 5th, 2009
Originally Posted by Ancient Dragon View Post
post the header file that defines Rectangle class and the code brick.cc
brick.h
  1. #ifndef BRICK_H_
  2. #define BRICK_H_
  3.  
  4. #include "shape.h"
  5.  
  6. class Brick
  7.  
  8. {
  9. public:
  10. Brick() {};
  11. void setThickness(double Tck);
  12. void setDimensions(double l, double w, double t);
  13. void setColor(char* clr);
  14. void setTexture(char* txr);
  15. char* getColor() const;
  16. char* getTexture() const;
  17. double Volume() const;
  18. void Display();
  19.  
  20. private:
  21. Rectangle shape;
  22. char* Color;
  23. char* Texture;
  24. double Thickness;
  25. };
  26.  
  27. #endif // BRICK_H_
brick.cc
  1. #include <iostream>
  2. #include "brick.h"
  3. using namespace std;
  4.  
  5.  
  6. void Brick::setThickness(double Tck)
  7. {
  8. Thickness = Tck;
  9. }
  10.  
  11. void Brick::setColor(char* clr)
  12. {
  13. Color = clr;
  14. }
  15.  
  16. void Brick::setTexture(char* txr)
  17. {
  18. Texture = txr;
  19. }
  20.  
  21. void Brick::setDimensions(double l, double w, double t)
  22. {
  23. shape.setLength(l);
  24. shape.setWidth(w);
  25. setThickness(t);
  26. }
  27.  
  28. char* Brick::getColor() const
  29. {
  30. return Color;
  31. }
  32.  
  33. char* Brick::getTexture() const
  34. {
  35. return Texture;
  36. }
  37.  
  38. double Brick::Volume() const
  39. {
  40. return shape.getLength() * shape.getWidth() * Thickness;
  41. }
  42.  
  43. void Brick::Display()
  44. {
  45. cout << "\nBrick characteristics";
  46. cout << "\n\tLength = " << shape.getLength();
  47. cout << "\n\tWidth = " << shape.getWidth();
  48. cout << "\n\tArea = " << shape.Area();
  49. cout << "\n\tVolume = " << Volume();
  50. cout << "\n\tColor = " << getColor();
  51. cout << "\n\tTextture = " << getTexture();
  52. cout << endl;
  53. }


shape.h
  1. #ifndef _SHAPE_H
  2. #define _SHAPE_H
  3.  
  4. class Rectangle
  5. {
  6. public:
  7. Rectangle(double l = 0, double w = 0)
  8. : Length(l), Width(w) {}
  9. void setLength(double lgt);
  10. void setWidth(double wdt);
  11. double getLength() const;
  12. double getWidth() const;
  13. double Perimeter() const;
  14. double Area() const;
  15. void Properties();
  16.  
  17. private:
  18. double Length;
  19. double Width;
  20. };
  21.  
  22. #endif // _SHAPE_H

shape.cc
  1. #include <iostream>
  2. #include "shape.h"
  3. using namespace std;
  4.  
  5.  
  6.  
  7. void Rectangle::setLength(double lgt)
  8. {
  9. Length = lgt;
  10. }
  11.  
  12. void Rectangle::setWidth(double wdt)
  13. {
  14. Width = wdt;
  15. }
  16.  
  17. double Rectangle::getLength() const
  18. {
  19. return Length;
  20. }
  21.  
  22. double Rectangle::getWidth() const
  23. {
  24. return Width;
  25. }
  26.  
  27. double Rectangle::Perimeter() const
  28. {
  29. return 2 * (Length + Width);
  30. }
  31.  
  32. double Rectangle::Area() const
  33. {
  34. return Length * Width;
  35. }
  36.  
  37. void Rectangle::Properties()
  38. {
  39. cout << "\nRectangle characteristics";
  40. cout << "\n\tLength = " << Length;
  41. cout << "\n\tWidth = " << Width;
  42. cout << "\n\tPerimeter = " << Perimeter();
  43. cout << "\n\tArea = " << Area() << endl;
  44. }

my.make
  1. my.out:shape.o brick.o Exo.o
  2. g++ -o my.out:shape.o brick.o Exo.o
  3. Exo.o: Exo.cc brick.h shape.h
  4. g++ -c Exo.cc
  5. shape.o: shape.cc shape.h
  6. g++ -c shape.cc
  7. brick.o: brick.cc brick.h
  8. g++ -c brick.cc
  9. clean: rm *.o my.out
Last edited by Ancient Dragon; Jul 5th, 2009 at 10:00 am. Reason: add code tags and disable smilies
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 628
Reputation: daviddoria is a jewel in the rough daviddoria is a jewel in the rough daviddoria is a jewel in the rough 
Solved Threads: 46
daviddoria daviddoria is offline Offline
Practically a Master Poster

Re: simple code not working

 
0
  #9
Jul 5th, 2009
Please use code tags - then the smiley faces won't happen, indentation will be correct, and syntax highlighting will happen.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1462
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: simple code not working

 
0
  #10
Jul 5th, 2009
>>g++ -o my.out:shape.o brick.o Exo.o

What is that colon doing there between out and shape.o? I think it should be a space and g++ is not recognizing shape.o as an input file.
Last edited by Ancient Dragon; Jul 5th, 2009 at 10:06 am.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC