Please find the details of the code in attachment.

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

Regards,
Shivi

Recommended Answers

All 10 Replies

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?

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.

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

Those errors mean you either failed to code those functions or you didn't include the *.o file in the makefile.

I have checked everything but did not getting error !!

post the header file that defines Rectangle class and the code brick.cc

post the header file that defines Rectangle class and the code brick.cc

brick.h

#ifndef BRICK_H_
#define BRICK_H_

#include "shape.h"

class Brick

{
public:
	Brick() {};
	void setThickness(double Tck);
	void setDimensions(double l, double w, double t);
	void setColor(char* clr);
	void setTexture(char* txr);
	char* getColor() const;
	char* getTexture() const;
	double Volume() const;
	void Display();

private:
        Rectangle shape;
	char* Color;
	char* Texture;
	double Thickness;
};

#endif // BRICK_H_

brick.cc

#include <iostream>
#include "brick.h"
using namespace std;


void Brick::setThickness(double Tck)
{
	Thickness = Tck;
}

void Brick::setColor(char* clr)
{
	Color = clr;
}

void Brick::setTexture(char* txr)
{
	Texture = txr;
}

void Brick::setDimensions(double l, double w, double t)
{
	shape.setLength(l);
	shape.setWidth(w);
	setThickness(t);
}

char* Brick::getColor() const
{
	return Color;
}

char* Brick::getTexture() const
{
	return Texture;
}

double Brick::Volume() const
{
	return shape.getLength() * shape.getWidth() * Thickness;
}

void Brick::Display()
{
	cout << "\nBrick characteristics";
	cout << "\n\tLength   = " << shape.getLength();
	cout << "\n\tWidth    = " << shape.getWidth();
	cout << "\n\tArea     = " << shape.Area();
	cout << "\n\tVolume   = " << Volume();
	cout << "\n\tColor    = " << getColor();
	cout << "\n\tTextture = " << getTexture();
	cout << endl;
}

shape.h

#ifndef _SHAPE_H
#define _SHAPE_H

class Rectangle
{
public:
	Rectangle(double l = 0, double w = 0)
		: Length(l), Width(w) {}
	void setLength(double lgt);
	void setWidth(double wdt);
	double getLength() const;
	double getWidth() const;
	double Perimeter() const;
	double Area() const;
	void Properties();

private:
	double Length;
	double Width;
};

#endif // _SHAPE_H

shape.cc

#include <iostream>
#include "shape.h"
using namespace std;



void Rectangle::setLength(double lgt)
{
	Length = lgt;
}

void Rectangle::setWidth(double wdt)
{
	Width = wdt;
}

double Rectangle::getLength() const
{
	return Length;
}

double Rectangle::getWidth() const
{
	return Width;
}

double Rectangle::Perimeter() const
{
	return 2 * (Length + Width);
}

double Rectangle::Area() const
{
	return Length * Width;
}

void Rectangle::Properties()
{
	cout << "\nRectangle characteristics";
	cout << "\n\tLength    = " << Length;
	cout << "\n\tWidth     = " << Width;
	cout << "\n\tPerimeter = " << Perimeter();
	cout << "\n\tArea      = " << Area() << endl;
}

my.make

my.out:shape.o brick.o Exo.o
		g++ -o my.out:shape.o brick.o Exo.o
Exo.o: Exo.cc brick.h shape.h
	        g++ -c Exo.cc
shape.o: shape.cc shape.h
		g++ -c shape.cc
brick.o: brick.cc brick.h
		g++ -c brick.cc
clean: rm *.o my.out

Please use code tags - then the smiley faces won't happen, indentation will be correct, and syntax highlighting will happen.

>>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.

>>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.

correct this was the mistake. Now its working. Thanks alot !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.