Tgiác, nhập kc cv dt, Phân số + - * /

***** Tgiác, nhập, kc, cv ,dt :

#include<iostream.h>

#include<math.h>

typedef struct

{

<tab>float x, y;

}DIEM;

void nhap(DIEM &p);

float kc(DIEM P, DIEM Q);

float cv(DIEM A, DIEM B, DIEM C);

float dt(DIEM A, DIEM B, DIEM C);

void main()

{

<tab>clrscr ();

<tab>DIEM A,B,C;

<tab>cout<<"

Nhap toa do dinh A:";

<tab>nhap(A);

<tab>cout<<"

Nhap toa do dinh B:";

<tab>nhap(B);

<tab>cout<<"

Nhap toa do dinh C:";

<tab>nhap(C);

<tab>float DT=dt(A,B,C);

<tab>float CV=cv(A,B,C);

<tab>cout<<"

DT = "<<DT;

<tab>cout<<"

CV = "<<CV;

<tab>getch ();

}

void nhap(DIEM &p)

{

<tab>cout<<"

x = ";

<tab>cin>>p.x;

<tab>cout<<"

y = ";

<tab>cin>>p.y;

}

float kc(DIEM P, DIEM Q)

{

<tab>return sqrt((P.x-Q.x)*(P.x-Q.x) + (P.y-Q.y)*(P.y-Q.y));

}

float cv(DIEM A, DIEM B, DIEM C)

{

<tab>float a,b,c,p;

<tab>a=kc(A,C);

<tab>b=kc(B,C);

<tab>c=kc(A,B);

<tab>p=a+b+c;

<tab>return p;

}

float dt(DIEM A, DIEM B, DIEM C)

{

<tab>float a,b,c,p,s;

<tab>a=kc(A,C);

<tab>b=kc(B,C);

<tab>c=kc(A,B);

<tab>p=(a+c+b)/2;

<tab>s=sqrt(p*(p-a)*(p-b)*(p-c));

<tab>return s;

}

__________

**** : PHÂN SỐ, + - * /

3 dòng include conio iostream.h math.h

typedef struct

{

<tab>float tu, mau;

}PHANSO;

void nhap (PHANSO &x);

void xuat (PHANSO x);

void rutgon(PHANSO &x);

PHANSO tong (PHANSO A, PHANSO B);

PHANSO hieu (PHANSO A, PHANSO B);

PHANSO tich  (PHANSO A, PHANSO B);

PHANSO thuong(PHANSO A, PHANSO B);

void main ()

{

<tab>clrscr();

<tab>PHANSO A, B, kq;

<tab>cout<<"

Nhap phan so A:";

<tab>nhap(A);

<tab>cout<<" Phan so A =";

<tab>xuat(A);

<tab>cout<<"

Nhap phan so B:";

<tab>nhap(B);

<tab>cout<<" Phan so B =";

<tab>xuat(B);

<tab>cout<<"

+ - * / cua A va B la:

";

<tab>kq=tong(A,B);

<tab>cout<<"

TONG   = ";

<tab>xuat(kq);

<tab>kq=hieu(A,B);

<tab>cout<<"

HIEU   = ";

<tab>xuat(kq);

<tab>kq=tich(A,B);

<tab>cout<<"

TICH   = ";

<tab>xuat(kq);

<tab>kq=thuong(A,B);

<tab>cout<<"

THUONG = ";

<tab>xuat(kq);

<tab>getch ();

}

void nhap(PHANSO &x)

{

<tab>cout<<"

tu = ";

<tab>cin>>x.tu;

<tab>cout<<" mau= ";

<tab>cin>>x.mau;

}

void xuat(PHANSO x)

{

<tab>cout<<" "<< x.tu<<"/"<<x.mau;

}

void rutgon(PHANSO &x)

{

<tab>int a=abs(x.tu);

<tab>int b=abs(x.mau);

<tab>while(a*b!=0)

<tab>{

<tab><tab>if(a>b)

<tab><tab>{

<tab><tab><tab>a -= b;

<tab><tab>}

<tab><tab>else

<tab><tab>{

<tab><tab><tab>b -= a;

<tab><tab>}

<tab>}

<tab>x.tu = x.tu/(a+b);

<tab>x.mau=x.mau/(a+b);

}

PHANSO tong(PHANSO A, PHANSO B)

{

<tab>PHANSO kq;

<tab>kq.tu=A.tu*B.mau + B.tu*A.mau;

<tab>kq.mau=A.mau*B.mau;

<tab>rutgon(kq);

<tab>return(kq);

}

PHANSO hieu(PHANSO A, PHANSO B)

{

<tab>PHANSO kq;

<tab>kq.tu=A.tu*B.mau - B.tu*A.mau;

<tab>kq.mau=A.mau*B.mau;

<tab>rutgon(kq);

<tab>return (kq);

}

PHANSO tich(PHANSO A, PHANSO B)

{

<tab>PHANSO kq;

<tab>kq.tu=A.tu*B.tu;

<tab>kq.mau=A.mau*B.mau;

<tab>rutgon(kq);

<tab>return (kq);

}

PHANSO thuong(PHANSO A, PHANSO B)

{

<tab>PHANSO kq;

<tab>kq.tu=A.tu*B.mau;

<tab>kq.mau=A.mau*B.tu;

<tab>rutgon(kq);

<tab>return (kq);

}

Bạn đang đọc truyện trên: AzTruyen.Top

Tags: