@evgenyt2000

Как сделать так чтоб не появлялась ошибка CS7036?

Добрый вечер!
Получаю ошибку CS7036 и не поучается от неё избавиться
Ругается на класс наследник
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace laba3
{
    public class Vektor
    {
        public readonly double x, y, z;
        public Vektor(double x, double y, double z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        //summa
        public Vektor Add(Vektor V)
        { return new Vektor(this.x + V.x, this.y + V.y, this.z + V.z); }
        //raznost
        public Vektor Razn(Vektor V)
        { return new Vektor(this.x - V.x, this.y - V.y, this.z - V.z); }
        public double Length()
        { return Math.Sqrt(x * x + y * y + z * z); }
        public double Length(Vektor V)
        { return (Math.Sqrt(x * x + y * y + z * z) * Math.Sqrt(x * x + y * y + z * z));}
        //skalarnoe proizvedenie
        public virtual double Skalar(Vektor V)
        { return x * this.x + y * this.y + z * this.z; }
        //umnozenie na skalar a
        public  double Uskalar()
        {
            double a = 1;
            return a * this.x + a * this.y + a * this.z;}
        //sravnenie
        public bool Equals(Vektor V)
        {
            if (!(V is Vektor))
            { return false; }
            return base.Equals(V);
        }
        public override string ToString()
        {
            return $"{x} {y} {z}";
        }
        //класс наследник +переопределение
        class Naslednik : Vektor
        {
            public override double Skalar(Vektor V)
            {
                base.Skalar(V);
                return 2*x * this.x + 2*y * this.y + 2*z * this.z; ;
            }
        }
        public class Demo
        {
            public static void Main()
            {
                
                Vektor A = new Vektor(10, 7, 9);
                Vektor B = new Vektor(3, 5, 7);
                Console.WriteLine("A vektor: x={0},y={1},z={2}", A.x, A.y, A.z);
                Console.WriteLine("B vektor: x={0},y={1},z={2}", B.x, B.y, B.z);
                Console.WriteLine($"Summa : {A.Add(B)}");
                Console.WriteLine($"Raznost: {A.Razn(B)}");
                Console.WriteLine($"The scalar *****: {A.Skalar(B)}");
                Console.WriteLine("Dlina A  :   {0}    ", A.Length());
                Console.WriteLine("Dlina B  :   {0}  ", B.Length());
                Console.WriteLine($"Umnozenie na skalar-Vektor A: {A.Uskalar()}");
                Console.WriteLine($"Umnozenie na skalar-Vektor B: {B.Uskalar()}");
                Console.WriteLine($"Vektor v kvadrate-Vektor A: {A.Length(B)}");
                Console.WriteLine($"Ravni li: {A.Equals(B)}");


                Console.WriteLine("Press Enter...");
                Console.ReadLine(); // Чтобы программа сразу не закрылась
            }
        }
    }
}
  • Вопрос задан
  • 130 просмотров
Решения вопроса 1
@kttotto
пофиг на чем писать
Ну так а зачем Вы засунули класс наследник внутрь класса Vector?
spoiler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace laba3
{
    public class Vektor
    {
        public readonly double x, y, z;
        public Vektor(double x, double y, double z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        //summa
        public Vektor Add(Vektor V)
        { return new Vektor(this.x + V.x, this.y + V.y, this.z + V.z); }
		
        //raznost
        public Vektor Razn(Vektor V)
        { return new Vektor(this.x - V.x, this.y - V.y, this.z - V.z); }
		
        public double Length()
        { return Math.Sqrt(x * x + y * y + z * z); }
		
        public double Length(Vektor V)
        { return (Math.Sqrt(x * x + y * y + z * z) * Math.Sqrt(x * x + y * y + z * z));}
		
        //skalarnoe proizvedenie
        public virtual double Skalar(Vektor V)
        { return x * this.x + y * this.y + z * this.z; }
		
        //umnozenie na skalar a
        public  double Uskalar()
        {
            double a = 1;
            return a * this.x + a * this.y + a * this.z;
		}
        //sravnenie
        public bool Equals(Vektor V)
        {
            if (!(V is Vektor))
            { return false; }
            return base.Equals(V);
        }
		
        public override string ToString()
        {
            return $"{x} {y} {z}";
        }
	}
	
    //класс наследник +переопределение
    class Naslednik : Vektor
    {
        public override double Skalar(Vektor V)
        {
            base.Skalar(V);
            return 2*x * this.x + 2*y * this.y + 2*z * this.z; ;
        }
    }
	
    public class Demo
    {
        public static void Main()
        {
            
            Vektor A = new Vektor(10, 7, 9);
            Vektor B = new Vektor(3, 5, 7);
            Console.WriteLine("A vektor: x={0},y={1},z={2}", A.x, A.y, A.z);
            Console.WriteLine("B vektor: x={0},y={1},z={2}", B.x, B.y, B.z);
            Console.WriteLine($"Summa : {A.Add(B)}");
            Console.WriteLine($"Raznost: {A.Razn(B)}");
            Console.WriteLine($"The scalar *****: {A.Skalar(B)}");
            Console.WriteLine("Dlina A  :   {0}    ", A.Length());
            Console.WriteLine("Dlina B  :   {0}  ", B.Length());
            Console.WriteLine($"Umnozenie na skalar-Vektor A: {A.Uskalar()}");
            Console.WriteLine($"Umnozenie na skalar-Vektor B: {B.Uskalar()}");
            Console.WriteLine($"Vektor v kvadrate-Vektor A: {A.Length(B)}");
            Console.WriteLine($"Ravni li: {A.Equals(B)}");


            Console.WriteLine("Press Enter...");
            Console.ReadLine(); // Чтобы программа сразу не закрылась
        }
    }
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы