Әдісті асыра жүктеу
Автор: nazgulya22 • Февраль 4, 2023 • Лабораторная работа • 6,226 Слов (25 Страниц) • 189 Просмотры
Әдісті асыра жүктеу
using System;
class Tortburysh
{
public double a;
public double b;
public Tortburysh(double a, double b)
{ this.a = a; this.b = b; }
public void Shygaru()
{
Console.WriteLine("tortburysh qabyrgalary:"+a+","+b);
}
//bir butin parametrli eseleu adisin asyra jukteu
public Tortburysh eseleu(int k)
{
return new Tortburysh(a * k, b * k); }
//bir naqty parametrli eseleu adisin asyra jukteu
public Tortburysh eseleu(double k)
{
return new Tortburysh(a * k, b * k);
}
//eki butin parametrli eseleu adisin asyra jukteu
public Tortburysh eseleu(int k,int i)
{
return new Tortburysh(a * i, b * k);
}
}
class Program
{
static void Main()
{
Tortburysh ob1 = new Tortburysh(4, 5);
Console.WriteLine("bastapqy tortburysh:");
ob1.Shygaru();
Console.WriteLine("eseleu adisin butin parametrmen shygaru");
Tortburysh ob2 = ob1.eseleu(2);
ob2.Shygaru();
Console.WriteLine("eseleu adisin naqty parametrmen shygaru");
Tortburysh ob3 = ob1.eseleu(2.3);
ob3.Shygaru();
Console.WriteLine("eseleu adisin eki butin parametrmen shygaru");
Tortburysh ob4 = ob1.eseleu(2, 3);
ob4.Shygaru();
Console.ReadKey();
}
}
IComparable
using System;
namespace 9лабка
{
abstract class Goobs : IComparable
{
public string aty;
public int jasy;
public int baga;
public Goobs() { }
public Goobs(string aty,int jasy,int baga)
{
this.aty = aty;
this.baga = baga;
this.jasy = jasy;
}
public int CompareTo(object a)
{
Goobs a1 = (Goobs)a;
if (a1.jasy<jasy)
{
return 1;
}
else if (a1.jasy == jasy)
{
return 0;
}
else return -1;
}
public abstract void tizim();
public bool poisk(int a)
{
if (this.jasy <= a)
{
return true;
}
else return false;
}
}
class Toy : Goobs //(аты, бағасы, өндіруші, материал, ойнайтын балалардың жасы)
{
public Toy(string aty, int jasy, int baga, string ondirushi, string material) : base(aty, jasy, baga)
{
this.ondirushi = ondirushi;
this.material = material;
}
public string ondirushi;
public string material;
public override void tizim()
{
Console.WriteLine("aty: " + this.aty + "\tbagasy: " + this.baga + "\tondirushi: " + this.ondirushi + "\tmaterial: " + this.material + "\tjasy" + this.jasy);
}
}
class Book : Goobs // (аты, авторы, бағасы, басылым, ойнайтын балалардың жасы)
{
public Book(string aty, int jasy, int baga, string avtory, string basylym) : base(aty, jasy, baga)
{
this.avtory = avtory;
this.basylym = basylym;
}
public string avtory;
public string basylym;
public override void tizim()
{
Console.WriteLine("aty: " + this.aty + "\tbagasy: " + this.baga + "\tavtor: " + this.avtory + "\tbasylym: " + this.basylym + "\tjasy" + this.jasy);
}
}
class SportsEquipment : Goobs //(аты, бағасы, өндіруші, ойнайтын балалардың жасы)
{
public string ondirushi;
public SportsEquipment(string aty, int jasy, int baga, string ondirushi) : base(aty, jasy, baga)
{
this.ondirushi = ondirushi;
}
public override void tizim()
{
Console.WriteLine("aty: " + this.aty + "\tbagasy: " + this.baga + "\tondirushi: " +this.ondirushi + "\tjasy" + this.jasy);
}
}
class Program
{
static void Main(string[] args)
{
Goobs[] G =
{
new Toy ("mashina",5,2500,"china","plastic") ,
new Book("robinzon", 18, 3000, "Tom", "america"),
new SportsEquipment("shtanga",10,5000,"china")
};
Console.WriteLine("************");
Array.Sort(G);
for (int i = 0; i < G.Length; i++)
{
G[i].tizim();
}
Console.WriteLine("************");
...