Looking for Central Point (C++)

Finding the midpoint of a line that ends its points are A (x1, y1) and B (x2, y2).

Read the insert end point of line A (x1, y1) and B (x2, y2), determine the midpoint of the line and then write the output of the midpoint of a line C (x3, y3).

algoritma :

Deklarasi
x1 , y1, x2, y2 : integer {input}
x3, y3 : integer {output}

Deskripsi
Read A (x1 , y1) dan B( x2, y2)
x3 <– (x2 +x1 )/2
y3 <– (y2 + y1)/2

program C++

#include <iostream.h>
#include <conio.h>

class titiktengah {
public:
void titikujung();
void hitung();
private:
int x1,x2,y1,y2,A,B;
};
void titiktengah::titikujung(){
cout<<"MENCARI TITIK TENGAH DARI SEBUAH GARIS"<<endl;
cout<<"nilai x1 : "; cin>>x1;
cout<<"nilai x2 : "; cin>>x2;
cout<<"nilai y1 : "; cin>>y1;
cout<<"nilai y2 : "; cin>>y2;
cout<<endl;
}
void titiktengah::hitung(){
A=(x1+x2)/2;
B=(y1+y2)/2;
cout<<"jadi titik tengah dari sebuah garis yaitu "<< A <<" , " << B;
}
int main(){
titiktengah x;
x.titikujung();
x.hitung();

getch();
return 0;
}
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: