| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3263 人关注过本帖
标题:第一次写类 不知道哪里错了
只看楼主 加入收藏
说了会等你
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-4-9
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
第一次写类 不知道哪里错了
不知道哪里错了
\\triangle.h
class triangle
{
private:
     float a,b,c;
public:
    void Setlength(float lengthA,float lengthB,float lengthC);
    void Judgetype();
    void Circumference();
    void area();
};


\\triangle.cpp
#include <iostream.h>
#include "triangle.h"
void triangle::Setlength (float lengthA,float lengthB,float lengthC)
{    float a,b,c;
    a=lengthA;b=lengthB;c=lengthC;
}
void triangle::Judgetype ()
{    float t,m;
    if(a>b)
        t=a;a=b;b=t;
    if(a>c)
        t=a;a=c;c=t;
    if(b>c)
        t=b;b=c;c=t;
    m=a+b;
    if(m<=c)
        cout<<"This is not a triangle."<<endl;
    else
        if(a=b!=c)
        {
            if(a*a+b*b=c*c)
                cout<<"This is a Rt isosceles triangle."<<endl;
            else
                cout<<"This is a isosceles triangle."<<endl;
        }
        if(a=b=c)
        {
            cout<<"This is a equilateral triangle."<<endl;
        }
        if(a!=b&&a!=c)
        {
            if (a*a+b*b=c*c)
                cout<<"This is a Rt triangle."<<endl;
            else
                cout<<"This is a common triangle."<<endl;
        }
}
float triangle::Circumference ()
{
    float cir;
    cir=a+b+c;
    cout<<"The circumference is"<<cir<<endl;
}
float triangle::area ()
{
    float p,s;
    p=(a+b+c)/2;
    s=sqrt(p*(p-a)*(p-b)*(p-c));
    cout<<"The area is"<<s<<endl;
}



\\main.cpp
#include <iostream.h>
#include "triangle.h"
void main()
{
    triangle triangleA;
    triangleA.Setlength();
    cout<<triangleA.Circumference ()<<endl;
    cout<<triangleA.area ()<<endl;
    cout<<triangleA.Judgetype ()<<endl;
}
2016-04-09 16:57
说了会等你
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-4-9
收藏
得分:0 
第一部分头文件,第二部分cpp,第三部分main
2016-04-09 17:26
alice_usnet
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:18
帖 子:370
专家分:2020
注 册:2016-3-7
收藏
得分:20 
程序代码:
#include <iostream.h>
#include "triangle.h"
void triangle::Setlength (float lengthA,float lengthB,float lengthC)
{    //float a,b,c;
    a=lengthA;
    b=lengthB;
    c=lengthC;
}
void triangle::Judgetype ()
{    float t,m;
    if(a>b)
    {
        t=a;a=b;b=t;
    }
    if(a>c)
    {
        t=a;a=c;c=t;
    }
    if(b>c)
    {
        t=b;b=c;c=t;
    }
    m=a+b;
    if(m<=c)
        cout<<"This is not a triangle."<<endl;
    else 
    {
        if(a==b&&b!=c)
        {
            if(a*a+b*b==c*c)
                cout<<"This is a Rt isosceles triangle."<<endl;
            else 
                cout<<"This is a isosceles triangle."<<endl;
        }
        else if(a==b&&b==c)
        {
            cout<<"This is a equilateral triangle."<<endl;
        }
        else if(a!=b&&a!=c)
        {
            if (a*a+b*b==c*c)
                cout<<"This is a Rt triangle."<<endl;
            else 
                cout<<"This is a common triangle."<<endl;
        }
    }
}
float triangle::Circumference ()
{
    float cir;
    cir=a+b+c;
    cout<<"The circumference is"<<cir<<endl;
}
float triangle::area ()
{
    float p,s;
    p=(a+b+c)/2;
    s=sqrt(p*(p-a)*(p-b)*(p-c));
    cout<<"The area is"<<s<<endl;
}



\\main.cpp
#include <iostream.h>
#include "triangle.h"
void main()
{
    triangle triangleA;
    triangleA.Setlength(10,30,30);
    cout<<triangleA.Circumference ()<<endl;
    cout<<triangleA.area ()<<endl;
    cout<<triangleA.Judgetype ()<<endl;
}
//楼主还是有很多地方需要注意,再接再厉!


[此贴子已经被作者于2016-4-9 17:57编辑过]


未佩好剑,转身便已是江湖
2016-04-09 17:55
快速回复:第一次写类 不知道哪里错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.045650 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved