rectangles: implement area method
This commit is contained in:
parent
e9f349d55c
commit
e011a4f94f
1 changed files with 11 additions and 0 deletions
|
|
@ -4,6 +4,12 @@ struct Rectangle {
|
||||||
height: u32,
|
height: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Rectangle {
|
||||||
|
fn area(&self) -> u32 {
|
||||||
|
self.width * self.height
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let width1 = 30;
|
let width1 = 30;
|
||||||
let height1 = 50;
|
let height1 = 50;
|
||||||
|
|
@ -29,6 +35,11 @@ fn main() {
|
||||||
"The area of the rectangle is {} square pixels.",
|
"The area of the rectangle is {} square pixels.",
|
||||||
area_struct(&rect)
|
area_struct(&rect)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"The area of the rectangle is {} square pixels.",
|
||||||
|
rect.area()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn area(width: u32, height: u32) -> u32 {
|
fn area(width: u32, height: u32) -> u32 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue