Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp67
- {
- class Weigth
- {
- private double funt;
- public double Funt
- {
- get { return funt; }
- set { funt = value; }
- }
- public double Unc
- {
- get { return funt * 16; }
- set { funt = value / 16; }
- }
- public double Gram
- {
- get { return funt * 453.59237; }
- set { funt = value / 453.59237; }
- }
- private Weigth(double w)
- {
- funt = w;
- }
- public static Weigth CreateFromFunt(double funt)
- {
- return new Weigth(funt);
- }
- public static Weigth CreateFromGram(double funt)
- {
- return new Weigth(funt / 453.59237);
- }
- public static Weigth CreateFromUnc(double funt)
- {
- return new Weigth(funt / 16);
- }
- public override string ToString()
- {
- return $"Funt={Funt:f5} Unc={Unc:f5} Gram={Gram:f5}\n";
- }
- public static Weigth operator +(Weigth t1, Weigth t2)
- {
- return new Weigth(t1.Funt + t2.Funt);
- }
- public static Weigth operator -(Weigth t1, Weigth t2)
- {
- return new Weigth(t1.Funt - t2.Funt);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Weigth w1, w2, w3;
- w1 = Weigth.CreateFromFunt(40);
- w2 = Weigth.CreateFromGram(10);
- w3 = Weigth.CreateFromUnc(20);
- Console.WriteLine(w1);
- Console.WriteLine(w2);
- Console.WriteLine(w3);
- Console.WriteLine(w2 - w1);
- Console.WriteLine(w1 + w3);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement