|
|||
Лабораторная работа № 8. Ход работы
22.11.11 Кондратенко Юрия 54 ПО КТ
Лабораторная работа № 8 Тема. Классы. Цель: изучить на примерах особенности создания и использования классов в консольных проектах; приобрести навыки работы в среде Microsoft Visual Studio 2010.
Ход работы
1. Проверить работу программы, реализующей создание и использование класса Monster. using System; namespace ConsoleApplication1 { class Monster { public Monster() { this.health = 100; this.ammo = 100; this.name = "Noname"; } public Monster(string name) : this() { this.name = name; } public Monster(int health, int ammo, string name) { this.health = health; this.ammo = ammo; this.name = name; } public int Health { get { return health; } set { if (value > 0) health = value; else health = 0; } } public int Ammo { get { return ammo; } set { if (value > 0) ammo = value; else ammo = 0; } } public string Name { get { return name; } } public void Passport() { Console.WriteLine("Monster {0} \t health = {1} ammo = {2}", name, health, ammo); } string name; int health, ammo; } class Class1 { static void Main() { Monster Masha = new Monster(200, 200, "Masha"); Masha.Passport(); Masha.Health -= 1; Masha.Ammo += 100; Masha.Passport(); Console.ReadLine(); } } }
using System; namespace ConsoleApplication1 { class Kniga { public Kniga (int Avtor, int God) { this.Avtor = Avtor; this.God = God; } public double Gety() { return God; } int Avtor; int God; } class Class1 { static void Main() { Kniga Avtor = new Kniga(2011, 200); Console.WriteLine("Knig"); Console.WriteLine(Avtor.Gety()); Console.WriteLine("Goda"); Kniga God = new Kniga(1990, 2011); Console.WriteLine(God.Gety()); Console.ReadLine (); } } }
|
|||
|