Too depressed, so many mistakes we help

Category: C/C++ -> C++ Author: robenbat Date: 2010-07-11 13:48:43
 
robenbat
2010-07-11 13:48:43

#include <iostream>
using namespace std;

class Triangle
{
protected:
double a;
double b;
double c;
double Area;

public:
    Triangle ( double A, double B, double C );
void DisplayDetails ( );
virtual void GetArea ( ) = 0;
};

Triangle ::Triangle(double A, double B, double C)
{
a = A;
b = B;
c = C;
Area = 0;

cout<<"You has enter all the side!"<<endl;
}

void Triangle ::DisplayDetails()
{
cout<<a<<endl<<b<<endl<<c<<endl;
}


class NormalTriangle : public Triangle
{
private:
double p;
public:
NormalTriangle (  ) ;
virtual void GetArea ( );
};

NormalTriangle ::NormalTriangle(  ) : Triangle ( double A, double B, double C ) ;


p = ( a + b + c ) / 2;
cout<<"It's a normal triangle!"<<endl;
}

void NormalTriangle ::GetArea() 
{
Area = p*(p-a)*(p-b)*(p-c);
}


class RrightTriangle : public Triangle
{
public:
RrightTriangle (  );
virtual void GetArea ( );
};

RrightTriangle ::RrightTriangle(  )  : Triangle ( double A, double B, double C ) ;
{
cout<<"It's an right triangle!"<<endl;
}

void RrightTriangle::GetArea() 
{
if ( a*a + b*b == c*c )
Area = a * b / 2;

else if ( b*b + c*c == a*a )
Area = b * c / 2;

else 
Area = a * c / 2;

cout<<"The area is :"<<Area<<endl;
}

bool CheckType ( double a, double b, double c  )
{
if ( a*a + b*b == c*c )
return true;

else if ( b*b + c*c == a*a )
return true;

else if ( a*a + c*c == b*b )
return true;

else 
return false;
}

void main ( void )
{
double A, B, C;

    Triangle* p;

cin>>A>>B>>C;

if ( CheckType ( A, B, C ) )
{
p = new RrightTriangle (A, B, C );
}

else 
{
p = new NormalTriangle (A, B, C );
}
}


1> ------ Build started: Project: sanjiaoxing, Configuration: Debug Win32 ------
1> Compiling ...
1> sanjiaoxing.cpp
1> c: \ users \ andy \ documents \ visual studio 2008 \ projects \ sanjiaoxing \ sanjiaoxing \ sanjiaoxing.cpp (43): error C2144: syntax error: "double" should be preceded by ")"
1> c: \ users \ andy \ documents \ visual studio 2008 \ projects \ sanjiaoxing \ sanjiaoxing \ sanjiaoxing.cpp (43): error C2612: base / member initializer list illegal suffix "Type"
1> c: \ users \ andy \ documents \ visual studio 2008 \ projects \ sanjiaoxing \ sanjiaoxing \ sanjiaoxing.cpp (43): error C2512: "Triangle": No appropriate default constructor available
1> c: \ users \ andy \ documents \ visual studio 2008 \ projects \ sanjiaoxing \ sanjiaoxing \ sanjiaoxing.cpp (43): error C2062: Unexpected type "double"
1> c: \ users \ andy \ documents \ visual studio 2008 \ projects \ sanjiaoxing \ sanjiaoxing \ sanjiaoxing.cpp (43): error C2059: Syntax error: ")"
1> c: \ users \ andy \ documents \ visual studio 2008 \ projects \ sanjiaoxing \ sanjiaoxing \ sanjiaoxing.cpp (51): error C2601: "NormalTriangle :: GetArea": ​​local function definitions are illegal
1> c: \ users \ andy \ documents \ visual studio 2008 \ projects \ sanjiaoxing \ sanjiaoxing \ sanjiaoxing. cpp (59): warning C4822: "NormalTriangle :: {ctor} :: RrightTriangle :: RrightTriangle": local class member function does not function body
1> c: \ users \ andy \ documents \ visual studio 2008 \ projects \ sanjiaoxing \ sanjiaoxing \ sanjiaoxing.cpp (60): warning C4822: "NormalTriangle :: {ctor} :: RrightTriangle :: GetArea": local class member function does not function body
1> c: \ users \ andy \ documents \ visual studio 2008 \ projects \ sanjiaoxing \ sanjiaoxing \ sanjiaoxing.cpp (60): error C3640: ; "NormalTriangle :: {ctor} :: RrightTriangle :: GetArea": ​​a reference to a local class member functions or virtual member function must be defined
1> c: \ users \ andy \ documents \ visual studio 2008 \ projects \ sanjiaoxing \ sanjiaoxing \ sanjiaoxing.cpp (63): error C2143: syntax error: missing ';' (in the ":" in front)
1> c: \ users \ andy \ documents \ visual studio 2008 \ projects \ sanjiaoxing \ sanjiaoxing \ sanjiaoxing.cpp (63): error C2143: syntax error: missing ';' ( In ":" in front)
1> c: \ users \ andy \ documents \ visual studio 2008 \ projects \ sanjiaoxing \ sanjiaoxing \ sanjiaoxing.cpp (69): error C2601: ; "NormalTriangle :: {ctor} :: RrightTriangle :: GetArea": ​​local function definitions are illegal
1> c: \ users \ andy \ documents \ visual studio 2008 \ projects \ sanjiaoxing \ sanjiaoxing \ sanjiaoxing.cpp (83): error C2601: "CheckType": local function definitions are illegal
1> c: \ users \ andy \ documents \ visual studio 2008 \ projects \ sanjiaoxing \ sanjiaoxing \ sanjiaoxing.cpp (98): error C2601: "main": local function definitions are illegal
1> c: \ users \ andy \ documents \ visual studio 2008 \ projects \ sanjiaoxing \ sanjiaoxing \ sanjiaoxing.cpp (115): fatal error C1004: unexpected end of file found
1> Build log was saved at "file: / / c: \ Users \ ANDY \ Documents \ Visual Studio 2008 \ Projects \ sanjiaoxing \ sanjiaoxing \ Debug \ BuildLog.htm "
1> sanjiaoxing - 13 errors, 2 warnings
========== Build: 0 succeeded, 1 failed, 0 up, skip 0 = =========
hanqi456838
2010-07-11 14:04:03


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

class Triangle
{
protected:
    double a;
    double b;
    double c;
    double Area;

public:
    Triangle ( double A, double B, double C );
    void DisplayDetails ( );
    virtual void GetArea ( ) = 0;
};

Triangle ::Triangle(double A, double B, double C)
{
    a = A;
    b = B;
    c = C;
    Area = 0;
    
    cout<<"You has enter all the side!"<<endl;
}

void Triangle ::DisplayDetails()
{
    cout<<a<<endl<<b<<endl<<c<<endl;
}


class NormalTriangle : public Triangle
{
private:
    double p;
public:
    NormalTriangle (double A, double B, double C) ;
    virtual void GetArea ( );
};

NormalTriangle ::NormalTriangle(double A, double B, double C) : Triangle (a, b, c ) 


    p = ( a + b + c ) / 2;
    cout<<"It's a normal triangle!"<<endl;
}

void NormalTriangle ::GetArea() 
{
    Area = p*(p-a)*(p-b)*(p-c);
}


class RrightTriangle : public Triangle
{
public:
    RrightTriangle (double A, double B, double C);
    virtual void GetArea ( );
};

RrightTriangle ::RrightTriangle(double A, double B, double C)  : Triangle (a, b, c ) 
{
    cout<<"It's an right triangle!"<<endl;
}

void RrightTriangle::GetArea() 
{
    if ( a*a + b*b == c*c )
        Area = a * b / 2;

    else if ( b*b + c*c == a*a )
        Area = b * c / 2;

    else 
        Area = a * c / 2;

    cout<<"The area is :"<<Area<<endl;
}

bool CheckType ( double a, double b, double c  )
{
    if ( a*a + b*b == c*c )
        return true;

    else if ( b*b + c*c == a*a )
        return true;

    else if ( a*a + c*c == b*b )
        return true;

    else 
        return false;
}

void main ( void )
{
    double A, B, C;

    Triangle* p;

    cin>>A>>B>>C;

    if ( CheckType ( A, B, C ) )
    {
        p = new RrightTriangle (A, B, C );
    }

    else 
    {
        p = new NormalTriangle (A, B, C );
    }
}

tginkfull258
2010-07-11 14:15:34

//1. , double
//2. , ,
NormalTriangle ::NormalTriangle(  ) : Triangle ( double A, double B, double C ) ;


    p = ( a + b + c ) / 2;
    cout<<"It's a normal triangle!"<<endl;
}
szcopy
2010-07-11 14:21:46
NormalTriangle :: NormalTriangle (double A, double B, double C): Triangle (A, B , C);
baozaizang
2010-07-11 14:28:55
behind the semicolon should be removed. . . ~!
gbfengyun
2010-07-11 14:41:57
RrightTriangle :: RrightTriangle (double a, double b, double c): Triangle (a, b, c)
ldx790306570
2010-07-11 14:49:27
RrightTriangle :: RrightTriangle (double A, double B, double C): Triangle (A, B , C)
mumulan1984
2010-07-11 14:55:48
constructor problem parameters did not write; and data member initialization statement is also a problem, the following changes, compiled by:
NormalTriangle ( double A, double B, double C) ;/ / parameter type
NormalTriangle :: NormalTriangle (double A, double B, double C): Triangle (a, b, c) not followed by a semicolon. The next issue the same constructor.

freegirl_yu
2010-07-11 15:13:26
with a virtual function, you only need to add virtual in the base class can be
sdlwkaifaqu
2010-07-11 15:32:20
Thank you for your answer I got it
But I have a question, call the constructor call is layer by layer, of course, this is the compiler choose it
I would say is a matter of habit, it seems a good limit specified subclass call the parent constructor a class constructor relatively okay
even say that I actually call the parent class's default constructor is also written child (): father ()
because it can increase the readability of the code written so others clearly see your calling relationships, when there are a large number of constructor overload seem to do better
you master is how you see it?
xiaoxiaoranran
2010-07-11 15:47:21
readability is very important, so, though a bit cumbersome, but the habit is always good, stick until this style into their own style.
BABTY
2010-07-11 16:02:19
Bangding.