-
Notifications
You must be signed in to change notification settings - Fork 0
/
02.20.SlopeLine.cpp
83 lines (69 loc) · 2.91 KB
/
02.20.SlopeLine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
/*
========================================================================
02.20. Slop Of A Line
by : #bayuyudhasaputra
lang : IDN (Bahasa Indonesia)
------------------------------------------------------------------------
Masalah :
Write a program that prompts the user to enter the coordinates of two
points (x1, y1) and (x2, y2), and displays the slope of the line that
connects the two points. The formula of the slope is (y2 - y1)/(x2 - x1).
==========================================================================
*/
int main()
{
std::cout << std::endl
<< " ============================================================ "
<< std::endl;
// 1. Input absis titik pertama
std::cout << " Input absis titik A (Misal. 4.5) : ";
double absisTitik1;
std::cin >> absisTitik1;
std::cout << std::endl;
// 2. Input ordinat titik pertama
std::cout << " Input ordinat titik A (Misal. -5.5) : ";
double ordinatTitik1;
std::cin >> ordinatTitik1;
std::cout << std::endl;
// 3. Tampilkan titik pertama
std::cout << " ----------------------------------------------------------- "
<< std::endl
<< " Anda menginput titik A"
<< "(" << absisTitik1 << " , " << ordinatTitik1 << ")"
<< std::endl
<< " ----------------------------------------------------------- "
<< std::endl;
// 4. Input absis titik kedua
std::cout << " Input absis titik B (Misal, 6.6) : ";
double absisTitik2;
std::cin >> absisTitik2;
std::cout << std::endl;
// 5. Input ordinat titik kedua
std::cout << " Input ordinat titik kedua (Misal, -6.5) : ";
double ordinatTitik2;
std::cin >> ordinatTitik2;
std::cout << std::endl;
// 6. Tampilkan titik kedua
std::cout << " ----------------------------------------------------------- "
<< std::endl
<< " Anda menginput titik B"
<< "(" << absisTitik2 << " , " << ordinatTitik2 << ")"
<< std::endl
<< " ----------------------------------------------------------- "
<< std::endl;
// 7. Hitung gradien garis
double gradien;
gradien = (ordinatTitik2 - ordinatTitik1) / (absisTitik2 - absisTitik1);
// 8. Tampilkan gradien garis
std::cout << " Gradien garis AB adalah " << gradien
<< std::endl
<< " ============================================================ "
<< std::endl;
return 0;
}
/*
Liang. 2014. Introduction to Programming with C++ 3rd Edition.
London : Pearson Education.
https://www.pearson.com/en-us/subject-catalog/p/Liang-Companion-Website-for-Introduction-to-Programming-with-C-Access-to-Videonotes-3rd-Edition/P200000003422/978013338026
*/