3. Construct a set of user-defined functions based on the following table. Each function must receive the relevant parameters and return the total surface area and volume of the respective geometric shape.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

WHY DOES MY CODE APPEARS TO HAVE ERROR? PLEASE CHECK MY CODING (USING R PROGRAMMING)

 

#For Cuboid
cuboid <- function(l, w, h)
  calcArea <- function(l, w, h)
{
  Area <- 2*((l*w) +(l*h) +(w*h))
  return(Area)
}
  calcvol <- function(l, w, h)
{
    vol <- l*w*h
    return(vol)
  }

#For cube 
cube <- function(a)
  calcArea <- function(a)
{
  Area <- 6*a*a
  return(Area)
  }

calcvol <- function(a)
{
  vol <- a*a*a
return(vol)
  }
  
  
#For circular cylinder
cir_cylinder <- function(r, h)
  calcArea <- function(r, h)
{
    Area <- 2*3.14*r*(r+h)
    return(Area)
  }
calcvol <- function(r, h) 
{
  vol <- 3.14*r*r*h
  return(vol)
}
  
#For circular cone 
cir_cone <- function(s, h, r)
  calcArea <- function(s, h, r)
{
  Area <- 3.14*r*(r+s)
  return(Area)
  }
calcvol <- function(s, h, r) 

  vol <- ((3.14*r*r*h) /3)
 return (vol)
  }

#For Sphere
sphere <- function(r)
  calcArea <- function(r)
{
  Area <- 4*3.14*r*r
  return(Area)
  }
  calcvol <- function(r)
{
  vol <- (4/3) *3.14*r*r*r
  return(vol)
}

#For hemisphere
hemi_sphere <- function(r)
  calcArea<- function(r)
{
  Area <- 3*3.14*r*r
  return(Area)
  }
  calcvol <- function(r)
{
  vol <- (2/3) *3.14*r*r*r
  return(vol)
  }
 

if(interactive()){
  l<-as.numeric(readline(prompt="Enter the length (l) of the cuboid "))
  w<-as.numeric(readline(prompt="Enter the width (w) of the cuboid "))
  h<-as.numeric(readline(prompt="Enter the height (h) of the cuboid "))
  print(paste("The area of the cuboid is ", calcArea(l, w, h)))
  print(paste("The volume of the cuboid is ", calcvol(l, w, h)))
}

if(interactive()){
  a<-as.numeric(readline(prompt="Enter the length (a) of the cube "))
  print(paste("The area of the cube is ", calcArea(a)))
  print(paste("The volume of the cube is ", calcvol(a)))
}

if(interactive()){
  r<-as.numeric(readline(prompt="Enter the length (r) of the circular cylinder "))
  h<-as.numeric(readline(prompt="Enter the height (h) of the circular cylinder "))
  print(paste("The area of the circular cylinder is ", calcArea(r,h)))
  print(paste("The volume of the circular cylinder is ", calcvol(r,h)))
}

if(interactive()){
  s<-as.numeric(readline(prompt="Enter the length (s) of the circular cone "))
  h<-as.numeric(readline(prompt="Enter the height (h) of the circular cone "))
  r<-as.numeric(readline(prompt="Enter the radius (r) of the circular cone "))
  print(paste("The area of the circular cone is ", calcArea(s, h, r)))
  print(paste("The volume of the circular cone is ", calcvol(s, h, r)))
}

if(interactive()){
  r<-as.numeric(readline(prompt="Enter the radius (r) of the sphere "))
  print(paste("The area of the sphere is ", calcArea(r)))
  print(paste("The volume of the sphere is ", calcvol(r)))
}

if(interactive()){  
  r<-as.numeric(readline(prompt="Enter the radius (r) of the hemi_sphere "))
  print(paste("The area of the hemi_sphere is ", calcArea(r)))
  print(paste("The volume of the hemi_sphere is ", calcvol(r)))
}

3. Construct a set of user-defined functions based on the following table. Each function must receive the
relevant parameters and return the total surface area and volume of the respective geometric shape.
Name
Cuboid
Cube
Right circular cylinder
Right circular cone
Sphere
Hemi-sphere
Figure
1 = length
w = width
h = height
a
a = length
r = radius
h = height
s = slant height
h = height
r = radius
S
r = radius
0:0
r = radius
h
h
W
Function Name
cuboid
cube
cir_cylinder
cir_cone
sphere
hemi_sphere
Transcribed Image Text:3. Construct a set of user-defined functions based on the following table. Each function must receive the relevant parameters and return the total surface area and volume of the respective geometric shape. Name Cuboid Cube Right circular cylinder Right circular cone Sphere Hemi-sphere Figure 1 = length w = width h = height a a = length r = radius h = height s = slant height h = height r = radius S r = radius 0:0 r = radius h h W Function Name cuboid cube cir_cylinder cir_cone sphere hemi_sphere
Console Terminal x Background Jobs x
R R 4.2.1 - -/-
LUTLIMI
+ {
++ A+
TUTTCL TOITETT
vol <- 1*w*h
return (vol)
ww.g
117
}
> if (interactive()) {
1<-as.numeric (readline (prompt="Enter the length (1) of the cuboid "))
+ w<-as.numeric (readline (prompt="Enter the width (w) of the cuboid "))
+ h<-as.numeric (readline (prompt="Enter the height (h) of the cuboid "))
+ print (paste("The area of the cuboid is ", calcArea (1, w, h)))
print (paste("The volume of the cuboid is ",
calcvol(1, w,
calcvol(1, w, hɔɔɔ
+
+ }
Enter the length (1) of the cuboid 2
Enter the width (w) of the cuboid 2
Enter the height (h) of the cuboid 2
Error in calcArea (1, w, h): could not find function "calcArea"
Transcribed Image Text:Console Terminal x Background Jobs x R R 4.2.1 - -/- LUTLIMI + { ++ A+ TUTTCL TOITETT vol <- 1*w*h return (vol) ww.g 117 } > if (interactive()) { 1<-as.numeric (readline (prompt="Enter the length (1) of the cuboid ")) + w<-as.numeric (readline (prompt="Enter the width (w) of the cuboid ")) + h<-as.numeric (readline (prompt="Enter the height (h) of the cuboid ")) + print (paste("The area of the cuboid is ", calcArea (1, w, h))) print (paste("The volume of the cuboid is ", calcvol(1, w, calcvol(1, w, hɔɔɔ + + } Enter the length (1) of the cuboid 2 Enter the width (w) of the cuboid 2 Enter the height (h) of the cuboid 2 Error in calcArea (1, w, h): could not find function "calcArea"
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY