IMG-LOGO
×

Giáo Trình Học

Khoá học lập trình C# (.NET Core)

Kiến Thức Căn Bản - Khai Báo Biến, Toán Tử, Mệnh Đề Điều Kiện, Lặp

[Video] Giới thiệu về ngôn ngữ lập trình C# & .NET Framework + Khai báo biến trong C# [Video] Hướng dẫn tìm hiểu biến + toán tử trong lập trình C# [Video] Hướng dẫn tìm hiểu mệnh đề điều kiện if - else - switch trong C# [Video] Tìm dãy số nguyên tố - Lập trình C# - Loop trong C# [Video] In dãy số chẵn & lẻ từ mảng số nguyên - Lập trình C# - Loop trong C#




Trang Chủ C Sharp [Assignment] Bài tập ôn luyên tổng quát C# - Lập Trình C# - Lập Trình C Sharp

[Assignment] Bài tập ôn luyên tổng quát C# - Lập Trình C# - Lập Trình C Sharp

by GokiSoft.com - 09:41 01/11/2021 15,521 Lượt Xem

Đề 1: Tạo ứng dụng calculator bằng giao diện (Winform Application) gồm các chức năng sau

- Tạo máy tính gồm các chức năng cơ bản

- Lưu lại toàn bộ lịch sử đã thực hiện các phép tính vào file hoặc CSDL

Đề 2 : Tạo ứng dụng quản lý khách sạn (Dùng console hoặc Winform -> tuỳ chọn)

Note : Form sẽ đc nhiều điểm hơn

Gồm các chức năng

- Thêm/Sửa/Xoá KS

- Thêm sửa xoá khách hàng

- Quản lý đặt phòng

- Tìm kiếm.


Bình luận



Chia sẻ từ lớp học

Do Trung Duc [T2008A]

Ngày viết: 17:29 01/06/2021



using System;
using System.Collections.Generic;
using System.Text;

namespace Assigment
{
    [Serializable]
    class Hotel
        
    {
       public List<Room> RoomList { get; set; }

        public string Name { get; set; }
        public string Address { get; set; }
        public int ID { get; set; }

        public Hotel() {
            RoomList = new List<Room>();
        }



        public void CreateNewRoom()
        {
            Room room = new Room();
            room.Input();
            RoomList.Add(room);
            Console.WriteLine("Da tao phong moi thanh cong");
        }

        public void DeleteRoom()
        {   
            Console.WriteLine("Nhap ten phong can xoa");
            string FindRoomName = Console.ReadLine();

                foreach(Room item in RoomList)
            {
                if (item.Name == FindRoomName)
                {
                    RoomList.Remove(item);
                }
            }
            Room room = new Room();
            room.Input();
            RoomList.Add(room);
            Console.WriteLine("Da tao phong moi thanh cong");
        }

        public void Input()
        {
            Console.WriteLine("Nhap ten khach san: ");
            Name = Console.ReadLine();
            Console.WriteLine("Nhap dia chi khach san: ");
            Address = Console.ReadLine();
            Console.WriteLine("Nhap ID khach san: ");
            ID = Int32.Parse(Console.ReadLine());

        }

        public void Display()
        {
            Console.WriteLine("Ten khach san: {0} , Dia chi: :{1}, ID: {2} ", Name, Address, ID);
            Console.WriteLine("Ban co muon xem danh sach phong khong? An phim 1 neu co, phim 0 neu khong");
            int choose = Int32.Parse(Console.ReadLine());
            if (choose == 1)
            {
                int count = 1;
                foreach (Room item in RoomList)
                {
                    Console.WriteLine("Thong tin phong thu " + count);
                    item.Dispay();
                    count++;
                }
            }
            else
            {
                return;
            }
        }

    }
}


Do Trung Duc [T2008A]

Ngày viết: 17:28 01/06/2021



using System;
using System.Collections.Generic;
using System.IO;

namespace Assigment
{
    class Manager
    {
        static List<Hotel> HotelList = new List<Hotel>();

        static void Main(string[] args)
        {
            
            int choose;
    
            do
            {
                DisplayMenu();
                Console.WriteLine("Nhap lua chon: ");
                choose = Int32.Parse(Console.ReadLine());

                switch (choose)
                {
                    case 1:
                        AddNewHotel();
                        break;

                    case 2:
                        DeleteHotel();
                        break;

                    case 3:
                        CreateNewRoom();
                        break;

                    case 4:
                        DeleteRoom();
                        break;

                    case 5:
                        AddNewBookRoom();
                        break;

                    case 6:
                        DeleteBookRoom();
                        break;

                    case 7:
                        FindEmtyRoom();
                        break;

                    case 8:
                        FindHotelInforMation();
                        break;

                    case 9:
                        SaveAndExit();
                        break;

                    case 0:
                        LoadData();
                        break;
                }   

            } while (choose != 9);

        }

        private static void DeleteRoom()
        {
            Console.WriteLine("Nhap ID khach san ban muon xoa phong");
            int ID = Int32.Parse(Console.ReadLine());
            foreach (Hotel hotel in HotelList)
            {
                if (ID == hotel.ID)
                {
                    hotel.DeleteRoom();
                }
            }
        }

        private static void CreateNewRoom()
        {
           Console.WriteLine("Nhap ID khach san ban tao phong moi");
            int ID = Int32.Parse(Console.ReadLine());
            foreach(Hotel hotel in HotelList)
            {
                if(ID == hotel.ID)
                {
                    hotel.CreateNewRoom();
                }
            }

        }

        private static void LoadData()
        {
            using (Stream stream = File.Open("hotels.dat", FileMode.Open))
            {
                var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
               HotelList = (List<Hotel>)binaryFormatter.Deserialize(stream);
            }
            Console.WriteLine("Doc file thanh cong");
        }

        private static void SaveAndExit()
        {
            string filePath = "hotels.dat";
            using (Stream stream = File.Open(filePath, FileMode.Create))
            {
                var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
           
                binaryFormatter.Serialize(stream, HotelList);
            }
            Console.WriteLine("Luu file thanh cong");
        }

        private static void FindHotelInforMation()
        {
            foreach(Hotel hotel in HotelList)
            {
                Console.WriteLine("Ten Khach san: {0}, ID : {1}", hotel.Name, hotel.ID);
            }
                Console.WriteLine("Nhap ID khach san ban muon tim thong tin theo danh sach tren ");
                int ID = Int32.Parse(Console.ReadLine());
            int count = 0;

            foreach (Hotel hotel in HotelList)
            {
               if(ID == hotel.ID)
                {
                    hotel.Display();
                    count++;
                }
            }
            if (count == 0)
            {
                Console.WriteLine("Khong tim thay khach san nao co ID da nhap: ");
            }

        }

        private static void FindEmtyRoom()
        {
            int count = 0;
            Console.WriteLine("Nhap loai phong phong can tim: An phim 1 neu la phong don, an phim 2 neu la phong doi: ");
            int choose = Int32.Parse(Console.ReadLine());
            string Type;
            if (choose == 1)
            {
                Type = "Single";
            }
            else
            {
                Type = "Double";
            }

            Console.WriteLine("Nhap thoi gian checkin theo cu phap: Nam/thang/ngay Gio:Phut:Giay");
            DateTime CheckInTime = DateTime.Parse(Console.ReadLine());

            Console.WriteLine("Nhap thoi gian checkout theo cu phap: Nam/thang/ngay Gio:Phut:Giay");
            DateTime CheckOutTime = DateTime.Parse(Console.ReadLine());

            foreach(Hotel hotel in HotelList)
            {
                foreach (Room room in hotel.RoomList)
                {
                      if(room.Type == Type)
                    {
                        bool Emty = false;
                        foreach(BookRoom bookroom in room.BookRoomList)
                        {
                            int CompareCheckIn1 = DateTime.Compare(CheckInTime, bookroom.CheckInTime);
                            int CompareCheckIn2 = DateTime.Compare(CheckInTime, bookroom.CheckOutTime);

                            int CompareCheckOut1 = DateTime.Compare(CheckOutTime, bookroom.CheckInTime);
                            int CompareCheckOut2 = DateTime.Compare(CheckOutTime, bookroom.CheckOutTime);

                            if  ((CompareCheckIn1 > 0 && CompareCheckIn2 < 0) || (CompareCheckOut1 > 0 && CompareCheckOut2 < 0))
                            {
                                Emty = true;
                                break;
                            }
                        }
                        if (Emty == false)
                        {
                            Console.Write("Thong tin phong phu hop nhu sau:");
                            Console.WriteLine("Ten khach san {0}, Phong: {1}",hotel.Name, room.Name);
                            count++;
                        }
                    }
                }
            }
            if(count == 0)
            {
                Console.WriteLine("Tat ca cac phong da duoc Book vao khoang thoi gian tren");
            }
        }

        private static void DeleteBookRoom()
        {
            Console.WriteLine("Nhap ID khach san: ");
            int ID = Int32.Parse(Console.ReadLine());

            Console.WriteLine("Nhap chinh xac ten phong muon xoa lich Book: ");
            string RoomName = Console.ReadLine();

            foreach (Hotel hotel in HotelList)
            {
                if (hotel.ID == ID)
                {
                    foreach (Room item in hotel.RoomList)
                    {
                        if (RoomName == item.Name)
                        {
                            item.DeleteBookRoom();
                            break;
                        }
                    }
                }
            }
        }

        private static void AddNewBookRoom()
        {
            Console.WriteLine("Nhap ID khach san: ");
            int ID = Int32.Parse(Console.ReadLine());

            Console.WriteLine("Nhap chinh xac ten phong duoc Book: ");
            string RoomName = Console.ReadLine();

            foreach(Hotel hotel in HotelList)
            {
                if(hotel.ID == ID)
                {
                    foreach(Room item in hotel.RoomList)
                    {
                        if(RoomName == item.Name)
                        {
                            item.AddBookRoom();
                        }
                    }
                }
            }

        }

        private static void AddNewHotel()
        {
            Hotel hotel = new Hotel();
            hotel.Input();
            HotelList.Add(hotel);
            Console.WriteLine("Them moi khach san thanh cong");
        }

        private static void DeleteHotel()
        {
            Console.WriteLine("Nhap ID khach san can xoa");
            int FindHotelID = Int32.Parse(Console.ReadLine());

            foreach (Hotel hotel in HotelList)
            {
                if (hotel.ID == FindHotelID)
                {
                    HotelList.Remove(hotel);
                    break;
                }
            }
            Console.WriteLine("Da xoa thanh cong");
        }


        private static void DisplayMenu()
        {
            Console.WriteLine("0. Update du lieu tu File");
            Console.WriteLine("1. Tao khach san moi");
            Console.WriteLine("2. Xoa khach san");
            Console.WriteLine("3. Tao Phong moi");
            Console.WriteLine("4. Xoa phong");
            Console.WriteLine("5. Them lich Book phong");
            Console.WriteLine("6. Xoa lich Book phong");
            Console.WriteLine("7. Tim kiem phong con trong theo yeu cau");
            Console.WriteLine("8. Tra cuu thong tin khach san");
            Console.WriteLine("9. Thoat chuong trinh, du lieu se duoc luu tu dong...");
        }
    }
}


Trần Văn Lâm [T2008A]

Ngày viết: 20:29 27/05/2021


#Book.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel
{
    class Book
    {
        int CheckIn { get; set; }
        int CheckOut { get; set; }
        public string CMTND { get; set; }
        public string HotelNo { get; set; }
        public string RoomNo { get; set; }

        public Book()
        {

        }
        public Book(int CheckIn, int CheckOut, string CMTND, string HotelNo, string RoomNo)
        {
            this.CheckIn = CheckIn;
            this.CheckOut = CheckOut;
            this.CMTND = CMTND;
            this.HotelNo = HotelNo;
            this.RoomNo = RoomNo;
        }
        public void Input(List<Customer> customerList, List<Hotel> hotelList)
        {
            Console.WriteLine("Nhap CMTND Cua Khach Hang");
            CMTND = Console.ReadLine();
            bool isFind = false;
            for (int i = 0; i < customerList.Count; i++)
            {
                if (customerList[i].CMTND.Equals(CMTND))
                {
                    isFind = true;
                    break;
                }
            }

            if (!isFind)
            {
                Console.WriteLine("Khach Hang Khong Ton Tai! Nhap Moi:");
                Customer customer = new Customer();
                customer.CMTND = CMTND;
                customer.InputWithCMTND();
            }

            DisplayHotelMenu(hotelList);
            Hotel hotel = null;
            while (true)
            {
                HotelNo = Console.ReadLine();
                isFind = false;
                for (int i = 0; i < hotelList.Count; i++)
                {
                    if (hotelList[i].No.Equals(HotelNo))
                    { 
                        isFind = true;
                        hotel = hotelList[i];
                        break;
                    }
                }
                if (!isFind)
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Nhap Lai Ma Khach San!");
                }

            }

            DisplayRoomMenu(hotel);
            while (true)
            {
                RoomNo = Console.ReadLine();
                isFind = false;

                for (int i = 0; i < hotel.roomList.Count; i++)
                {
                    if (hotel.roomList[i].No.Equals(RoomNo))
                    {
                        isFind = true;
                        break;
                    }
                }
                if (!isFind)
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Nhap Lai Ma Phong Khach San!");
                }
            }
            Console.WriteLine("Nhap Ngay Dat Phong:");
            CheckIn = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Nhap Ngay Tra Phong:");
            CheckOut = Convert.ToInt32(Console.ReadLine());
        }
        public void DisplayHotelMenu(List<Hotel> hotelList)
        {
            for (int i = 0; i < hotelList.Count; i++)
            {
                Console.WriteLine("{0}. - {1} - {2}", i+1, hotelList[i].Name, hotelList[i].No);
                
            }
            Console.WriteLine("Nhap Ma Khach San Can Chon:");
        }
        public void DisplayRoomMenu(Hotel hotel)
        {
            for (int i = 0; i < hotel.roomList.Count; i++)
            {
                Console.WriteLine("{0}. - {1} - {2}", i + 1, hotel.roomList[i].Name, hotel.roomList[i].No) ;

            }
            Console.WriteLine("Nhap Ma Phong Can Chon:");
        }
    }
}


