Week five project three-multi-file organization multiple classes

Source: Internet
Author: User

Main.cpp

#include <iostream> #include "header.h" using namespace Std;int Main () {    CPoint X (2,5), Y (5,2), Z (7,8);    Ctriangle Tri1 (x, y, z);    cout<< "The circumference of the triangle is:" <<tri1.perimeter () << ", Area:" <<tri1.area () <<endl<<endl;    cout<< "The Triangle" << (Tri1.isrighttriangle ()? " Yes ":" not ") <<" right triangle "<<endl;    cout<< "The Triangle" << (Tri1.isisoscelestriangle ()? " Yes ":" not ") <<" isosceles triangle "<<endl;    return 0;}


Header.cpp

#include <iostream> #include <cmath> #include "header.h" using namespace std;  Cpoint::cpoint (double xx,double yy) {x=xx; Y=yy;}  void Cpoint::input () {char ch;  cout<< "Please enter the coordinate point (format x, y):";    while (1) {cin>>x>>ch>>y;    if (ch== ', ') break;  cout<< "Input data format does not conform to specifications, please re-enter \ n"; }}void Cpoint::output () {cout<< "(" <<x<< "," <<y<< ")" &LT;&LT;ENDL;}  Double CPoint::d Istance1 (CPoint p) const{double D;  D=sqrt ((p.x-x) * (p.x-x) + (p.y-y) * (p.y-y)); return D;}  void Ctriangle::settriangle (CPoint &x,cpoint &y,cpoint &z) {a=x;  B=y; C=z;}  Double ctriangle::p erimeter (void) {double A=b.distance1 (C), B=c.distance1 (a), C=a.distance1 (B); return (A + B + c);}  Double Ctriangle::area (void) {double A=b.distance1 (C), B=c.distance1 (a), C=a.distance1 (B);  Double s = (A + B + c)/2; return sqrt (S * (s-a) * (s-b) * (S-C));}  BOOL Ctriangle::isrighttriangle () {double A=b.distance1 (C), B=c.distance1 (a), C=a.distance1 (B);  Double max=a; If(B>max) max=b;  if (C>max) max=c; if ((max==a) && (ABS (A*A-B*B-C*C) <1e-7) | | ((max==b) && (ABS (B*B-A*A-C*C) <1e-7)) | |    ((max==c) && (ABS (C*C-B*B-A*A) <1e-7)))  return true; else return false;}  BOOL Ctriangle::isisoscelestriangle () {double A=b.distance1 (C), B=c.distance1 (a), C=a.distance1 (B); if (ABS (a) <1e-7) | | (ABS (B-C) <1e-7) | |    (ABS (C-A) <1e-7))  return true; else return false;}


Header.h

#ifndef header_h_included#define header_h_includedclass cpoint{private:  double x;  Double y;public:  CPoint (double xx=0,double yy=0);  Double Distance1 (CPoint p) const;  void input ();  void output ();}; Class Ctriangle{public:  ctriangle (CPoint &x,cpoint &y,cpoint &z): A (X), B (Y), C (Z) {}  void Settriangle (CPoint &x,cpoint &y,cpoint &z);  Double perimeter (void);  Double area (void);  BOOL Isrighttriangle ();  BOOL Isisoscelestriangle ();p rivate:  CPoint a,b,c;}; #endif//header_h_included


Operation Result:

Learning experience:

Good study Day Day up

Fifth week item three-multi-file organization multiple classes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.