Создать конструктор класса и метод для вычисления - C#
Формулировка задачи:
Здравствуйте, составил программу по условию, но только с одним классом, не знаю как сделать конструктор класс, т.е. два класса должно быть насколько я понимаю..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Seize
{
class Program
{
static void Main(string[] args)
{
//Где a-сторона, b-высота, c-объем.
double a1 = 2;
double a2 = 1;
int b1 = 1;
int b2 = 3;
var c1 = 1.0 / 3 * a1 * b1;
var c2 = 1.0 / 3 * a2 * b2;
Console.WriteLine("The side of the first pyramid: " + a1);
Console.WriteLine("The side of the second pyramid: " + a2);
Console.WriteLine("===============================================");
Console.WriteLine("The height of the first pyramid: " + b1);
Console.WriteLine("The height of the second pyramid: " + b2);
Console.WriteLine("===============================================");
Console.WriteLine("The volume of the first pyramid is: " + String.Format("{0:0.00}", c1));
Console.WriteLine("The volume of the second pyramid is :" + c2);
Console.Read();
}
}
}Решение задачи: «Создать конструктор класса и метод для вычисления»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Seize
{
class Seize
{
double a1, a2, b1, b2;
public Seize(double A1, double A2, double B1, double B2)
{
a1 = A1;
a2 = A2;
b1 = B1;
b2 = B2;
}
public double Dist()
{
return (1.0 / 3 * b1 * a1);
return (1.0 / 3 * b2 * a2);
}
}
class Program
{
static void Main(string[] args)
{
//Где a-сторона, b-высота, c-объем.
double a1 = 2;
double a2 = 1;
int b1 = 1;
int b2 = 3;
var c1 = 1.0 / 3 * a1 * b1;
var c2 = 1.0 / 3 * a2 * b2;
Console.WriteLine("The side of the first pyramid: " + a1);
Console.WriteLine("The side of the second pyramid: " + a2);
Console.WriteLine("===============================================");
Console.WriteLine("The height of the first pyramid: " + b1);
Console.WriteLine("The height of the second pyramid: " + b2);
Console.WriteLine("===============================================");
Console.WriteLine("The volume of the first pyramid is: " + String.Format("{0:0.00}", c1));
Console.WriteLine("The volume of the second pyramid is :" + c2);
Console.Read();
}
}
}