Professional Documents
Culture Documents
Lab 5 6 7 8 C#1
Lab 5 6 7 8 C#1
class ChuNhat
{
public double rong;
public double dai;
}
public void Xuat()
{
Console.WriteLine("Ho ten: {0}", hoTen);
Console.WriteLine("Nganh: {0}", tenNganh);
Console.WriteLine("Diem: {0}", GetDiem());
Console.WriteLine("Hoc Luc: {0}", GetHocLuc());
}
class SinhVienPolyEx : SinhVienPoly
{
private double diem;
public SinhVienPolyEx(string hoTen, string tenNganh, double diem) : base(hoTen, tenNganh)
{
this.diem = diem;
}
public override double GetDiem()
{
return diem;
}
}
class Prongram
{
static void Main(string[] args)
{
SinhVienPoly sv = new SinhVienPolyEx("BEo", "CNTT", 4);
sv.Xuat();
}
}
}
}
public void Xuat()
{
Console.WriteLine("Ho ten: {0}", hoTen);
Console.WriteLine("Nganh: {0}", tenNganh);
Console.WriteLine("Diem: {0}", GetDiem());
Console.WriteLine("Hoc Luc: {0}", GetHocLuc());
}
class SinhVienIT : SinhVienPoly
{
private double diemJava;
private double diemHTML;
private double diemCSS;
public SinhVienIT(string hoTen, string tenNganh, double diemJava, double diemHTML, double diemCSS) :
base(hoTen, tenNganh)
{
this.diemJava = diemJava;
this.diemHTML = diemHTML;
this.diemCSS = diemCSS;
}
public override double GetDiem()
{
return (2 * diemJava + diemHTML + diemCSS) / 4 ;
}
}
class SinhVienBiz : SinhVienPoly
{
private double diemMarketing;
private double diemSales;
public SinhVienBiz(string hoTen, string tenNganh, double diemMarketing, double diemSales) : base(hoTen,
tenNganh)
{
this.diemMarketing = diemMarketing;
this.diemSales = diemSales;
}
public override double GetDiem()
{
return (2 * diemMarketing + diemSales) / 3;
}
}
class Prongram
{
static void Main(string[] args)
{
SinhVienPoly svit = new SinhVienIT("BEo", "CNTT", 4, 8 ,7 );
Console.WriteLine("Thong tin sinh vien IT: ");
svit.Xuat();
SinhVienPoly svbiz = new SinhVienBiz("gay", "Kinh daonh", 6, 8);
Console.WriteLine("Thong tin sinh vien Biz: ");
svbiz.Xuat();
}
}
}
void DisplayInfo();
}
public class Book : IBook
{
public string Title { get; set; }
public string Author { get; set; }
public string Publisher { get; set; }
public int Year { get; set; }
public string ISBN { get; set; }
public List<string> Chapters { get; set; }
public Book(string title, string author, string publisher, int year, string iSBN, List<string> chapters)
{
Title = title;
Author = author;
Publisher = publisher;
Year = year;
ISBN = iSBN;
Chapters = chapters;
}
public void DisplayInfo()
{
Console.WriteLine("Ten sach: {0}", Title);
Console.WriteLine("Ten tac gia: {0}", Author);
Console.WriteLine("Nha xuat ban: {0}", Publisher);
Console.WriteLine("ISNB: {0}", ISBN);
Console.WriteLine("Chuong: ");
foreach (var chap in Chapters)
{
Console.WriteLine("{0}", chap);
}
}
}
public class BookList
{
private List<Book> books;
public BookList()
{
books = new List<Book>();
}
public void AddBook(IBook book)
{
books.Add((Book)book);
}
public void DisplayBooks()
{
foreach (var book in books)
{
book.DisplayInfo();
}
}
public void SortByAuthor()
{
books.Sort((x,y) => x.Author.CompareTo(y.Author));
}
public void SortByTitle()
{
books.Sort((x, y) => x.Title.CompareTo(y.Title));
}
public void SortByYear()
{
books.Sort((x, y) => x.Year.CompareTo(y.Year));
}
}
internal class Program
{
static void Main(string[] args)
{
List<string> chapters1 = new List<string> { "Chapter 1", "Chapter 2", "Chapter 3" };
IBook book1 = new Book("Book 1", "Author B", "Publisher X", 2020, "ISBN123456", chapters1);
while (true)
{
Console.WriteLine("Menu");
Console.WriteLine("Add");
Console.WriteLine("Display");
Console.WriteLine("Exit");
Console.WriteLine("Choice: ");
string choice = Console.ReadLine();
switch (choice)
{
case "add":
Console.WriteLine("Enter integer number:");
if (int.TryParse(Console.ReadLine(),out int num))
{
manager.AddNumber(num);
}
else
{
Console.WriteLine("Invalid");
}
break;
case "display":
manager.DisplayNumber();
break;
case "exit":
Console.WriteLine("Exit");
return;
default : Console.WriteLine("Ivnvalid");
break;
}
}
}
}
class Product
{
public string Name { get; set; }
public double Cost { get; set; }
public int OnHand { get; set; }
public override string ToString()
{
return $"Name: {Name}, Cost: {Cost}, On Hand {OnHand}";
}
}
internal class Program
{
static void Main(string[] args)
{
ArrayList pro = new ArrayList();
class Program
{
static void Main(string[] args)
{
Hashtable weekDay = new Hashtable();
weekDay.Add(1, "Monday");
weekDay.Add(2, "Tuesday");
weekDay.Add(3, "Wednesday");
weekDay.Add(4, "Thursday");
weekDay.Add(5, "Friday");
weekDay.Add(6, "Saturday");
weekDay.Add(7, "Sunday");
class Program
{
static void Main(string[] args) {
int a = 1;
int b = 2;
Console.WriteLine($"Truoc khi hoan vi: a = {a}, b = {b} ");
Swap( ref a, ref b );
Console.WriteLine($"Sau khi hoan vi: a = {a}, b = {b} ");
string x = "Beo";
string y = "Vai";