I am having trouble with myRectangle2 taking the values I am assigning to it. The myLine2 value works just fine.

Can anyone spot what I am doing wrong? I have stared at this for too long and now I am second guessing everything I have already done.

Any help is greatly appreciated.

// Scott Streit
//Chapter 13 inclass Exercise.


#include "stdafx.h"
#include <iostream>

using namespace std;
#define frz system("pause");

class lineType
{
public:
	void setDimension(double l);
	double getLength() const;
	void print() const;
	lineType();//default constructor
	lineType(double l);//constructor initializing length
private:
	double length;
};//end lineType class

class rectangleType: public lineType
{
public:
	void setDimension(double l, double w);
	double getWidth() const;
	double calcArea() const;
	void print() const;
	rectangleType();//default constructor
	rectangleType(double length, double width);//constructor initalizing length and width
private:
	double width;
};//end rectangleType class


int main()
{
	lineType myLine;
	lineType myLine2(10);
	rectangleType myRectangle;
	rectangleType myRectangle2(3,6);
	
	
	cout<<"my line 1: ";
	myLine.print();
	cout<<endl;

	cout<<"my line 2: ";
	myLine2.print();
	cout<<endl;

	cout<<"my rectangle 1: ";
	myRectangle.print();
	cout<<endl<<endl;

	cout<<"my rectangle 2: ";
	myRectangle.print();
	cout<<endl<<endl;

	cout<<"the width of my rectangle 2 : ";
	myRectangle2.getWidth();
	cout<<endl<<endl;

	cout<<"the area of rectangle 2 is : ";
	myRectangle2.calcArea();
	cout<<endl<<endl;

	frz;
	return 0;
}//end main


lineType::lineType()
{
	length=0;
};//end default constructor
lineType::lineType(double l)
{
	length=l;
}//end lineType constructor
void lineType::setDimension(double l)
{
	length=l;
}//end set Dimension
double lineType::getLength() const
{
	return length;
}//end getLength
void lineType::print() const
{
	cout<<"Length = "<<length<<endl;
}//end print

rectangleType::rectangleType()
{
	width=0;
};
rectangleType::rectangleType(double l, double w )
	:lineType(l)
{
	width=w;
}//end lineType constructor
void rectangleType::setDimension(double l, double w)
{
	lineType::setDimension(l);
	width=w;
	
}//end set Dimension
double rectangleType::getWidth() const
{
	lineType::getLength();
	return width;
}//end getLength
double rectangleType::calcArea() const
{
	return lineType::getLength()*width;
}//end calcArea
void rectangleType::print() const
{
	cout<<"Length = "<<lineType::getLength()<<endl;
	cout<<"Width = "<<width<<endl;
}//end print

Reformatting slightly, is this what you really want?

rectangleType::rectangleType(double l, double w ) :lineType(l)
{
    width=w;
}//end lineType constructor
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.