CIS 218 – C# Programming Lab 10 - 20 points Using a Subclass
Due: Friday, Nov. 7 by 11:59pm
Instructions: Create a C# program that uses a class named Triangle (shown below) in order to produce a subclass of Triangle called Prism. Use the program to create a Prism object that calculates the volume and surface area of the Prism when supplied the width, height, and length of the Prism. The volume of the Prism should be calculated by multiplying the area of the triangle by the length of the Prism.
Prompt the user for the values of width, height, and length. Validate these values to make sure they are not negative. If a negative value is entered, force the user to make another entry. If all three values are zero, use a default constructor that you create for Prism that takes the default value of width and height from Triangle and assigns a value of 10 to length in the default constructor of Prism. Within the subclass Prism include an overriding method named findArea() that computes the surface area of the prism (the sum of the areas of all five sides). Obtain the area of the end of the prism from the findArea() method in the Triangle class. Use this value and the area of each side to compute the total surface area of a Prism. (ie., surface area = 2 times the area of an end plus the three sides. You many assume that the ends are isosceles triangles. How do you find the area of an isosceles triangle? Look it up! You will also need to calculate the length of the slanting side so you can use it to find the surface area. Welcome to Geometry 101!)
Print the values of width, height, length, volume, and surface area before asking the user if he/she would like to create another Prism. Round all output results to 2 decimal places. Display an appropriate message when the user enters 'n' or 'N'.
public class FLastLab10
{ . . .
}
public class Triangle
{ protected double width, height; // protected allows the subclass access to these
public Triangle ()
{ // default constructor
DO NOT ADD ANY MORE METHODS TO THE TRIANGLE CLASS! width = 7;
DO NOT ADD ANY MORE METHODS TO THE TRIANGLE CLASS!
height = 8;
public Triangle (double w, double h)
{ width = w;
height = h;
public double findArea()
{ return (width * height * 0.5);
(continued)
public class Prism : Triangle
{ // code a default constructor, another constructor, a method for the volume,
// and a method named findArea() for the surface area; Also code a method // named displayData within the Prism class to print the desired output.
Submit your program (FLastLab10.cs) before the deadline. Your output should appear similar to that shown below:
Sample output:
Lab 10 has started for Your Name
Enter the value for width 5.1
Enter the value for height 9.4
Enter the value for Length 6.7
The width of the Prism is xx.x
The height of the Prism is xx.x
The length of the Prism is xx.x
The Volume is xxx.xx cubic units
The Surface area is xxx.xx square units
Would you like to enter more data (Y/N) Y
Enter the value for width -5.6
The width many not be Negative! Please re-enter!
Enter the value for width 8.1
Enter the value for height -5.6
The height many not be Negative! Please re-enter!
Enter the value for height 6.8
. . .
Lab 10 has successfully terminated for Yourname