Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PROGRAMMING Using Visual stuido. C# Object-Oriented application. a) Write an obj

ID: 3598491 • Letter: P

Question

PROGRAMMING Using Visual stuido. C#

Object-Oriented application.

a) Write an object-oriented program that calculates the surface area and volume of a cylinder.

b) Define Cylinder Class (Cylinder.cs)

Define properties

Radius

Height

Define 2 methods

calcSurfacearea() research the formula

calcVolume() research the formula

c) Place your codes in the Calculate button click method.

Define variables if needed

Instantiate your class / Constructor

Make calls to the object methods

Display outputs on read-only textboxes.

Explanation / Answer

//--------- Forms -------------//

//---- Class diagram -----------//

//------- Class code -------------//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chegg_vol
{
    class Cylinder
    {
        // define the required variables
        private int radius;
        private int height;

        // define the default contructor as we would have a parameterised constructor
        public Cylinder()
        {
            //
            Console.WriteLine("Empty Cylinder object initialised ");
            //
            //throw new System.NotImplementedException();
        }

        // define the parameterised constructor
        public Cylinder(int rad, int ht)
        {
            //
            radius = rad;
            //
            height = ht;
            //throw new System.NotImplementedException();
        }

        // define the property for radius
        public int Radius
        {
            get
            {
                //
                return radius;
                //throw new System.NotImplementedException();
            }

            set
            {
                //
                radius = value;
            }
        }

        // define the property for height
        public int Height
        {
            get
            {
                //
                return height;
                //throw new System.NotImplementedException();
            }

            set
            {
                //
                height = value;
            }
        }

        //
        public double calcSurfacearea()
        {
            double PI = 3.14; // initialise the value of PI to be used to calculate volume
            //
            double area;
            //
            area = (2 * PI * radius * height) + (2 * PI * radius * radius); // formula for surface area of cylinder
            //
            return area;
            //throw new System.NotImplementedException();
        }

        public double calcVolume()
        {
            //
            double PI = 3.14;
            //
            double vol;
            //
            vol = PI * (radius * radius) * height; // formula for volume of cylinder
            //
            return vol;
            //throw new System.NotImplementedException();
        }
        //

    }
}


// ----------- Calculate button callback handler ----------//

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Chegg_vol
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Cylinder c1 = new Cylinder(Convert.ToInt32(this.tBox_radius), Convert.ToInt32(this.tBox_height)); // create an object and invoke its constructor, pass values from the form for radius and height
            //
            Cylinder cX = new Cylinder();
            //
            cX.Radius = Convert.ToInt32(this.tBox_radius.Text); // use the properties to initialise the radius and height values from the form
            //
            cX.Height = Convert.ToInt32(this.tBox_height.Text);
            //
            this.tBox_vol.Text = Convert.ToString(cX.calcVolume());
            //
            this.tBox_area.Text = Convert.ToString(cX.calcSurfacearea());
            //
            //c1.sayHello();
        }
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote