- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Haskell Program to Find the Surface area and Volume of Cuboid
This tutorial discusses writing a program to find the Surface area and volume of a cuboid in the Haskell programming language.
A cuboid is a solid shape that has six rectangular faces. A cuboid has three dimensions length, breadth, and height. The surface area of a cuboid is the total area of the six rectangular faces i.e 2*length*breadth + 2*length*height + 2*breadth*height. The volume of the cuboid is length*breadth*height. As volume is area*height.
In this tutorial we see,
- Program to find the surface area of a cuboid.
- Program to find the volume of a cuboid.
Algorithm Steps
- Take input or initialize the variables.
- Implement the program logic to compute the surface area and volume of the cuboid.
- Print or display the surface area and volume.
Example 1
Program to find the surface area of a cuboid.
-- function declaration surfaceArea :: Float->Float->Float->Float -- function definition surfaceArea a b h = 2*a*b + 2*a*h + 2*b*h main = do -- declaring and initializing variables let a = 5 let b = 4 let h = 3 -- computing the surface area let area = surfaceArea a b h -- printing the surface area print ("The surface area of a cuboid with length, breadth, and height as " ++ show a ++ ", "++show b ++ ", and " ++ show h ++" is:") print (area)
Output
"The surface area of a cuboid with length, breadth, and height as 5.0, 4.0, and 3.0 is:" 94.0
In the above program, we declared a function surfaceArea as such it takes three floats as arguments and returns a float. In its function definition, three arguments are accepted a, b, and h. Where a, b, and h are length, breadth, and height respectively. The surface area is computed and returned. In the main function, three variables for length, breadth, and height of the cuboid a, b, and c are declared and initialized with values 5, 4, and 3 respectively. The function surfaceArea is invoked with these initialized variables as arguments. As this function returns the surfaceArea of the cuboid, the returned output is loaded into a variable area. Finally, the surface area of the cuboid is printed with the print function.
Note − The function show takes the argument of a number and returns the parsed string of a number. “++” is an operator to concatenate strings in Haskell.
Example 2
Program to find the volume of a cuboid.
-- function declaration volume :: Float->Float->Float->Float -- function definition volume a b h = a*b*h main = do -- declaring and initializing variables let a = 5 let b = 4 let h = 3 -- computing the volume let vol = volume a b h -- printing the volume print ("The volume of a cuboid with length, breadth, and height as " ++ show a ++ ", "++show b ++ ", and " ++ show h ++" is:") print (vol)
Output
"The volume of a cuboid with length, breadth, and height as 5.0, 4.0, and 3.0 is:" 60.0
In the above program, we declared a function volume as such it takes three floats as arguments and returns a float. In its function definition, three arguments are accepted a, b, and h. Where a, b, and h are length, breadth, and height respectively. The volume is computed and returned. In the main function, three variables for length, breadth, and height of the cuboid a, b, and c are declared and initialized with values 5, 4, and 3 respectively. The function volume is invoked with these initialized variables as arguments. As this function returns the volume of the cuboid, the returned output is loaded into a variable vol. Finally, the surface area of the cuboid is printed with the print function.
Conclusion
In this tutorial, we discussed implementing programs to find the surface area and volume of the cuboid in the Haskell programming language.
- Related Articles
- Java Program to Find the Surface area and Volume of Cuboid
- Swift Program to Find the Surface area and Volume of Cuboid
- Kotlin Program to Find the Surface Area and Volume of Cuboid
- Program for Volume and Surface Area of Cuboid in C++
- How to find the Surface area and Volume of Cuboid in Golang?
- Haskell Program to calculate the volume and area of Cone
- Haskell Program to calculate the volume and area of Sphere
- Haskell Program to calculate the volume and area of the Cylinder
- Golang program to Calculate the Volume, Diagonal and Area of a Cuboid?
- Haskell Program to calculate the volume, diagonal, and area of Cuboids
- Two cubes each of volume $27\ m^{3}$ are joined end to end. Find the surface area of the resulting cuboid.
- Two cubes each of volume $64\ cm^3$ are joined end to end. Find the surface area of the resulting cuboid.
- Two cubes, each of volume $512\ cm^3$ are joined end to end. Find the surface area of the resulting cuboid.
- 2 cubes each of volume $64\ cm^3$ are joined end to end. Find the surface area of the resulting cuboid."
- Program for Volume and Surface Area of Cube in C++
