By GokiSoft.com| 09:53 07/10/2021|
C Sharp

Chương trình quản lý sách - Develop Book Project - Lập Trình C# - OOP trong C# - C Sharp

Cài đặt lớp Book gồm các thuộc tính:

private String bookName;

private String bookAuthor;

private String producer;

private int yearPublishing;

private float price;

 

Cài đặt 2 constructors, các phương thức set/get cho các thuộc tính của lớp.

Cài đặt 2 phương thức input() và display để nhập và hiển thị các thuộc tính của lớp.

 

Cài đặt lớp AptechBook kế thừa lớp Book và bổ sung thêm vào thuộc tính:

private String language;

private int semester;

 

Cài đặt 2 constructor trong đó sử dụng super để gọi đến constructor của lớp cha.

Cài đặt các phương thức get/set cho các thuộc tính bổ sung

Override các phương thức input() và display().

 

Cài đặt lớp Test trong đó tạo menu và thực hiện theo các chức năng của menu:
1.    Nhập thông tin n cuốn sách của Aptech
2.    Hiển thị thông tin vừa nhập
3.    Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị
4.    Tìm kiếm theo tên sách
5.    Tìm kiếm theo tên tác giả
6. Lưu thông tin sách đã nhập vào file
7. Đọc nội dung từ file và lưu vào mang quản lý sách
8.    Thoát.

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

Nguyễn Tiến Đạt [T2008A]
Nguyễn Tiến Đạt

2021-05-28 09:00:37


#Program.cs


using System;
using System.Collections.Generic;
using Develop_Book_Project.Modals;
using System.IO;

namespace Develop_Book_Project
{
    class Program
    {
        static void Main(string[] args)
        {
            List<AptechBook> bookList = new List<AptechBook>();
            int choose = 0;
            do
            {
                showMenu();
                choose = int.Parse(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        Console.WriteLine("Nhap so luong sach muon them:");
                        int n = int.Parse(Console.ReadLine());
                        for (int i = 0; i < n; i++)
                        {
                            Console.WriteLine("Nhap thong tin cho sach thu " + (i + 1) + ":");
                            AptechBook book = new AptechBook();
                            book.input();
                            bookList.Add(book);
                        }
                        break;
                    case 2:
                        for (int i = 0; i < bookList.Count; i++)
                        {
                            Console.WriteLine("Thong tin quyen sach thu " + (i + 1) + ":");
                            bookList[i].display();
                        }
                        break;
                    case 3:
                        bookList.Sort((o1, o2) =>
                        {
                            return -o1.yearPublishing.CompareTo(o2.yearPublishing);
                        });
                        for (int i = 0; i < bookList.Count; i++)
                        {
                            Console.WriteLine("Thong tin quyen sach thu " + (i + 1) + ":");
                            bookList[i].display();
                        }
                        break;
                    case 4:
                        Console.WriteLine("Nhap ten sach can tim kiem:");
                        string bookName = Console.ReadLine();
                        int check = 0;
                        foreach (AptechBook b in bookList)
                        {
                            if(b.bookName == bookName)
                            {
                                check++;
                                b.display();
                            }
                        }
                        if (check == 0) Console.WriteLine("Khong tim thay!!");
                        break;
                    case 5:
                        Console.WriteLine("Nhap ten tac gia can tim kiem:");
                        string bookAuthor = Console.ReadLine();
                        int check1 = 0;
                        foreach (AptechBook b in bookList)
                        {
                            if (b.bookAuthor == bookAuthor)
                            {
                                check1++;
                                b.display();
                            }
                        }
                        if (check1 == 0) Console.WriteLine("Khong tim thay!!");
                        break;
                    case 6:
                        string filepath1 = "aptechbook.dat";
                        using(Stream stream = File.Open(filepath1, FileMode.Create))
                        {
                            var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                            binaryFormatter.Serialize(stream, bookList);
                        }
                        Console.WriteLine("Luu file thanh cong!!");
                        break;
                    case 7:
                        string filepath = "aptechbook.dat";
                        using (Stream stream = File.Open(filepath, FileMode.Open))
                        {
                            var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                            bookList = (List<AptechBook>)binaryFormatter.Deserialize(stream);
                        }
                        Console.WriteLine("Lay du lieu tu file thanh cong!!");
                        break;
                    case 8:
                        Console.WriteLine("Tam biet!!");
                        break;
                    default:
                        Console.WriteLine("Nhap sai!!");
                        break;
                }
            } while (choose != 8);
        }
        static private void showMenu()
        {
            Console.WriteLine("Lua chon chuong trinh:");
            Console.WriteLine("1.Nhap thong tin N cuon sach cua Aptech");
            Console.WriteLine("2.Hien thi thong tin vua nhap");
            Console.WriteLine("3.Sap xep thong tin giam dan theo nam xuat ban va hien thi");
            Console.WriteLine("4.Tim kiem theo ten sach");
            Console.WriteLine("5.Tim kiem theo ten tac gia");
            Console.WriteLine("6.Luu thong tin da nhap vao file");
            Console.WriteLine("7.Doc noi dung tu file va luu vao mang quan ly sach");
            Console.WriteLine("8.Thoat");
        }
    }
}


#AptechBook.cs


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

namespace Develop_Book_Project.Modals
{
    [Serializable]
    class AptechBook : Book
    {
        public String language { get; set; }
        public int semester { get; set; }
        public AptechBook()
        {

        }
        public AptechBook(String bookName, String bookAuthor, String producer, int yearPublishing, float price, String language, int semester) : base(bookName,bookAuthor,producer,yearPublishing,price) 
        {
            this.language = language;
            this.semester = semester;
        }
        public override void input()
        {
            base.input();
            Console.WriteLine("Ngon ngu:");
            language = Console.ReadLine();
            Console.WriteLine("Hoc ki:");
            semester = int.Parse(Console.ReadLine());
        }
        public override void display()
        {
            Console.WriteLine("Sach: {0}, Tac gia: {1}, NSX: {2}, Nam: {3}, Gia: {4}, Ngon ngu: {5}, Hoc ki: {6}", bookName, bookAuthor, producer, yearPublishing, price,language,semester);
        }
    }
}


#Book.cs


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

namespace Develop_Book_Project.Modals
{
    [Serializable]
    class Book
    {
        public String bookName { get; set; }
        public String bookAuthor { get; set; }
        public String producer { get; set; }
        public int yearPublishing { get; set; }
        public float price { get; set; }
        public Book()
        {

        }
        public Book(String bookName, String bookAuthor, String producer, int yearPublishing, float price)
        {
            this.bookName = bookName;
            this.bookAuthor = bookAuthor;
            this.producer = producer;
            this.yearPublishing = yearPublishing;
            this.price = price;
        }
        public virtual void input()
        {
            Console.WriteLine("Ten sach:");
            bookName = Console.ReadLine();
            Console.WriteLine("Ten tac gia:");
            bookAuthor = Console.ReadLine();
            Console.WriteLine("Nha san xuat:");
            producer = Console.ReadLine();
            Console.WriteLine("Nam san xuat:");
            yearPublishing = int.Parse(Console.ReadLine());
            Console.WriteLine("Gia tien:");
            price = float.Parse(Console.ReadLine());
        }
        public virtual void display()
        {
            Console.WriteLine("Sach: {0}, Tac gia: {1}, NSX: {2}, Nam: {3}, Gia: {4}", bookName, bookAuthor, producer, yearPublishing, price);
        }
    }
}



Hoàng Quang Huy [C1907L]
Hoàng Quang Huy

2020-06-29 07:53:18



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

namespace Project1
{
    class Book
    {
        
        public String BookName{ get; set; }
        public String BookAuthor { get; set; }
        public String Producer { get; set; }
        public int YearPublishing { get; set; }
        public float Price { get; set; }

        public Book()
        {
        }

        public virtual void Input()
        {
            Console.WriteLine("Input Name of the Book: ");
            this.BookName = Console.ReadLine();
            Console.WriteLine("Input Book's Author: ");
            this.BookAuthor = Console.ReadLine();
            Console.WriteLine("Input Producer: ");
            this.Producer = Console.ReadLine();
            Console.WriteLine("Input YearPublishing: ");
            this.YearPublishing = int.Parse(Console.ReadLine());
            Console.WriteLine("Input Price: ");
            this.Price = float.Parse(Console.ReadLine());
        }

        public virtual void Display()
        {
            Console.WriteLine("Book's Name: " + BookName);
            Console.WriteLine("Author: " + BookAuthor);
            Console.WriteLine("Producer: " + Producer);
            Console.WriteLine("YearPublishing: " + YearPublishing);
            Console.WriteLine("Price: " + Price);
        }

        public Book(string BookName, string BookAuthor, string Producer, int YearPublishing, float Price)
        {
            this.BookName = BookName;
            this.BookAuthor = BookAuthor;
            this.Producer = Producer;
            this.YearPublishing = YearPublishing;
            this.Price = Price;
        }
    }

}
-------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;

namespace Project1
{
    class AptechBook : Book
    {
        public String language { get; set; }
        public int semester { get; set; }

        public AptechBook()
        {

        }

        public AptechBook(string BookName, string BookAuthor, string Producer, int YearPublishing, float Price, string language, int semester):base( BookName,  BookAuthor,  Producer,  YearPublishing, Price)
        {
            this.language = language;
            this.semester = semester;
        }

        public override void Display()
        {
            base.Display();
            Console.WriteLine("Language: " + language);
            Console.WriteLine("Semester: " + semester);
        }

        public override void Input()
        {
            base.Input();
            Console.WriteLine("Input Language: ");
            this.language = Console.ReadLine();
            Console.WriteLine("Semester: ");
            this.semester = int.Parse(Console.ReadLine());
        }
    }
}
-------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;

namespace Project1
{
    class Test
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.Unicode;
            List<AptechBook> ListBook = new List<AptechBook>();
            int choose;
            do
            {
                ShowMenu();
                choose = int.Parse(Console.ReadLine());
                switch (choose){
                    case 1:
                        Input(ListBook);
                        break;
                    case 2:
                        Show(ListBook);
                        break;
                    case 3:
                        Sort(ListBook);
                        break;
                    case 4:
                        SearchByName(ListBook);
                        break;
                    case 5:
                        SearchByAuthor(ListBook);
                        break;
                    case 6:
                        break;
                    case 7:
                        break;
                    case 8:
                        System.Environment.Exit(0);
                        break;
                }
            } while (choose != 8) ;
        }

        static void ShowMenu()
        {
            Console.WriteLine("1. Nhập thông tin n cuốn sách của Aptech");
            Console.WriteLine("2. Hiển thị thông tin vừa nhập");
            Console.WriteLine("3. Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị");
            Console.WriteLine("4. Tìm kiếm theo tên sách");
            Console.WriteLine("5. Tìm kiếm theo tên tác giả");
            Console.WriteLine("6. Lưu thông tin sách đã nhập vào file");
            Console.WriteLine("7. Đọc nội dung từ file và lưu vào mang quản lý sách");
            Console.WriteLine("8. Thoát");
            Console.WriteLine("Choose:");
        }

        static void Input(List<AptechBook> list)
        {
            Console.WriteLine("Nhập số sách cần thêm: ");
            int n = int.Parse(Console.ReadLine());
            for(int i= 0; i< n; i++)
            {
                AptechBook book = new AptechBook();
                book.Input();
                list.Add(book);
            }
        }

        static void Show(List<AptechBook> list)
        {
            for (int i = 0; i < list.Count; i++)
            {
               list[i].Display();
            }
        }

        static void Sort(List<AptechBook> list)
        {
            for (int i = 0; i < list.Count-1; i++)
            {
                for (int j = 1; j < list.Count; j++)
                {
                    if(list[i].YearPublishing < list[j].YearPublishing)
                    {
                        AptechBook temp = list[i];
                        list[i] = list[j];
                        list[j] = temp;
                    }
                }
            }

            for (int i = 0; i < list.Count; i++)
            {
                list[i].Display();
            }
        }

        static void SearchByName(List<AptechBook> list)
        {
            Console.WriteLine("Nhập tên sách cần tìm kiếm: ");
            String name = Console.ReadLine();
            int count = 0;
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].BookName.Equals(name))
                {
                    list[i].Display();
                    count++;
                }
            }
            if(count == 0)
            {
                Console.WriteLine("Không tìm thấy sách tên là : " + name);
            }
        }

        static void SearchByAuthor(List<AptechBook> list)
        {
            Console.WriteLine("Nhập tên sách cần tìm kiếm: ");
            String author = Console.ReadLine();
            int count = 0;
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].BookAuthor.Equals(author))
                {
                    list[i].Display();
                    count++;
                }
            }
            if (count == 0)
            {
                Console.WriteLine("Không tìm thấy sách của tác giả : " + author);
            }
        }
    }
}



trung [C1907L]
trung

2020-06-28 15:09:14



using System;

namespace qlsach
{
    public class Book
    {
        public Book()
        {
        }
        public Book(string bookName, string bookAuthor, string producer, int yearPublishing, float price)
        {
            this.BookName = bookName;
            this.BookAuthor = bookAuthor;
            this.Producer = producer;
            this.YearPublishing = yearPublishing;
            this.Price = price;
        }
        public string BookName { get; set; }
        public string BookAuthor { get; set; }
        public string Producer { get; set; }
        public int YearPublishing { get; set; }
        public float Price { get; set; }

        public virtual void Input()
        {
            Console.WriteLine("Input book name");
            BookName = Console.ReadLine();
            Console.WriteLine("Input book author");
            BookAuthor = Console.ReadLine();
            Console.WriteLine("Input producer");
            Producer = Console.ReadLine();
            Console.WriteLine("Input year publishing");
            YearPublishing = int.Parse(Console.ReadLine());
            Console.WriteLine("Input price");
            Price = float.Parse(Console.ReadLine());
        }

        public virtual void Output()
        {
            Console.WriteLine("Bookname : {0}", BookName);
            Console.WriteLine("Bookauthor : {0}", BookAuthor);
            Console.WriteLine("Producer : {0}", Producer);
            Console.WriteLine("Year publishing : {0}", YearPublishing);
            Console.WriteLine("Price: {0}", Price);
        }
    }
}



using System;

namespace qlsach
{
    public class AptechBook : Book
    {
        public AptechBook()
        {
            
        }
        public AptechBook(string bookName, string bookAuthor, string producer, 
            int yearPublishing, float price, string language, int semester) 
            : base(bookName, bookAuthor, producer, yearPublishing, price)
        {
            this.Language = language;
            this.Semester = semester;
        }
        public string Language { get; set; }
        public int Semester { get; set; }

        public override void Input()
        {
            base.Input();
            Console.WriteLine("Input language");
            this.Language = Console.ReadLine();
            Console.WriteLine("Input semester");
            this.Semester = int.Parse(Console.ReadLine());
        }

        public override void Output()
        {
            base.Output();
            Console.WriteLine("Language: {0}",Language);
            Console.WriteLine("Semester: {0}",Price);
        }
    }
}



using System;
using System.Collections.Generic;
namespace qlsach
{
    public class Test
    {
        static void Main(string[] args)
        {
            Test test = new Test();
            int choice = 0;
            do
            {
                test.ShowMenu();
                Console.WriteLine("Input your choice");
                choice = int.Parse(Console.ReadLine());
                switch (choice)
                {
                    case 1:
                        test.Input();
                        break;
                    case 2:
                        test.Output();
                        break;
                    case 3:
                        test.Sort();
                        break;
                    case 4:
                        test.SearchByBookName();
                        break;
                    case 5:
                        test.SearchByAuthor();
                        break;
                    case 6:
                        break;
                    case 7:
                        break;
                    case 8:
                        Console.WriteLine("Bye ...");
                        return;
                    default:
                        Console.WriteLine("Invalid input...");
                        break;
                }
            }
            while (choice != 8);
        }
        public List<Book> ListBook { get; private set; }

        public Test()
        {
            ListBook = new List<Book>();
        }

        public void Input()
        {
            Console.WriteLine("Input number of book");
            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                AptechBook aNewBook = new AptechBook();
                aNewBook.Input();
                ListBook.Add(aNewBook);
            }
        }

        public void Output()
        {
            Console.WriteLine("Book list information:");
            for (int i = 0; i < ListBook.Count; i++)
            {
                ListBook[i].Output();
            }
        }

        public void Sort()
        {
            for (int i = 0; i < ListBook.Count - 1; i++)
            {
                for (int j = i + 1; j < ListBook.Count; j++)
                {
                    if (ListBook[i].YearPublishing < ListBook[j].YearPublishing)
                    {
                        Book temp = ListBook[i];
                        ListBook[i] = ListBook[j];
                        ListBook[j] = temp;
                    }
                }
            }
            this.Output();
        }

        public void SearchByBookName()
        {
            Console.WriteLine("Input book name you want to search:");
            string bookName = Console.ReadLine();
            foreach (Book book in ListBook)
            {
                if (book.BookName.Equals(bookName))
                {
                    Console.WriteLine("Found the book:");
                    book.Output();
                    return;
                }
            }
            Console.WriteLine("Not found");
        }

        public void SearchByAuthor()
        {
            Console.WriteLine("Input author you want to search:");
            string author = Console.ReadLine();
            foreach (Book book in ListBook)
            {
                if (book.BookAuthor.Equals(author))
                {
                    Console.WriteLine("Found the book:");
                    book.Output();
                    return;
                }
            }
            Console.WriteLine("Not found");
        }

        public void ShowMenu()
        {
            Console.WriteLine("1. Nhập thông tin n cuốn sách của Aptech");
            Console.WriteLine("2. Hiển thị thông tin vừa nhập");
            Console.WriteLine("3. Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị");
            Console.WriteLine("4. Tìm kiếm theo tên sách");
            Console.WriteLine("5. Tìm kiếm theo tên tác giả");
            Console.WriteLine("6. Lưu thông tin sách đã nhập vào file");
            Console.WriteLine("7. Đọc nội dung từ file và lưu vào mang quản lý sách");
            Console.WriteLine("8. Thoát.");
        }
    }
}



hoangkhiem [C1907L]
hoangkhiem

2020-06-27 05:59:25



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

namespace Baitap
{
    class Program
    {
        static void Main(string[] args)
        {
            List<AptachBook> Listbook = new List<AptachBook>();
            int choose = 0;
            int n;
            while (choose != 6)
            {
                showmenu();
                choose = int.Parse(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        Console.WriteLine("please enter N = ");
                         n = int.Parse(Console.ReadLine());
                        for(int i = 0; i< Listbook.Count; i++)
                        {
                            Console.WriteLine("book : "+ (i + 1));
                            AptachBook book1 = new AptachBook();
                            book1.input();
                            Listbook.Add(book1);
                        }
                        break;
                    case 2:
                        for (int i = 0; i < Listbook.Count; i++)
                        {
                            Console.WriteLine("book : " + (i + 1));
                            Listbook[i].disalay();
                        }
                        break;
                    case 3:
                        for (int i = 0; i < Listbook.Count; i++)
                        {
                            for (int j = i + 1; j < Listbook.Count; j++)
                            {
                                if (Listbook[i].Price < Listbook[j].Price)
                                {
                                    //cach trao doi gia tri
                                    AptachBook tmp = Listbook[i];
                                    Listbook[i] = Listbook[j];
                                    Listbook[j] = tmp;
                                }
                            }
                        }
                        for (int i = 0; i < Listbook.Count; i++)
                        {
                            Console.WriteLine("book : " + (i + 1));
                            Listbook[i].disalay();
                        }
                        break;
                    case 4:
                        Console.WriteLine("TIM KIEM TEN SACH :");
                        string seach = Console.ReadLine();
                        for (int i = 0; i < Listbook.Count; i++)
                        {
                            if (Listbook[i].BookName .Equals(seach) ){
                                Listbook[i].disalay();
                            }
                        }
                        break;
                    case 5:
                        Console.WriteLine("TIM KIEM TEN TAC GIA :");
                        string seachs = Console.ReadLine();
                        for (int i = 0; i < Listbook.Count; i++)
                        {
                            if (Listbook[i].BookAuthor.Equals(seachs) ){
                                Listbook[i].disalay();
                            }
                        }
                        break;
                    case 6:
                        Console.WriteLine("bye");
                        break;
                    default:
                        Console.WriteLine("Lua chon sai");
                        break;
                }
            }
    }
        public static void showmenu()
        {
            Console.WriteLine("************************");
            Console.WriteLine(" 1. Insert n book");
            Console.WriteLine("2. Display");
            Console.WriteLine("3. Sort");
            Console.WriteLine("4. Search by Name");
            Console.WriteLine("5. Search by Author");
            Console.WriteLine("6. Exit");
            Console.Write("Choose: ");
        }
   }
}



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

namespace Baitap
{
    class AptachBook : book
    {
        public String Language { get; set; }
        public String Semester { get; set; }

        public AptachBook()
        {
        }

        public AptachBook(string bookName, string bookAuthor, string producer, int yearPublishing, float price ,string language, string semester) : base ( bookName,  bookAuthor,  producer,  yearPublishing, price)
        {
            Language = language;
            Semester = semester;
        }
        public override void input()
        {
            base.input();
            Console.WriteLine("please enter language  : ");
            Language = Console.ReadLine();
            Console.WriteLine("Pleasw enter semester : ");
            Semester = Console.ReadLine();
        }
        public  void disalay()
        {
            base.disalay();
            Console.WriteLine(" language  : "+Language);
            Console.WriteLine("semester : "+Semester);
        }
    }
}




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

namespace Baitap
{
    class book

    {
        //   private String bookName;
        public string BookName { get; set; }

        //  private String bookAuthor;
        public string BookAuthor { get; set; }
        // private String producer;
        public string Producer { get; set; }
        // private int yearPublishing;
        public int YearPublishing { get; set; }

        private float _price;
        public float Price
        {
            get
            {
                return _price;
            }

            set
            {
                if (value >= 0)
                {
                    _price = value;
                }
                else
                {
                    Console.WriteLine("Cai dat price sai");
                }
            }
        }

        public book()
        {
        }

        public book(string bookName, string bookAuthor, string producer, int yearPublishing, float price)
        {
            BookName = bookName;
            BookAuthor = bookAuthor;
            Producer = producer;
            YearPublishing = yearPublishing;
            Price = price;
        }
        public virtual void input()
        {
            Console.WriteLine("Please enter a title : ");
            BookName = Console.ReadLine();
            Console.WriteLine("Please enter the author's name : ");
            BookAuthor = Console.ReadLine();
            Console.WriteLine("Please enter the manufacturer  : ");
            Producer = Console.ReadLine();
            Console.WriteLine("Please enter the year of publication  : ");
            YearPublishing = int.Parse(Console.ReadLine());
            Console.WriteLine("Please enter the price : ");
            Price = float.Parse(Console.ReadLine());
        }
        public void disalay() {
            Console.WriteLine("the name of the book is : "+ BookName);
            Console.WriteLine("the author's name is  : "+ BookAuthor);
            Console.WriteLine("manufacturer is : "+ Producer);
            Console.WriteLine("year of publication was :  "+ YearPublishing);
            Console.WriteLine("Price is : "+ Price);
  


        }
    }
}



Nguyễn Hoàng Anh [C1907L]
Nguyễn Hoàng Anh

2020-06-26 16:09:01



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

namespace BookManager
{
    class AptechBook: Book
    {
        private string _language;
        public string Language {
            get {
                return _language;
            }
            set {
                _language = value;
            }
        }
        private int _semester;
        public int Semester {
            get {
                return _semester;
            }
            set {
                if (value >= 0) {
                    _semester = value;
                }
            }
        }

        public  AptechBook  (string bookname, string bookauthor, string producer, int yearpublishing, float price,string language, int semester) : base( bookname,  bookauthor,  producer,  yearpublishing,  price)
        {
            Language = language;
            Semester = semester;
        }

        public AptechBook()
        {
        }

        public override void input()
        {
            base.input();
            Console.WriteLine("Enter language : ");
            Language = Console.ReadLine();
            Console.WriteLine("Enter semester : ");
            Semester = int.Parse(Console.ReadLine());
        }
        public override void display()
        {
            base.display();
            Console.Write(", Language {0} , Semester {1} \n",Language,Semester);
        }
    }
}



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

namespace BookManager
{
    class Book
    {
        

        private string _bookname, _bookauthor, _producer;
        public string BookName{
            get {
                return _bookname;
            }
            set {
                _bookname = value;
            }
        }
        public string BookAuthor
        {
            get
            {
                return _bookauthor;
            }
            set
            {
                _bookauthor = value;
            }
        }
        public string Producer
        {
            get
            {
                return _producer;
            }
            set
            {
                _producer = value;
            }
        }
        private int _yearpublishing;
        public int YearPublishing {
            get {
                return _yearpublishing;
            }
            set {
                if (value >= 0) {
                    _yearpublishing = value;
                }
            }
        }
        private float _price;
        public float Price {
            get {
                return _price;
            }
            set {
                if (value >= 0) {
                    _price = value;
                }
            }
        }

        public  Book(string bookname, string bookauthor, string producer, int yearpublishing, float price)
        {
            _bookname = bookname;
            _bookauthor = bookauthor;
            _producer = producer;
            _yearpublishing = yearpublishing;
            _price = price;
        }
        public Book() { }

        public virtual void input() {
            Console.WriteLine("Enter book name : ");
            this.BookName = Console.ReadLine();
            Console.WriteLine("Enter book author : ");
            this.BookAuthor = Console.ReadLine();
            Console.WriteLine("Enter producer : ");
            this.Producer = Console.ReadLine();
            Console.WriteLine("Enter year publishing : ");
            this.YearPublishing = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter price : ");
            this.Price = float.Parse(Console.ReadLine());
        }
        public virtual void display() {
            Console.Write("Book Name : {0} , Author : {1} , Producer : {2} , Year Publishing : {3} , Price : {4}", BookName,BookAuthor,Producer,YearPublishing,Price);
            
        }
        
        
    }
}



using System;
using System.Collections.Generic;
using System.Net;

namespace BookManager
{
    class Program
    {
        static void Menu() {
            Console.WriteLine("1. Nhập thông tin n cuốn sách của Aptech");
            Console.WriteLine("2. Hiển thị thông tin vừa nhập");
            Console.WriteLine("3. Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị");
            Console.WriteLine("4. Tìm kiếm theo tên sách");
            Console.WriteLine("5. Tìm kiếm theo tên tác giả");
            Console.WriteLine("6. Lưu thông tin sách đã nhập vào file");
            Console.WriteLine("7. Đọc nội dung từ file và lưu vào mang quản lý sách");
            Console.WriteLine("8. Thoát.");
        }
        static void Input(List<AptechBook> aptechBooks) {
            Console.WriteLine("Enter number of book : ");
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++) {
                Console.WriteLine("Enter book {0} information", (i + 1));
                AptechBook aptechBook = new AptechBook();
                aptechBook.input();
                aptechBooks.Add(aptechBook);
            }
        }
        static void Show(List<AptechBook> aptechBooks) {
            int length = aptechBooks.Count;
            for (int i = 0; i < length; i++) {
                aptechBooks[i].display();
            }

        }
        static void Sort(List<AptechBook> aptechBooks) {
            int length = aptechBooks.Count;
            for (int i = 0; i < length; i++) {
                for (int j = i + 1; j < length; j++) {
                    if (aptechBooks[i].YearPublishing > aptechBooks[j].YearPublishing) {
                        AptechBook temp = aptechBooks[i];
                        aptechBooks[i] = aptechBooks[j];
                        aptechBooks[j] = temp;
                    }
                }
            }
            for (int i = 0; i < length; i++) {
                aptechBooks[i].display();
            }
        }
        static void FindByBookName(List<AptechBook> aptechBooks)
        {
            Console.WriteLine("Enter book name : ");
            int length = aptechBooks.Count;
            string BookName = Console.ReadLine();
            for (int i = 0; i < length; i++)
            {
                if (BookName == aptechBooks[i].BookName) {
                    aptechBooks[i].display();
                }
            }
        }
        static void FindByAuthor(List<AptechBook> aptechBooks)
        {
            Console.WriteLine("Enter author name : ");
            int length = aptechBooks.Count;
            string Author = Console.ReadLine();
            for (int i = 0; i < length; i++)
            {
                if (Author == aptechBooks[i].BookAuthor)
                {
                    aptechBooks[i].display();
                }
            }
        }
        static void Main(string[] args)
        {
            List<AptechBook> aptechBooks = new List<AptechBook>();
            while (true) {
                Menu();
                int choice = int.Parse(Console.ReadLine());
                switch (choice) {
                    case 1:
                        Input(aptechBooks);
                        break;
                    case 2:
                        Show( aptechBooks);
                        break;
                    case 3:
                        Sort( aptechBooks);
                        break;
                    case 4:
                        FindByBookName(aptechBooks);
                        break;
                    case 5:
                        FindByAuthor(aptechBooks);
                        break;
                    case 6:
                        break;
                    case 7:
                        break;
                    case 8:
                        return;
                }
            }
        }
    }
}



Ngô Quang Huy [C1907L]
Ngô Quang Huy

2020-06-26 14:03:50



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

namespace BT
{
    class Test
    {
        static void Main(string[] args)
        {
            List<AptechBook> list = new List<AptechBook>();
            while (true)
            {
                showMenu();
                int choose = int.Parse(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        Console.Write("Insert n = ");
                        int n = int.Parse(Console.ReadLine());
                        for (int i=0; i < n; i++)
                        {
                            Console.WriteLine("\nBook "+(i+1));
                            AptechBook apt = new AptechBook();
                            apt.input();
                            list.Add(apt);
                        }
                        break;
                    case 2:
                        for (int i = 0; i < list.Count; i++)
                        {
                            list[i].display();
                        }
                        break;
                    case 3:
                        for (int i = 0; i < list.Count-1; i++)
                        {
                            for (int j = i + 1; j < list.Count; j++)
                            {
                                if (list[i].YearPublishing < list[j].YearPublishing)
                                {
                                    AptechBook tmp = list[i];
                                    list[i] = list[j];
                                    list[j] = tmp;
                                }
                            }
                        }
                        Console.WriteLine("sorted!!");
                        break;
                    case 4:
                        Console.WriteLine("Insert Book: ");
                        string search = Console.ReadLine();

                        for (int i = 0; i < list.Count; i++)
                        {
                            if (list[i].Equals(search))
                            {
                                list[i].display();
                                break;
                            }
                        }
                        break;
                    case 5:
                        Console.WriteLine("Insert Author: ");
                        string searchAuthor = Console.ReadLine();

                        for (int i = 0; i < list.Count; i++)
                        {
                            if (list[i].Equals(searchAuthor))
                            {
                                list[i].display();
                                break;
                            }
                        }
                        break;
                    case 6:
                        break;
                    case 7:
                        break;
                    case 8:
                        Environment.Exit(0);
                        break;
                }

            }
        }

        static void showMenu()
        {
            Console.WriteLine("\n1. Insert n book");
            Console.WriteLine("2. Display");
            Console.WriteLine("3. Sort");
            Console.WriteLine("4. Search by Name");
            Console.WriteLine("5. Search by Author");
            Console.WriteLine("6. Save");
            Console.WriteLine("7. Read");
            Console.WriteLine("8. Exit");
            Console.Write("Choose: ");
        }
    }
}



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

namespace BT
{
    class Book
    {

        public string Bookname { get; set; }

        public string BookAuthor { get; set; }

        public string Producer { get; set; }

        public int YearPublishing { get; set; }

        private float price;
        public float Price {
            get{
                return price;
            }
            set{
                if (value > 0)
                {
                    price = value;
                }
                else
                {
                    Console.WriteLine("Invalid Input");
                }
            }
        }

        public Book()
        {
        }

        public Book(string bookName, string bookAuthor, string producer, int yearPublishing, float price)
        {
            this.Bookname = bookName;
            this.BookAuthor = bookAuthor;
            this.Producer = producer;
            this.YearPublishing = yearPublishing;
            this.price = price;
        }

        public virtual void input()
        {
            Console.Write("Insert bookName: ");
            Bookname = Console.ReadLine();
            Console.Write("Insert bookAuthor: ");
            BookAuthor = Console.ReadLine();
            Console.Write("Insert producer: ");
            Producer = Console.ReadLine();
            Console.Write("Insert yearPublishing: ");
            YearPublishing = int.Parse(Console.ReadLine());
            Console.Write("Insert price: ");
            price = float.Parse(Console.ReadLine());
        }
        
        public virtual void display()
        {
            Console.WriteLine("bookName=" + Bookname + "; bookAuthor=" + BookAuthor + "; producer=" + Producer + "; yearPublishing=" + YearPublishing + "; price=" + price);
        }
    }
}



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

namespace BT
{
    class AptechBook : Book
    {
        public string Language { get; set; }
        public int Semester { get; set; }

        public override void input()
        {
            base.input();
            Console.Write("Insert language: ");
            Language = Console.ReadLine();
            Console.Write("Insert semester: ");
            Semester = int.Parse(Console.ReadLine());
        }

        public override void display()
        {
            base.display();
            Console.WriteLine("language=" + Language + "; semester=" + Semester);

        }

        public AptechBook()
        {

        }

        public AptechBook(string bookName, string bookAuthor, string producer, int yearPublishing, float price, string language, int semester) : base(bookName, bookAuthor, producer, yearPublishing, price)
        {
            this.Language = language;
            this.Semester = semester;
        }
    }
}



thienphu [T1907A]
thienphu

2020-05-25 00:02:24


#AptechBook.cs


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

namespace Lesson5
{
    class AptechBook : Book
    {
        private string language;

        private int semester;

        public string Language { get; set; }
        public int Semester { get; set; }
        
        public AptechBook() { }
       public AptechBook(string bookname, string bookAuthor, string producer, int yearPublishing, float price,
           string language, int semester) : base(bookname, bookAuthor, producer, yearPublishing, price)
        {
            Language = language;
            Semester = semester;
        }
        public override void input()
        {
            base.input();
            Console.WriteLine("input Language");
            Language = Console.ReadLine();
            Console.WriteLine("input Semester");
            Semester = Convert.ToInt32(Console.ReadLine());
        }
        public override void display()
        {
            base.display();
            Console.Write("Language ={0}, Semester= {1}\n",Language,Semester);
        }
        public string getString()
        {
            return "bookName =" + BookName + ", bookAuthor =" + BookAuthor + ", producer =" + Producer + ", yearPublishing ="
                + YearPublishing + ",price =" + Price + ",Language ="+Language+ ",Semester="+Semester+"\n";

        }

    }
}


#Book.cs


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

namespace Lesson5
{
    class Book
    {
        public string bookName;

        public string bookAuthor;

        public string producer;

        public int yearPublishing;

        public float price;

        public string BookName { get; set; }
        public string BookAuthor { get; set; }
        public string Producer { get; set; }
        public int YearPublishing { get; set; }
        public float Price { get; set; }

        public Book() { }
        public Book(string bookname,string bookAuthor,string producer,int yearPublishing, float price)
        {
            BookName = bookname;
            BookAuthor = bookAuthor;
            Producer = producer;
            YearPublishing = yearPublishing;
            Price = price;
        }
        public virtual void display()
        {
            Console.Write("\nbookName = {0}, bookAuthor = {1}, producer = {2}, yearPublishing = {3},price = {4}",
                BookName,BookAuthor,Producer,YearPublishing,Price);
        }
        public virtual void input()
        {
            Console.WriteLine("Input bookName");
            BookName = Console.ReadLine();
            Console.WriteLine("Input BookAuthor");
            BookAuthor = Console.ReadLine();
            Console.WriteLine("Input producer");
            Producer = Console.ReadLine();
            Console.WriteLine("Input YearPublishing");
            YearPublishing = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Input Price");
            Price = float.Parse(Console.ReadLine());
        }
      

    }
}


#Manage.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Lesson5
{
    class Manage
    {

        //ham input aptechbook
        public static void input(List<AptechBook> list)
        {
            Console.WriteLine("Nhap N thong tin cuon sach AptechBook");
            int n = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                AptechBook book = new AptechBook();
                book.input();
                list.Add(book);
            }
        }

        //ham hien thi thong tin vua nhap
        public static void display(List<AptechBook> list)
        {
            Console.WriteLine("Danh sach thong tin sach");
            foreach (var item in list)
            {
                item.display();
            }
        }

        //ham
        public static void sortYear(List<AptechBook> list)
        {
            Console.WriteLine("Sap xep theo nam san xuat giam dan");
            list.Sort(new SortByYear());
            display(list);
        }
        //tim kiem theo ten sach
        public static void searchNameBook(List<AptechBook> list)
        {
            Console.WriteLine("nhap name book can tim");
            string name = Console.ReadLine();
            AptechBook book = null;
            foreach (var item in list)
            {
                if (item.BookName.Equals(name))
                {
                    book = item;
                    break;
                }
            }
            if(book != null)
            {
                book.display();
                return;
            }
            Console.WriteLine("namebook = {0} khong ton tai",name);
        }
        //tim sach theo ten tac gia
        public static void searchAuthorBook(List<AptechBook> list)
        {
            Console.WriteLine("nhap name book can tim");
            string name = Console.ReadLine();
            AptechBook book = null;
            foreach (var item in list)
            {
                if (item.BookAuthor.Equals(name))
                {
                    book = item;
                    break;
                }
            }
            if (book != null)
            {
                book.display();
                return;
            }
            Console.WriteLine("AuthorBook = {0} khong ton tai", name);
        }

        //
        public static void writeFile(List<AptechBook> list)
        {
            FileStream fs = new FileStream("demo.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
            //string str = "smileahjhj do thien phu";

            //chuyen thanh mang byte theo ma utf8
            foreach (var item in list)
            {
                byte[] b = Encoding.UTF8.GetBytes(item.getString());
                fs.Write(b, 0, b.Length);
            }
            

            //ghi xuong file
           
            Console.WriteLine("write finish");
            //dong stream
            fs.Close();

        }
        //readFile

        public static void readFile()

        {
            string data = string.Empty;
            using(StreamReader str = new StreamReader("demo.txt"))
            {
                while((data = str.ReadLine()) != null)
                {
                    Console.WriteLine(data);
                }
            }
            Console.WriteLine("read file close");
        }

    }
}



#Program.cs


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

namespace Lesson5
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            List<AptechBook> listbook = new List<AptechBook>();
            int choose;


            do
            {
                showmenu();
                choose = Convert.ToInt32(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        Manage.input(listbook);
                        break;
                    case 2:
                        Manage.display(listbook);
                        break;
                    case 3:
                        Manage.sortYear(listbook);
                        break;
                    case 4:
                        Manage.searchNameBook(listbook);
                        break;
                    case 5:
                        Manage.searchAuthorBook(listbook);
                        break;
                    case 6:
                        Manage.writeFile(listbook);
                        break;
                    case 7:
                        Manage.readFile();
                        break;
                    case 8:
                        Console.WriteLine("Exit success");
                        break;
                    default:
                        Console.WriteLine("Chon tu 1 -8 , chon lai di");
                        break;

                }

            } while (choose != 8);
        }
        public static void showmenu()
        {
            Console.WriteLine("1.    Nhập thông tin n cuốn sách của Aptech");
            Console.WriteLine("2.    Hiển thị thông tin vừa nhập");
            Console.WriteLine("3.    Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị");
            Console.WriteLine("4.    Tìm kiếm theo tên sách");
            Console.WriteLine("5.    Tìm kiếm theo tên tác giả");
            Console.WriteLine("6. Lưu thông tin sách đã nhập vào file");
            Console.WriteLine("7. Đọc nội dung từ file và lưu vào mang quản lý sách");
            Console.WriteLine("8. Thoat");
            Console.WriteLine("Choose:");


        }
    }
}


#SortByYear.cs


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

namespace Lesson5
{
  
        class SortByYear : IComparer<AptechBook> // ke thua interface Icomparer
    {
        
            public int Compare(AptechBook x, AptechBook y)
            {
            return x.YearPublishing > y.YearPublishing ? -1 : 1;
            }
        

    
    }
}



Trần Mạnh Dũng [T1907A]
Trần Mạnh Dũng

2020-05-23 12:10:01


#Program.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

namespace Quanlisach
{
    class Program
    {
        static void Main(string[] args)
        {
            Test();
        }

        static public void Test()
        {
            List<AptechBook> listbook = new List<AptechBook>();
            int choose;

            do
            {
                Menu();
                Console.Write("Choose: ");
                choose = int.Parse(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        Console.Write("Enter n: ");
                        int n = int.Parse(Console.ReadLine());
                        for (int i = 1; i <= n; i++)
                        {
                            AptechBook aptechBook = new AptechBook();
                            Console.WriteLine("===============");
                            Console.WriteLine("Enter Book {0}: ", i);
                            aptechBook.input();
                            listbook.Add(aptechBook);
                        }
                        break;
                    case 2:
                        Console.WriteLine("Show Infor:");
                        showInfor(listbook);
                        break;
                    case 3:
                        Sort(listbook);
                        showInfor(listbook);
                        break;
                    case 4:
                        Console.Write("Enter bookName: ");
                        string search = Console.ReadLine();
                        AptechBook book = findBybookName(search, listbook);
                        Console.WriteLine("=================");
                        book.output();
                        break;
                    case 5:
                        Console.Write("Enter bookAuthor: ");
                        search = Console.ReadLine();
                        AptechBook author = findBybookAuthor(search, listbook);
                        Console.WriteLine("=================");
                        author.output();
                        break;
                    case 6:
                        FileStream fs = new FileStream("E:/C#/quanlisach.txt", FileMode.Create);
                        StreamWriter sWriter = new StreamWriter(fs, Encoding.UTF8);
                        foreach (var item in listbook)
                        {
                            sWriter.WriteLine(item.toString());
                        }
                        sWriter.Flush();
                        fs.Close();
                        break;
                    case 7:
                        string[] lines = File.ReadAllLines(@"E:/C#/quanlisach.txt");
                        foreach (string s in lines)
                        {
                            Console.WriteLine(s);
                        }
                        Console.ReadLine();
                        break;
                    case 8:
                        Console.WriteLine("Exit");
                        break;
                    default:
                        Console.WriteLine("ERROR");
                        break;

                }
            } while (choose != 8);
        }
        static public void Menu()
        {
            Console.WriteLine("==============================MENU===============================");
            Console.WriteLine("1. Enter information n book of Aptech");
            Console.WriteLine("2. Displays the information");
            Console.WriteLine("3. Sort information descending by publication year");
            Console.WriteLine("4. Search by bookName");
            Console.WriteLine("5. Search by bookAuthor");
            Console.WriteLine("6. Save file");
            Console.WriteLine("7. Read contents from file and save into book management array");
            Console.WriteLine("8. Exit");
            Console.WriteLine("================================================================");
        }
        static public void showInfor(List<AptechBook> listbook)
        {
            int showinfor = 0;
            foreach (var item in listbook)
            {
                ++showinfor;
                Console.WriteLine("=================");
                Console.WriteLine("Information book {0}: ", showinfor);
                item.output();
            }
        }
        static public void Sort(List<AptechBook> listbook)
        {
            listbook.Sort((x, y) => x.yearPublishing.CompareTo(y.yearPublishing));
        }
        static AptechBook findBybookName(String search, List<AptechBook> listbook)
        {
            AptechBook aptechBook = new AptechBook();
            foreach (var item in listbook)
            {
                if (item.bookName.Equals(search))
                {
                    aptechBook = item;
                    break;
                }
            }
            return aptechBook;
        }
        static AptechBook findBybookAuthor(String search, List<AptechBook> listbook)
        {
            AptechBook aptechBook = new AptechBook();
            foreach (var item in listbook)
            {
                if (item.bookAuthor.Equals(search))
                {
                    aptechBook = item;
                    break;
                }
            }
            return aptechBook;
        }
    }
}


#AptechBook.cs


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

namespace Quanlisach
{
    class AptechBook : Book
    {
        private string _language;
        private int _semester;

        public string language { get; set; }
        public int semester { get; set; }

        public AptechBook()
        {

        }
        public AptechBook(String laguage, int semester)
        {
            this.language = language;
            this.semester = semester;
        }
        public override void input()
        {
            base.input();
            Console.Write("Enter language: ");
            language = Console.ReadLine();
            Console.Write("Enter semester: ");
            semester = int.Parse(Console.ReadLine());
        }
        public override void output()
        {
            base.output();
            Console.WriteLine("Language: {0} \nSemester: {1}", language, semester);
        }
        public string toString()
        {
            return "bookName: " + bookName + "\nbookAuthor: " + bookAuthor + "\nProducer: " + producer + "\nYearPublishing: " + yearPublishing + "\nPrice: " + price;
        }

    }
}


#Book.cs


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

namespace Quanlisach
{
    class Book
    {
        private string _bookName;
        private string _bookAuthor;
        private string _producer;
        private int _yearPublishing;
        private float _price;

        public string bookName { get; set; }
        public string bookAuthor { get; set; }
        public string producer { get; set; }
        public int yearPublishing { get; set; }
        public float price { get; set; }

        public Book()
        {

        }
        public Book(String bookName, String bookAuthor, String producer, int yearPublishing, float price)
        {
            this.bookName = bookName;
            this.bookAuthor = bookAuthor;
            this.producer = producer;
            this.yearPublishing = yearPublishing;
            this.price = price;
        }
        public virtual void input()
        {
            Console.Write("Enter bookName: ");
            bookName = Console.ReadLine();
            Console.Write("Enter bookAuthor: ");
            bookAuthor = Console.ReadLine();
            Console.Write("Enter producer: ");
            producer = Console.ReadLine();
            Console.Write("Enter yearPublishing: ");
            yearPublishing = int.Parse(Console.ReadLine());
            Console.Write("Enter price: ");
            price = float.Parse(Console.ReadLine());
        }
        public virtual void output()
        {
            Console.WriteLine("bookName: {0} \nbookAuthor: {1} \nProducer: {2} \nYearPublishing: {3} \nPrice: {4}", bookName, bookAuthor, producer, yearPublishing, price); ;
        }



    }
}



Trương Công Vinh [T1907A]
Trương Công Vinh

2020-05-22 10:15:08



using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.IO;
namespace Book
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            Console.WriteLine("Hello World!");

            List<AptechBook> bookList = new List<AptechBook>();
            int c;
            do
            {
                menu();
                c = int.Parse(Console.ReadLine());
                switch (c)
                {
                    case 1:
                        Console.WriteLine("Nhap n : ");
                        int n = int.Parse(Console.ReadLine());
                        for (int i = 0; i < n; i++)
                        {
                            AptechBook aptechBook = new AptechBook();
                            aptechBook.input();
                            bookList.Add(aptechBook);
                        }

                        break;
                    case 2:
                        display(bookList);
                        break;
                    case 3:
                        sort(bookList);
                        display(bookList);
                        break;
                    case 4:
                        Console.WriteLine("nhap bookName de tim kiem :");
                        string search = Console.ReadLine();
                        AptechBook book = findBybookName(search, bookList);
                        book.display();
                        break;
                    case 5:
                        Console.WriteLine("nhap Author Name de tim kiem :");
                        search = Console.ReadLine();
                        AptechBook book1 = findBybookName(search, bookList);
                        book1.display();
                        break;
                    case 6:
                        FileStream fs = new FileStream("d:/C#/FileC#/test.txt", FileMode.Create);//Tạo file mới tên là test.txt            
                        StreamWriter sWriter = new StreamWriter(fs, Encoding.UTF8);//fs là 1 FileStream 
                        foreach (var item in bookList)
                        {
                            sWriter.WriteLine(item.toString());
                            
                        }
                        // Ghi và đóng file
                        sWriter.Flush();
                        fs.Close();
                        break;
                    case 7:

                        break;
                    case 8:
                        Console.WriteLine("End Program!!");
                        break;

                }

            } while (c != 8);

        }
        static void menu()
        {
            Console.WriteLine("********************************************");
            Console.WriteLine("1.    Nhập thông tin n cuốn sách của Aptech");
            Console.WriteLine("2.    Hiển thị thông tin vừa nhập");
            Console.WriteLine("3.    Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị");
            Console.WriteLine("4.    Tìm kiếm theo tên sách");
            Console.WriteLine("5.    Tìm kiếm theo tên tác giả");
            Console.WriteLine("6. Lưu thông tin sách đã nhập vào file");
            Console.WriteLine("7. Đọc nội dung từ file và lưu vào mang quản lý sách");
            Console.WriteLine("8.    Thoát.");
            Console.WriteLine("Chon : ");
        }
        static void sort(List<AptechBook> bookList)
        {
            bookList.Sort((x, y) => x.yearPublishing.CompareTo(y.yearPublishing));
        }
        static void display(List<AptechBook> bookList)
        {
            Console.WriteLine("********************************************");
            int stt = 0;
            foreach (AptechBook item in bookList)
            {
                ++stt;
                Console.WriteLine("thong tin cuon sach thu {0} : ", stt);
                item.display();
            }
        }
        static AptechBook findBybookName(string search, List<AptechBook> bookList)
        {
            AptechBook aptechBook = new AptechBook();
            foreach (var item in bookList)
            {
                if (item.bookName.Equals(search))
                {
                    aptechBook = item;
                    break;
                }
            }
            return aptechBook;
        }
        static AptechBook findByAuthorName(string search, List<AptechBook> bookList)
        {
            AptechBook aptechBook = new AptechBook();
            foreach (var item in bookList)
            {
                if (item.bookAuthor.Equals(search))
                {
                    aptechBook = item;
                    break;
                }
            }
            return aptechBook;
        }
    }
}



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

namespace Book
{
    class Book
    {
        private String _bookName { get; set; }

        private String _bookAuthor { get; set; }

        private String _producer { get; set; }

        private int _yearPublishing { get; set; }

        private float _price { get; set; }
        public int yearPublishing {
            get
            {
                return _yearPublishing;
            }
            set
            {
                _yearPublishing = value;
            }
            }
        public String bookName { get
            {
                return _bookName;
            }
            set
            {
                _bookName = value;
            }
        }
        public String bookAuthor {
            get
            {
                return _bookAuthor;
            }
            set {
                _bookAuthor = value;
            } }
        

        public String producer {
            get
            {
                return _producer;
            }
            set {
                _producer = value;
            }
            }

       

        public float price {
            get
            {
                return _price;
            }
            set {
                _price = value;
            } }
        public Book()
        {

        }
        public Book(String bookName, String bookAuthor, String producer, int yearPublishing, float price)
        {
            this._bookAuthor = bookAuthor;
            this._bookName = bookName;
            this._price = price;
            this._producer = producer;
            this._yearPublishing = yearPublishing;
        }
        public virtual void input()
        {
            Console.WriteLine("Enter Name of Book : ");
            _bookName = Console.ReadLine();
            Console.WriteLine("Enter Author of book : ");
            _bookAuthor = Console.ReadLine();
            Console.WriteLine("Enter Producer : ");
            _producer = Console.ReadLine();
            Console.WriteLine("Enter Year Publishing : ");
            _yearPublishing = int.Parse( Console.ReadLine());
            Console.WriteLine("Enter Price : ");
            _price = float.Parse(Console.ReadLine());
        }
        public virtual void display()
        {
            Console.WriteLine(" Name of Book : "+_bookName);
            Console.WriteLine("Author of book : "+_bookAuthor);
            Console.WriteLine("Producer : "+_producer);
            Console.WriteLine("Year Publishing : "+_yearPublishing);
            Console.WriteLine("Price : "+_price);
        }
    }
}



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

namespace Book
{
    class AptechBook : Book
    {
        private String language { get; set; }

        private int semester { get; set; }
        public AptechBook():base()
        {

        }
        public AptechBook(String bookName, String bookAuthor, String producer, int yearPublishing, float price,String language , int semester ):base()
        {
            this.language = language;
            this.semester = semester;
           
        }
        public override void input()
        {
            base.input();
            Console.WriteLine("Enter Language : ");
            language = Console.ReadLine();
            Console.WriteLine("Enter semester : ");
            semester = int.Parse(Console.ReadLine());
        }
        public override void display()
        {
            base.display();
            Console.WriteLine(" Language : "+language);
            Console.WriteLine(" semester : "+semester);

        }
        public string toString()
        {
            return "aptechBook{bookName : "+bookName + ", bookAuthor : "+bookAuthor+", Producer : "+producer+ ", yearPublishing : " + yearPublishing+", Price : "+price+", Language : "+language+", semester : "+semester+"}";
        }


    }
}



Lê Minh Bắc [T1907A]
Lê Minh Bắc

2020-05-22 09:55:06



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

namespace Lession5
{
    class Test
    {
        
        public static void Main(String[] agrs)
        {
            Console.OutputEncoding = Encoding.Unicode;
            Console.InputEncoding = Encoding.Unicode;
            int chosse,N;
            List<AptechBook> listBook = new List<AptechBook>();
            
            do
            {
                showMenu();
                Console.Write("Nhap lua chon: ");
                chosse = Convert.ToInt32(Console.ReadLine());
                switch (chosse)
                {
                    case 1:
                        Console.Write("Nhap N: ");
                        N = Convert.ToInt32(Console.ReadLine());
                        AptechBook[] atb = new AptechBook[N];
                        for (int i = 0; i < N; i++)
                        {
                            atb[i] = new AptechBook();
                            atb[i].input();
                            listBook.Add(atb[i]);
                        }
                        break;
                    case 2:
                        foreach (AptechBook itemp in listBook)
                        {
                            itemp.display();
                        }
                        break;
                    case 3:
                        int temp;
                        foreach(AptechBook item in listBook)
                        {
                            foreach (AptechBook item1 in listBook)
                            {
                                if(item.YearPublishing > item1.YearPublishing)
                                {
                                    temp = item.YearPublishing;
                                    item.YearPublishing = item1.YearPublishing;
                                    item1.YearPublishing = temp;
                                }
                            }
                        }
                        foreach (AptechBook itemp in listBook)
                        {
                            itemp.display();
                        }
                        break;
                    case 4:
                        Console.Write("Nhap ten sach can tim: ");
                        string search = Console.ReadLine();
                        foreach (AptechBook item in listBook)
                        {
                            if (search.Equals(item.BookName))
                            {
                                item.display();
                            } else
                            {
                                Console.WriteLine("Khong tim thay {0}", search);
                                break;
                            }
                        }
                            
                        break;
                    case 5:
                        Console.Write("Nhap ten tac gia can tim: ");
                        string search1 = Console.ReadLine();
                        foreach (AptechBook item in listBook)
                        {
                            if (search1.Equals(item.BookAuthor))
                            {
                                item.display();
                            }
                            else
                            {
                                Console.WriteLine("Khong tim thay tac gia {0}", search1);
                                break;
                            }
                        }
                        break;
                    case 6:
                        // Chua lam duoc
                        break;
                    case 7:
                        // Chua lam duoc
                        break;
                    case 8:
                        Console.WriteLine("Thoat!!!!");
                        break;
                    default:
                        Console.WriteLine("Chon sai!!! Moi chon lai");
                        break;
                }

            } while (chosse != 8);
            Console.ReadKey();
        }

        public static void showMenu()
        {
            Console.WriteLine("\t\t MENU");
            Console.WriteLine("1.    Nhập thông tin n cuốn sách của Aptech");
            Console.WriteLine("2.    Hiển thị thông tin vừa nhập");
            Console.WriteLine("3.    Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị");
            Console.WriteLine("4.    Tìm kiếm theo tên sách");
            Console.WriteLine("5.    Tìm kiếm theo tên tác giả");
            Console.WriteLine("6.    Lưu thông tin sách đã nhập vào file");
            Console.WriteLine("7.    Đọc nội dung từ file và lưu vào mang quản lý sách");
            Console.WriteLine("8.    Thoát.");
        }
    }
}