Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Box[] arr = new Box[5];
- for (int i = 0; i < arr.Length; i++) {
- Console.Write("Enter Length: ");
- double length = double.Parse(Console.ReadLine());
- Console.Write("Enter Width: ");
- double width = double.Parse(Console.ReadLine());
- Console.Write("Enter Height: ");
- double height = double.Parse(Console.ReadLine());
- arr[i] = new Box(length, width, height);
- }
- for (int i = 0; i < arr.Length; i++)
- Console.WriteLine(arr[i].ToString());
- }
- }
- }
- //Box.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Box
- {
- private double length;
- private double width;
- private double height;
- public Box(double length, double width, double height)
- {
- this.length = length;
- this.width = width;
- this.height = height;
- }
- public double GetLength()
- {
- return this.length;
- }
- public double GetWidth()
- {
- return this.width;
- }
- public double GetHeight()
- {
- return this.height;
- }
- public void SetLength(double length)
- {
- this.length = length;
- }
- public void SetWidth(double width)
- {
- this.width = width;
- }
- public void SetHeight(double height)
- {
- this.height = height;
- }
- public double GetVolume()
- {
- return this.height * this.width * this.length;
- }
- public string ToString()
- {
- return "The box's length is " + this.length + ", width is " + this.width + ", height is " + this.height + ", volume is " + this.GetVolume();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement