龙猫VV 龙猫VV
关注数: 9 粉丝数: 78 发帖数: 6,593 关注贴吧数: 42
求助,谢谢各位好人 #include<iostream> #include<math.h> #include<stdlib.h> using namespace std; class point { protected: double x,y; public: double getx(); double gety(); point(double,double); point(){}; }; point::point(double a,double b) {x=a;y=b;} double point::getx(){return x;} double point::gety(){return y;} class line:public point { private: point p1; public: line(double,double,double,double); double dis(); line(){}; }; line::line(double a, double b, double c, double d):point(a,b),p1(c,d){} double line::dis() { return sqrt(pow((getx()-p1.getx()),2)+pow((gety()-p1.gety()),2)); } class triangle { public: triangle(line line1,line line2,line line3):line1(line1),line2(line2),line3(line3) {} void distinguish() { double len1=line1.dis(),len2=line2.dis(),len3=line3.dis(); if( ((len1*len1+len2*len2)==len3*len3)||((len1*len1+len3*len3)==len2*len2)||((len2*len2+len3*len3)==len1*len1)) cout<<"三角形为直角三角形"<<endl; if(len1+len2<=len3||len1+len3<=len2||len2+len3<=len1) cout<<"不能再组成三角形"<<endl; else if(len1==len2&&len2==len3) cout<<"三角形为等边三角形"<<endl; else if(len1==len2||len1==len3||len2==len3) cout<<"三角形为等腰三角形"<<endl; else cout<<"三角形为普通三角形"<<endl; } void area() { double len1=line1.dis(),len2=line2.dis(),len3=line3.dis(); double len=(len1+len2+len3)/2; cout<<"三角形的面积为:"<<sqrt(len*(len-len1)*(len-len2)*(len-len3))<<endl; } private: line line1; line line2; line line3; }; void menu() { while(1) { cout<<"\t\t\tc++课程设计:三角形的种类与面积"<<endl; cout<<"\t**************************************************************"<<endl<<endl; cout<<" 判断三角形的种类和面积 退出 "<<endl<<endl; cout<<"“退出”请按0,按其他任意数字键进入功能"<<endl; int n; cin>>n; if(n==0) { cout<<"\t\t\t\t谢谢使用!"<<endl; return; } else { cout<<"请输入三个顶点:"<<endl; float x1,x2,x3,y1,y2,y3; cout<<"顶点1:"; cin>>x1>>y1; cout<<endl; cout<<"顶点2:"; cin>>x2>>y2; cout<<endl; cout<<"顶点3:"; cin>>x3>>y3; cout<<endl; line line1(x1,y1,x2,y2); line line2(x2,y2,x3,y3); line line3(x3,y3,x1,y1); triangle tri(line1,line2,line3); cout<<"请选择菜单:"<<endl; cout<<" 2 判断三角形的种类 3 输出三角形的面积"<<endl; cin>>n; switch(n) { case 2:tri.distinguish(); system("PAUSE"); system("CLS"); break; case 3:tri.area(); system("PAUSE"); system("CLS"); break; default:cout<<"输入错误!"<<endl; } } } } int main() { menu(); return 0; } 程序没有报错,只是判断三角形是否是直角三角形这项功能无法使用。 if( ((len1*len1+len2*len2)==len3*len3)||((len1*len1+len3*len3)==len2*len2)||((len2*len2+len3*len3)==len1*len1)) cout<<"三角形为直角三角形"<<endl;
首页 1 2 3 下一页