The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
triangle class
Posted by: Rob-Bot | December 1, 2010 @ 12:37am
C++ Code
[
Download
]
#include <iostream> #include <cmath> using namespace std; class triangle { private: //members int a; //declarations int b; int c; //Area = sq rt{s(s - a)(s - b)(s - c)} public: //methods "functions" triangle(); //declarations but no deffinitions void set_a(int d); void set_b(int e); void set_c(int f); int calc_perimeter(); double calc_area(); }; // definitions of methods (not-inline vs. inline) triangle::triangle() //refers to method in rectangle class { a = 5; b = 16; c = 15; // Triangle inequality theorem: A + B > C, B + C > A, A + C > B } void triangle::set_a(int d)// for cin { a = d; } void triangle::set_b(int e)// for cin { b = e; } void triangle::set_c(int f)// for cin { c = f; } int triangle::calc_perimeter() { return (a+b+c); } double triangle::calc_area() { double s = (a+b+c)/2; return (sqrt(s*(s - a)*(s - b)*(s - c))); } int main() { triangle t; // declaring OBJECT t of triangle class cout << "Perimeter: " << t.calc_perimeter() << endl << "Area: " << t.calc_area() << endl; cout << "Enter three sides of triangle Remember A + B > C, B + C > A, A + C > B: "; int g,h,i = 0; cin >> g >> h >> i; t.set_a(g); t.set_b(h); t.set_c(i); cout << "Perimeter: " << t.calc_perimeter() << endl << "Area: " << t.calc_area() << endl; return 0; }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.46 / 8
28 Votes