Write your question here.
This program, when calculating the perimeter and area of a given size rectangle, always returns a value of 1 for perimeter and a value of 1 for area.
ex09_11
MAIN
#include "stdafx.h"
#include "Rectangle.h"
int main()
{
double l;
double w;
std::cout<<"Please enter length\n"<<std::endl;
std::cin>>l;
std::cout<<"Please enter width\n"<<std::endl;
std::cin>>w;
Rectangle printPerimeter(double);
Rectangle printArea (double);
std::cout<<"The perimeter of the rectangle is:"<<&Rectangle::printPerimeter;
std::cout<<"The area of the rectangle is:" <<&Rectangle::printArea;
std::cout<<std::endl;
std::cin>>l;
std::cout<<"Please enter length\n"<<std::endl;
std::cin>>w;
return 0;
}
double Rectangle::getl()
{
return l;
}
double Rectangle::getw()
{
return w;
}
double Rectangle::printArea(double l, double w)
{
A=l*w;
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
std::cout<<"The perimeter of the rectangle is:"<<&Rectangle::printPerimeter;
std::cout<<"The area of the rectangle is:" <<&Rectangle::printArea;
you are trying to output address of member functions that are implicitly converted to bool values. As the addresses are not equal to zero then true (that is 1) is displayed for both the statements.
1>ex09_11.obj : error LNK2019: unresolved external symbol "public: __thiscall Rectangle::Rectangle(double,double)" (??0Rectangle@@QAE@NN@Z) referenced in function _main
1>C:\Users\Jonathan\Documents\Visual Studio 2010\Projects\Rectangleclass\Debug\Rectangleclass.exe : fatal error LNK1120: 1 unresolved externals
#include "stdafx.h"
//In these statements
//std::cout<<"The perimeter of the rectangle is:"<<&Rectangle::printPerimeter;
//std::cout<<"The area of the rectangle is:" <<&Rectangle::printArea;
//you are trying to output address of member functions that are implicitly converted to bool values. As the addresses are not equal to zero then true (that is 1) is displayed for both the statements.
#include "Rectangle.h"
int main()
{
double l;
double w;
std::cout<<"Please enter length\n"<<std::endl;
std::cin>>l;
std::cout<<"Please enter width\n"<<std::endl;
std::cin>>w;
Rectangle perimeter;//create two Rectangle class objects
Rectangle area;//
Rectangle printPerimeter(double);
Rectangle printArea (double);
std::cout<<"The perimeter of the rectangle is:"<<perimeter.printPerimeter(l,w);
std::cout<<"The area of the rectangle is:" <<area.printArea(l,w);
std::cout<<std::endl;
std::cin>>l;
std::cout<<"Please enter length\n"<<std::endl;
std::cin>>w;
return 0;
}
double Rectangle::getl()
{
return l;
}
double Rectangle::getw()
{
return w;
}
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#ifndef Rectangle_h
#define Rectangle_h
// TODO: reference additional headers your program requires here
class Rectangle
{
public:
//constructor
Rectangle::Rectangle(double length =1, double width =1);
When compiling this newer version of the application, I get syntax errors regarding identifiers 'l' and 'w':
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#ifndef Rectangle_h
#define Rectangle_h
// TODO: reference additional headers your program requires here
class Rectangle
{
public:
//constructor
//Rectangle();
Rectangle(double length =l, double width =w);
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//