Professional Documents
Culture Documents
Звіт до Лабораторної роботи №1 з дисципліни С#, Соколюка Д,М.
Звіт до Лабораторної роботи №1 з дисципліни С#, Соколюка Д,М.
Соколюка Дениса
З дисципліни С#
Лабораторна робота №1
Лабораторна робота №1
Тема: Створення класів. Аксесори читання та запису
Код програми:
using System;
namespace ConsoleApp1
{
class Program
{
public class Adress
{
private string city;
private string street;
private int number;
public static int count = 0;
public string City
{
get
{
Console.WriteLine("[get city]");
return city;
}
set
{
Console.WriteLine("[set city]");
city = value;
}
}
public string Street
{
get
{
Console.WriteLine("[get street]");
return street;
}
set
{
Console.WriteLine("[set street]");
street = value;
}
}
public int Number
{
get
{
Console.WriteLine("[get number]");
return number;
}
set
{
Console.WriteLine("[set number]");
number = value;
}
}
public Adress(string City1, string Street1, int Number1)
{
Console.WriteLine("");
Console.WriteLine("The constructor with parameters is called:");
City = City1;
Street = Street1;
Number = Number1;
count++;
Console.WriteLine("------------------------------------------------------------");
}
public Adress()
{
Console.WriteLine("");
Console.WriteLine("The default constructor is called:");
city = "Chernivtzi";
street = "Kozubinskiy";
number = 2;
count++;
Console.WriteLine("------------------------------------------------------------");
}
public void Print()
{
Console.WriteLine("");
Console.WriteLine($"City: {city}.");
Console.WriteLine($"Street: {street}.");
Console.WriteLine($"Number:{number}.");
Console.WriteLine("------------------------------------------------------------");
}
~Adress()
{
Console.WriteLine("The deconstructor is called");
}
}
static void Main(string[] args)
{
Adress chnu = new Adress();
Adress park = new Adress("Chernivtzi", "Sadova", 1);
Adress cinema = new Adress("Chernivtzi", "Kobelyanska", 14);
chnu.Print();
park.Print();
cinema.Print();
Adress.Print1();
}
}
}
Результат:
Контрольні запитання
1.Охарактеризуйте концепції (принципи) об’єктно-орієнтовано
програмування.
ООП – поняття програмування, яке розглядає програму як
множену “об‘єктів”.