Home > Software engineering >  C the problem of dynamic binding
C the problem of dynamic binding

Time:09-24

 # include "stdafx. H" 
//ConsoleApplication1. CPP: defines the entry point of the console application,
//
#include
#include

# define M_PI 3. 14159265358979323846
using namespace std;

The class CFigure
{
Public:
Virtual char * FigureType ()=0;
Virtual double Circumference ()=0;
Virtual double Area ()=0;
Virtual ~ CFigure () {}
};

The class CTriangle: public CFigure
{
Public:
CTriangle ()
{
A=b=c=0;
}
CTriangle (double a, b double, double c) : a (a), b (b), c (c) {}

Char * FigureType ()
{
Return "Triangle";
}
Double Circumference ()
{
The return of a + b + c;
}
Double Area ()
{
Double S=Circumference ()/2;
Return SQRT (S * (S - a) * (S - b) * (S - c));
}
Private:
Double a, b, c;
};
The class CSquare: public CFigure
{
Public:
CSquare ()
{
A=0.0;
B=0.0;
}
CSquare (double a, double b) : (a), b (b)
{

}
Char * FigureType ()
{
Return "Square";
}
Double Circumference ()
{
Return a + 2 * 2 * b;
}
Double Area ()
{
Return a * b;
}
Private:
Double a, b;
};
The class CCircle: public CFigure
{
Public:
CCircle ()
{
R=0;
}
CCircle (double r) : r (r)
{

}
Char * FigureType ()
{
Return "Circle";
}
Double Circumference ()
{
Return 2 * r * M_PI;
}
Double Area ()
{
Return r * r * M_PI;
}
Private:
double r;
};
Int _tmain (int arg c, _TCHAR * argv [])
{
CFigure * figures [3].
Figures [0]=new CTriangle (2, 1, 3, 2, 4. 3);
Figures [1]=new CSquare (5, 4, 6. 5).
Figures [2]=new CCircle (8, 8);

for (int i=0; i <3; I++)
{
Cout & lt; <"Figure type: \ t" & lt; <"\ nCircumference: \ t" & lt; <"\ nArea: t \ \ t" & lt; return 0;
}


Fellow teachers, error
Error:
Severity code shows the project file line prohibits display status
Error C2664 "CTriangle: : CTriangle (CTriangle & amp; & amp;) 1 cannot be the parameter ": from" double "into" const CTriangle & amp;" ConsoleApplication1 d: \ itteam_2017 07.14 \ \ MFC of vc \ \ 2 ConsoleApplication1 \ ConsoleApplication1 \ ConsoleApplication1 CPP 100
Severity code shows the project file line prohibits display status
Error C2664 "CSquare: : CSquare (CSquare & amp; & amp;) 1 cannot be the parameter ": from" double "into" const CSquare & amp;" ConsoleApplication1 d: \ itteam_2017 07.14 \ \ MFC of vc \ \ 2 ConsoleApplication1 \ ConsoleApplication1 \ ConsoleApplication1 CPP 101
Severity code shows the project file line prohibits display status
Warning C4129 "" : do not recognize the characters of escape sequences ConsoleApplication1 d: \ itteam_2017 07.14 \ \ MFC of vc \ \ 2 ConsoleApplication1 \ ConsoleApplication1 \ ConsoleApplication1 CPP 108


Thank you teacher

CodePudding user response:

Figures [0]=new CTriangle (2.1 f to 3.2 f to 4.3 f);
Figures [1]=new CSquare (5.4 f to 6.5 f);
Figures [2]=new CCircle (8.8 f);
So try again

CodePudding user response:

If it doesn't solve, suggests that there are other errors before. From the first line of the wrong place, please post all error information

CodePudding user response:

Thanks, the problem has been solved

CodePudding user response:

I you copy the code to vs2013, guess what??

In fact you all decimal, the decimal point on the right is more than a "space",,,, get rid of these Spaces, is correct,,,,