Question

Write a C# application that implements a class ‘Prism’ with the following members. Five private data...

  1. Write a C# application that implements a class ‘Prism’ with the following members.
    1. Five private data members ‘length’, ‘height’, ‘width’, ‘Volume’ and ‘Area’ of double data type.
    2. Implement the constructor Prism( ) to accept the length, height, and width of the rectangular prism from the user.
    3. Implement three methods, Vol(), Area(), and Result()
      1. Vol() – to calculate the volume of the prism using the formulae Volume= length ×height ×width
      2. Area() – to calculate the surface area of the prism using the formulae SurfaceArea=2×length×height+2×length×width+2×width×height
      3. Result() – to display the volume and surface area of the prism.

In the Main method, create an object of the above class, and use the object to call the methods to display the output as shown below.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:
using System;

class Prism
{
//declaring variales
private double length;   
private double breadth;
private double height;
private double area;
private double volume;
  
//constructor to input length,breadth and width
public Prism()
{
Console.WriteLine("Enter Length of rectangular prism: ");
length = Convert.ToDouble(Console.ReadLine());
  
Console.WriteLine("Enter Height of rectangular prism: ");
height = Convert.ToDouble(Console.ReadLine());
  
Console.WriteLine("Enter breadth of rectangular prism: ");
breadth = Convert.ToDouble(Console.ReadLine());
  
  
}
  
//function to calculate volume
public void Volume()
{
  
volume=length*breadth*height;
}
//function to calculate area
public void Area()
{
area = (2*length*height) + (2*length*breadth) + (2*breadth*height);
}
//function to display voulume and area
public void Result()
{
Console.WriteLine("\nVolume of rectangular prism is: {0}",volume);
Console.WriteLine("Surface area of rectangular prism is: {0}",area);
}
static void Main()
{
//creating object
Prism prism = new Prism();
//calling class functions
prism.Volume();
prism.Area();
prism.Result();

}
}

Code photo:
8 9 { 18 19 1 using System; 2 3 4 class Prism 5 { 6 //declaring variales 7 private double length; private double breadth; pri40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 public void Result() Console.WriteLine(\nVolume of rectangular prism is: {0}

Output:
Enter Length of rectangular prism: 10 Enter Height of rectangular prism: 12 Enter breadth of rectangular prism: 15 Volume of

Add a comment
Know the answer?
Add Answer to:
Write a C# application that implements a class ‘Prism’ with the following members. Five private data...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ******** IN JAVA ********* I have a program that I need help debugging. This program should...

    ******** IN JAVA ********* I have a program that I need help debugging. This program should ask a user to input 3 dimensions of a rectangular block (length, width, and height), and then perform a volume and surface area calculation and display the results of both. It should only be done using local variables via methods and should have 4 methods: getInput, volBlock, saBlock, and display (should be void). I have most of it written here: import java.util.*; public class...

  • Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default...

    Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default constructor -- that calls the default super class constructor and sets the default height to 0- Overloaded constructor with three parameters (length, width and height) – that calls the two parameterized super class constructor passing in length and width passed and sets the height to passed height.- setDimension method with three parameters (length, width, height) – call the super class setDimension and pass in...

  • Write a java program that computes the total surface area of a rectangular prism. There are...

    Write a java program that computes the total surface area of a rectangular prism. There are six sides, so the area of all six sides has to the summed to get the total area. The program should ask the user to enter the length (L), width (W) and the height )H) for the object in inches. Create a separate method from the main to calculate the area (name the method calcArea). The output of calcArea will return a double. Output;...

  • In a c++ program, Implement a Pyramid class with base and height as data members and...

    In a c++ program, Implement a Pyramid class with base and height as data members and surface area() and volume() calculations as member functions.

  • Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class...

    Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class should have a zero-argument constructor that initializes each data member to 0. It should have member functions named calcPerimeter() and calcArea() that calculate the perimeter and area of a rectangle respectively, a member function setLength() and setWidth() to set the length and width, member functions getLength() and getWidth() to return the length and width, and a member function showData() that displays the rectangle’s length,...

  • Write a Java program with the following requirements: Rectangle that implements Shape2D - instance variables height,...

    Write a Java program with the following requirements: Rectangle that implements Shape2D - instance variables height, width Block that implements Shape3D - instance variables height, width, depth Add appropriate parameterized constructors for each class. Implement the abstract methods to make each class a Shape2D, Shape3D, or both. Make the main method use each of these to print out the area of a rectangle, and the area and volume of a block.

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

  • This exercise guides you through the process of converting an Area and Perimeter application from a...

    This exercise guides you through the process of converting an Area and Perimeter application from a procedural application to an object-oriented application. Create and use an object 1. Open the project named ch04_ex2_Area and Perimeter that’s stored in the ex_starts folder. Then, review the code for the Main class. 2. Create a class named Rectangle and store it in the murach.rectangle package. 3. In the Rectangle class, add instance variables for length and width. The, code the get and set...

  • Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double...

    Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double variable that holds the rooms length(in feet). Breadth: The double variable that holds the rooms breadth(in feet). Height: Double variable that holds rooms height in feet. Color: String object that holds the color you want the room to be painted with. The class should have a constructor to initialize the fields for a particular instance (or object) of the class as given: All double...

  • Write a C Program 2. Write a program which defines a (hollow rectangular) prism as a...

    Write a C Program 2. Write a program which defines a (hollow rectangular) prism as a structure consisting of: length(int) width(int) height(int) • weight(double) • contents(char [25]) Initialize the structure with default values 10, 6, 3, 4.5, and "Best Jewelry" Ask user for new length, width and height and then display Contents, volume, and sum of dimensions

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT