By GokiSoft.com|
19:16 28/10/2021|
C Sharp
[Share Code] Bài tập - Quản lý rạp chiều phim C# - Lập trình C#
Bài tập - Quản lý rạp chiều phim C# - Lập trình C#
#Program.cs
using System;
using System.Collections.Generic;
namespace BT2509
{
delegate void ShowStatus();
class Program
{
static void Main(string[] args)
{
//Khai bao mang du lieu
List<IStatus> statusList = new List<IStatus>();
//Khoi tao doi tuong du lieu
for(int i=0;i<3;i++)
{
TicketCounter counter = new TicketCounter();
counter.Input();
statusList.Add(counter);
}
for (int i = 0; i < 2; i++)
{
Restaurant res = new Restaurant();
res.Input();
statusList.Add(res);
}
for (int i = 0; i < 2; i++)
{
Parking res = new Parking();
res.Input();
statusList.Add(res);
}
for (int i = 0; i < 5; i++)
{
CinemaRoom res = new CinemaRoom();
res.Input();
statusList.Add(res);
}
//C1. Goi toan bo onStatus trong statusList
FollowStatus(statusList);
//C2. Khai bao doi tuong delegate
ShowStatus showStatus = null;
foreach (IStatus status in statusList)
{
showStatus += status.OnStatus;
}
showStatus();
}
static void FollowStatus(List<IStatus> statusList)
{
foreach(IStatus status in statusList)
{
status.OnStatus();
}
}
}
}
#IStatus.cs
using System;
namespace BT2509
{
public interface IStatus
{
void OnStatus();
}
}
#PosObject.cs
using System;
namespace BT2509
{
public class PosObject : IStatus
{
public string Status { get; set; }
public string CurrentTime { get; set; }
public PosObject()
{
}
public void OnStatus()
{
Console.WriteLine("Trang thai: {0}", Status);
}
public void Input()
{
Console.WriteLine("Nhap trang thai: ");
Status = Console.ReadLine();
Console.WriteLine("Thoi diem: ");
CurrentTime = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("Trang thai: {0}, thoi diem: {1}", Status, CurrentTime);
}
}
}
#Parking.cs
using System;
namespace BT2509
{
public class Parking : PosObject
{
public Parking()
{
}
}
}
#Restaurant.cs
using System;
namespace BT2509
{
public class Restaurant : PosObject
{
public Restaurant()
{
}
}
}
#TicketCounter.cs
using System;
namespace BT2509
{
public class TicketCounter : PosObject
{
public TicketCounter()
{
}
}
}
#CinemaRoom.cs
using System;
namespace BT2509
{
public class CinemaRoom : IStatus
{
public int SeatTotal { get; set; }
public int UnavaiableSeatTotal { get; set; }
public string CurrentTime { get; set; }
public CinemaRoom()
{
}
public void Input()
{
Console.WriteLine("Nhap tong so ghe: ");
SeatTotal = int.Parse(Console.ReadLine());
Console.WriteLine("Nhap so ghe da ngoi: ");
UnavaiableSeatTotal = int.Parse(Console.ReadLine());
Console.WriteLine("Thoi diem: ");
CurrentTime = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("So ghe: {0}, so ghe da ngoi: {1}, thoi diem: {2}", SeatTotal, UnavaiableSeatTotal, CurrentTime);
}
public void OnStatus()
{
Console.WriteLine("Trang thai {0}/{1}", UnavaiableSeatTotal, SeatTotal);
}
}
}
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)