#Customer.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel
{
    class Customer
    {
        public string CMTND { get; set; }
        public string Fullname { get; set; }
        public int Age { get; set; }
        public string Gender { get; set; }
        public string Address { get; set; }

        public Customer()
        {

        }
        public Customer(string CMTND, string Fullname, int Age, string Gender, string Address)
        {
            this.CMTND = CMTND;
            this.Fullname = Fullname;
            this.Age = Age;
            this.Gender = Gender;
            this.Address = Address;
        }
        public void Input()
        {
            Console.WriteLine("Nhap CMTND:");
            CMTND = Console.ReadLine();
            InputWithCMTND();
        }
        public void InputWithCMTND()
        {
            Console.WriteLine("Nhap Ho Ten:");
            Fullname = Console.ReadLine();
            Console.WriteLine("Nhap Tuoi:");
            Age = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Nhap Gioi Tinh:");
            Gender = Console.ReadLine();
            Console.WriteLine("Nhap Dia Chi:");
            Address = Console.ReadLine();
        }
        public void Display()
        {
            Console.WriteLine("Thon tin Khach Hang: (Ho Ten : {0}, Tuoi : {1}, CMTND : {2}, Gioi Tinh : {3}, Dia Chi : {4})", Fullname, Age, CMTND, Gender, Address);
        }
    }
}


#Hotel.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel
{
    class Hotel
    {
        public string No { get; set; }
        public string Name { get; set; }
        public string Address { get; set; }
        public string Type { get; set; }
        public List<Room> roomList = new List<Room>();
        public Hotel()
        {

        }
        public Hotel(string No, string Name, string Address, string Type)
        {
            this.No = No;
            this.Name = Name;
            this.Address = Address;
            this.Type = Type;
        }
        public void Input()
        {
            Console.WriteLine("Nhap Ma Khach San:");
            No = Console.ReadLine();
            Console.WriteLine("Nhap Ten Khach San:");
            Name = Console.ReadLine();
            Console.WriteLine("Nhap Dia Chi:");
            Address = Console.ReadLine();
            Console.WriteLine("Nhap Loai Khach San:");
            Type = Console.ReadLine();
            Console.WriteLine("Nhap So Phong Can Them:");
            int N = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < N; i++)
            {
                Room room = new Room();
                room.Input();
                roomList.Add(room);
            }
        }
        public void Display()
        {
            Console.WriteLine("Hotel(Ten Khach San : {0}, Dia Chi : {1}, Loai Khach San : {2})", Name, Address, Type);
            for (int i = 0;i < roomList.Count; i++)
            {
                roomList[i].Display();
            }
        }
        public void DisplayBase()
        {
            Console.WriteLine("Hotel(Ten Khach San : {0}, Dia Chi : {1}, Loai Khach San : {2})", Name, Address, Type);
            
        }
    }
}


#Program.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Customer> customerList = new List<Customer>();
            List<Hotel> hotelList = new List<Hotel>();
            List<Book> bookList = new List<Book>();
            int choose;

            do
            {
                showMenu();
                choose = Convert.ToInt32(Console.ReadLine());

                switch (choose)
                {
                    case 1:
                        Input(hotelList);
                        break;
                    case 2:
                        Display(hotelList);
                        break;
                    case 3:
                        InputBook(hotelList,customerList,bookList);
                        break;
                    case 4:
                        SearchAvailableBook(hotelList, bookList);
                        break;
                    case 5:
                        Statistic(bookList, hotelList);
                        break;
                    case 6:
                        Search(bookList, hotelList);
                        break;
                    case 7:
                        Console.WriteLine("Thoat!!!");
                        break;
                    default :
                        Console.WriteLine("Nhap Lai!!");
                        break;
                }
            } while (choose!=7);
        }

        static void Input(List<Hotel> hotelList)
        {
            Console.WriteLine("Nhap So Khach San Can Them:");
            int N = Convert.ToInt32(Console.ReadLine());
            for(int i = 0; i < N; i++)
            {
                Hotel hotel = new Hotel();
                hotel.Input();

                hotelList.Add(hotel);
            }
        }
        static void Display(List<Hotel> hotelList)
        {
            for (int i = 0; i < hotelList.Count; i++)
            {
                hotelList[i].Display();
            }
        }
        static void InputBook(List<Hotel> hotelList, List<Customer> customerList, List<Book> bookList)
        {
            Book book = new Book();
            book.Input(customerList, hotelList);
            bookList.Add(book);
        }
        static void SearchAvailableBook(List<Hotel> hotelList, List<Book> bookList)
        {
            int checkIn;
            int checkOut;
            Console.WriteLine("Nhap Ngay Dat Phong:");
            checkIn = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Nhap Ngay Tra Phong:");
            checkOut = Convert.ToInt32(Console.ReadLine());

            for (int i = 0; i < hotelList.Count; i++)
            {
                hotelList[i].DisplayBase();
                Console.WriteLine("Danh Sach Phong Trong:");
                List<Room> rooms = new List<Room>();
                for (int j = 0; j < rooms.Count; j++)
                {
                    if (checkA(bookList, hotelList[i].No, rooms[j], checkIn, checkOut))
                    {
                        rooms[j].Display();
                    }
                }
            }
        }
        static bool checkA(List<Book> bookList, Room room, int checkIn, int checkOut, string roomNo, string hotelNo)
        {
            for (int i = 0; i < bookList.Count; i++)
            {
                Book book = bookList[i];
                if (book.HotelNo.Equals(hotelNo) && book.RoomNo.Equals(roomNo) && (book.CheckIn  >= checkIn && book.CheckIn <= checkOut) || (book.CheckIn >= checkIn && book.CheckOut <= checkOut))
                {
                    return false;
                }
            }
            return true;
        }
        static int Calculate(List<Book> bookList, Hotel hotel )
        {
            int total = 0;
            for (int i = 0; i < bookList.Count; i++)
            {
                if (bookList[i].HotelNo.Equals(hotel.No))
                {
                    int price = GetMoney(hotel.roomList, bookList[i].RoomNo);
                    total += price * (bookList[i].CheckOut) - bookList[i].CheckIn;
                }
            }
            return total;
        }
        static int GetMoney(List<Room> roomList, string roomNo)
        {
            for (int i = 0; i < roomList.Count; i++)
            {
                if (roomList[i].No.Equals(roomNo))
                {
                    return roomList[i].Price;
                }
            }
            return 0;
        }
        static void Statistic(List<Book> bookList, List<Hotel> hotelList)
        {
            for (int i = 0; i < hotelList.Count; i++)
            {
                int total = Calculate(bookList, hotelList[i]);
                Console.WriteLine("{0}. {1} - Doanh Thu : {2}", i + 1, hotelList[i].Name, total);
            }
        }
        static void Search(List<Book> bookList, List<Hotel> hotelList)
        {
            Console.WriteLine("Nhap CMTND Can Tim Kiem:");
            string cmtnd = Console.ReadLine();
            for (int i = 0; i < bookList.Count; i++)
            {
                if (bookList[i].Equals(cmtnd))
                {
                    Hotel hotel = GetHotelByNo(hotelList, bookList[i].HotelNo);
                    if (hotel!=null)
                    {
                        hotel.DisplayBase();
                    }
                }
            }
        }
        static Hotel GetHotelByNo(List<Hotel> hotelList, string hotelNo)
        {
            for (int i = 0; i < hotelList.Count; i++)
            {
                if (hotelList[i].No.Equals(hotelNo))
                {
                    return hotelList[i];
                }
            }
            return null;
        }
        static void showMenu()
        {
            Console.WriteLine("1.Nhap Thong Tin Khach San");
            Console.WriteLine("2.Hien Thi Thong Tin Khach San");
            Console.WriteLine("3.Dat Phong");
            Console.WriteLine("4.Tim Phong Con Trong");
            Console.WriteLine("5.Thong Ke Doanh Thu");
            Console.WriteLine("6.Tim Kiem Thong Tin Khach Hang");
            Console.WriteLine("7.Thoat!!!");
            Console.WriteLine("Lua Chon:");
        }
    }
}


#Room.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel
{
    class Room
    {
        public string Name { get; set; }
        public int Price { get; set; }
        public int Floor { get; set; }
        public int PersonalMax { get; set; }
        public string No { get; set; }

        public Room()
        {

        }
        public Room(string Name, int Price, int Floor, int PersonalMax, string No)
        {
            this.Name = Name;
            this.Price = Price;
            this.Floor = Floor;
            this.PersonalMax = PersonalMax;
            this.No = No;
        }
        public void Input()
        {
            Console.WriteLine("Nhap Ten Phong:");
            Name = Console.ReadLine();
            Console.WriteLine("Nhap Gia:");
            Price = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Nhap So Tang:");
            Floor = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Nhap So Nguoi Toi Da:");
            PersonalMax = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Nhap Ma Phong:");
            No = Console.ReadLine();
        }
        public void Display()
        {
            Console.WriteLine("Room (Ten Phong : {0}, Gia Phong : {1}, So Tang : {2}, So Nguoi Toi Da : {3}, Ma Phong : {4} )", Name, Price, Floor, PersonalMax, No);
        }
    }
}


Nguyễn đình quân [T2008A]

Ngày viết: 16:37 24/05/2021



private void button8_Click(object sender, EventArgs e)  
       {  
           textBox1.Text = textBox1.Text + 2;  
       }  
  
       private void button9_Click(object sender, EventArgs e)  
       {  
           textBox1.Text = textBox1.Text + 1;  
       }  
  
       private void button13_Click(object sender, EventArgs e)  
       {  
           textBox1.Text = textBox1.Text + 3;  
       }  
  
       private void button3_Click(object sender, EventArgs e)  
       {  
           textBox1.Text = textBox1.Text + 6;  
       }  
  
       private void button2_Click(object sender, EventArgs e)  
       {  
           textBox1.Text = textBox1.Text + 5;  
       }  
  
       private void button10_Click(object sender, EventArgs e)  
       {  
           textBox1.Text = textBox1.Text + 4;  
       }  
  
       private void button6_Click(object sender, EventArgs e)  
       {  
           textBox1.Text = textBox1.Text + 9;  
       }  
  
       private void button7_Click(object sender, EventArgs e)  
       {  
           textBox1.Text = textBox1.Text + 8;  
       }  
  
       private void button1_Click(object sender, EventArgs e)  
       {  
           textBox1.Text = textBox1.Text + 7;  
       }  
  
       private void button5_Click(object sender, EventArgs e)  
       {  
           textBox1.Text = textBox1.Text + 0;  
       }  
  
       private void button16_Click(object sender, EventArgs e)  
       {  
           textBox1.Text = textBox1.Text + 0 + 0;  
       }  
private void btnPlus_Click(object sender, EventArgs e)  
        {  
            num1 = float.Parse(textBox1.Text);  
            textBox1.Clear();  
            textBox1.Focus();  
            count = 2;  
             
        }  
private void btnminus_Click(object sender, EventArgs e)  
      {  
          if (textBox1.Text != "")  
          {  
              num1 = float.Parse(textBox1.Text);  
              textBox1.Clear();  
              textBox1.Focus();  
              count = 1;  
          }  
      }  
private void btnmultiply_Click(object sender, EventArgs e)  
        {  
            num1 = float.Parse(textBox1.Text);  
            textBox1.Clear();  
            textBox1.Focus();  
            count = 3;  
        }  
private void btndivide_Click(object sender, EventArgs e)  
       {  
           num1 = float.Parse(textBox1.Text);  
           textBox1.Clear();  
           textBox1.Focus();  
           count = 4;  
       }  
private void btnequal_Click(object sender, EventArgs e)  
        {  
            compute(count);  
        }  
        public void compute(int count)  
        {  
            switch (count)  
            {  
                case 1:  
                    ans = num1 - float.Parse(textBox1.Text);  
                    textBox1.Text = ans.ToString();  
                    break;  
                case 2:  
                    ans = num1 + float.Parse(textBox1.Text);  
                    textBox1.Text = ans.ToString();  
                    break;  
                case 3:  
                    ans = num1 * float.Parse(textBox1.Text);  
                    textBox1.Text = ans.ToString();  
                    break;  
                case 4:  
                    ans = num1 / float.Parse(textBox1.Text);  
                    textBox1.Text = ans.ToString();  
                    break;  
                default:  
                    break;  
            }  
        }  
private void btnC_Click(object sender, EventArgs e)  
       {  
           textBox1.Clear();  
           count = 0;   
       }  
private void button15_Click(object sender, EventArgs e)  
       {  
           int c = textBox1.TextLength;  
           int flag = 0;  
           string text = textBox1.Text;  
           for (int i = 0; i < c; i++)  
           {  
               if (text[i].ToString() == ".")  
               {  
                   flag = 1; break;  
               }  
               else  
               {  
                   flag = 0;  
               }  
           }  
           if (flag == 0)  
           {  
               textBox1.Text = textBox1.Text + ".";  
           }  
       }  

public Form1()  
       {  
  
           InitializeComponent();  
  
       }  
       float num1, ans;  
       int count;  


Trần Ngọc Hải [T1907A]

Ngày viết: 13:15 05/06/2020


Program.cs
using HCNinterface;
using System;
using System.Collections.Generic;
using System.Text;

namespace RectangleInterface
{
    class Program : Rectangle
    {
        static  public void Main(String[] args)
        {
            int N;
            Console.WriteLine("Moi nhap vao so hinh chu nhat :");
            N = int.Parse(Console.ReadLine());
            Rectangle[] reclist = new Rectangle[N];

            foreach (Rectangle Rectangle in reclist)
            {
                float cd, cr;
                Console.WriteLine("Chieudai la :");
                cd = float.Parse(Console.ReadLine());
                Console.WriteLine("Chieurong la :");
                cr = float.Parse(Console.ReadLine());

                Rectangle.setDaiRong(cd,
                    cr);


            }

            foreach (Rectangle rectangle in reclist)
            {
                Console.WriteLine("Chieu dai :{0}", rectangle.getChieuDai());
                Console.WriteLine("Chieu rong :{0}", rectangle.getChieuRong());
                Console.WriteLine("Dien tich  :{0}", rectangle.dientichHCN());
            }


            float max = 0;
            int a = 0;

            for (int i = 0; i < N; i++)
            {

                float dientich = reclist[i].dientichHCN();
                if (dientich > max)
                {
                    max = dientich;
                    a++;
                }


            }


            Console.WriteLine("Dien tich max : {0} , có chiều dài : {1} , chiều rộng {2} ", max, reclist[a].getChieuDai(), reclist[a].getChieuRong());


        }


    }
}

HCNinterface.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace HCNinterface
{
    interface HCNInterface
    {
        float dientichHCN();
        float getChieuDai();
        float getChieuRong();
        void setDaiRong(float cd, float cr);
        

    }
}

Rectangle.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace HCNinterface
{
    class Rectangle : HCNInterface
    {
        float chieudai { get; set; }
        float chieurong { get; set; }
        public Rectangle()
        {

        }

        public float dientichHCN()
        {
            return chieudai * chieurong;

        }

        public float getChieuDai()
        {
            return chieudai;
        }

        public float getChieuRong()
        {
            return chieurong;
        }

        public void setDaiRong(float cd, float cr)
        {

            chieudai = cd;

            chieurong = cr;
        }

    }
}

Đề bài : https://gokisoft.com/java-basic-oop-interface-hinh-chu-nhat-trong-java.html

Phân Loại Bài Viết

Tài Liệu Tham Khảo

Ứng Dụng Tiện Ích



Đã sao chép!!!