C# 实验九的试验要求

来源:百度知道 编辑:UC知道 时间:2024/06/04 13:54:30
完成一个完整的C#程序(严格按照题意要求)
(1)定义一个类cylinder,只有一个私有成员double变量y, 其他为公有成员变量。
(2)cylinder的构造函数被传递了两个参数double型的值r和h,分别表示了圆柱体的半径和高度。
(3)在类cylinder中包含了一个公有成员函数compute(),用来计算圆柱体的体积,体积存储在变量y中。包含一个公有成员函数vol(),用来输出每个cylinder对象的体积。
我自己只做得一点点:
using System;
class cylinder
{
double y;
public cylinder(double r, double h)
{
Console.WriteLine("请输入圆柱体的半径:");
r = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("请输入圆柱体的高度:");
h = Convert.ToDouble(Console.ReadLine());

}
public void compute(double r,double h)
{
double s=0.0;
s=Math.PI*r*r;
y=s*h;
return (y);

}
public void vol()
{
}

}

请高手帮修改或完成
请大家认真好一下题目要求好吗?

using System;
using System.Collections.Generic;
using System.Text;

namespace 百度_练习九
{
class cylinder
{
private double y;//体积
public double r, h;//半径和高
public cylinder(double a, double b)
{
r = a; h = b;
}
public void computer()
{
y = Math.PI * r * r * h;
}
public void vol()
{
Console.WriteLine("圆柱的体积为"+y);
}
}
class Program
{
static void Main(string[] args)
{
cylinder cy = new cylinder(2.0, 3.0);
cy.computer();
cy.vol();
}
}
}
//我也在学,程序写的很生疏。还有什么练习 我们共同探讨

LZ好强
没学过C#帮不了你

增加三个成员变量
double r,h,y;
public void compute(double r,double h)
这两 个参数直接使用成员变量.
void 改成double