formula_3d_shape_lib/
cylinder.rs

1//! # This Module for cylinder Shape
2//! 
3//! - This module take cylinder's radius and height as input parameter
4//! - This module gives output cylinder's volume, surface area, summary
5
6use super::common_formula::Formula;
7use std::f32::consts::PI;
8
9
10
11/// This is struct for Cylinder
12/// It has two members
13/// radius and height
14#[derive(Debug)]
15pub struct Cylinder
16{
17	/// radius of a Cylinder
18	pub radius: f32,
19	/// height of a Cylinder
20	pub height: f32,
21}
22
23impl Cylinder
24{
25	/// It will create new Cylinder instance 
26	///
27	///
28	/// # Examples
29	///
30	/// Basic usage:
31	///
32	/// ```
33	/// use formula_3d_shape_lib::cylinder::Cylinder;
34	/// let cylinder1 = Cylinder::new(4.0, 10.0);
35	/// ```
36	pub fn new(radius:f32, height:f32) -> Cylinder
37	{ 
38		Cylinder {
39		radius,
40		height,
41		} 
42	}
43}
44
45
46
47
48impl Formula for Cylinder
49{
50	/// this function gives the volume of cylinder
51  /// # Examples
52	///
53	/// Basic usage:
54	///
55	/// ```
56	/// use formula_3d_shape_lib::cylinder::Cylinder;
57	/// use formula_3d_shape_lib::common_formula::Formula;
58	/// let cylinder1 = Cylinder::new(4.0, 10.0);
59	/// let vol = cylinder1.get_volume();
60	/// ```
61	fn get_volume(&self) -> f32
62	{
63		return PI * self.radius * self.radius * self.height;
64	}
65
66	/// This function gives the surface area of cylinder
67  /// # Examples
68	///
69	/// Basic usage:
70	///
71	/// ```
72	/// use formula_3d_shape_lib::cylinder::Cylinder;
73	/// use formula_3d_shape_lib::common_formula::Formula;
74	/// let cylinder1 = Cylinder::new(4.0, 10.0);
75	/// let surface = cylinder1.get_surface_area();
76	/// ```
77	fn get_surface_area(&self) -> f32
78	{
79		return 2.0* PI * self.radius * self.height + 2.0 * PI * self.radius * self.radius;
80	}
81}
82
83impl Cylinder
84{
85	/// this implementation gives the summary of Cylinder
86	/// # Examples
87	///
88	/// Basic usage:
89	///
90	/// ```
91	/// use formula_3d_shape_lib::cylinder::Cylinder;
92	/// use formula_3d_shape_lib::common_formula::Formula;
93	/// let cylinder1 = Cylinder::new(4.0, 10.0);
94	/// cylinder1.summary();
95	/// ```
96	pub fn summary(&self)
97	{
98		println!("summary:");
99		println!("radius : {} & height : {}", self.radius, self.height);
100		println!("volume is {} and surface area is {}", self.get_volume(), self.get_surface_area());
101	}
102}