using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Rectangle
{
private double width;
private double height;
public Rectangle() { }
public Rectangle(double Width, double Height) // nếu dài hoặc rộng <=0 thì
thiết lập về 1, nếu >0 thì bình thường
{
if (Width > 0)
width = Width;
else
{
width = 1;
Console.WriteLine("Chieu rong <=0 khong phu hop nen set ve 1");
}
if (Height > 0)
height = Height;
else
{
height = 1;
Console.WriteLine("Chieu dai <=0 khong phu hop nen set ve 1");
}
}
public void Input()
{
do
{
Console.WriteLine("Nhap chieu rong >0:");
width = Int32.Parse(Console.ReadLine());
}
while (width < 0);
do
{
Console.WriteLine("Nhap chieu dai: >0");
height = Int32.Parse(Console.ReadLine());
}
while (height < 0);
}
public override String ToString()
{
String result = "Kich thuoc hinh chu nhat la " + width + "x" + height;
return result;
}
public double GetPerimeter()
{
return (width + height) * 2;
}
public double GetArea()
{
return width * height;
}
public bool IsSameArea(Rectangle rect)
{
if (this.width * this.height == rect.width * rect.height)
return true;
else
return false;
}
}
}
namespace Bai1
{
class Program
{
static void Main(string[] args)
{
Rectangle a = new Rectangle(4,3);
a.GetPerimeter();
Console.WriteLine(a.GetPerimeter());
Console.WriteLine(a.ToString());
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Date
{
private int day;
private int month;
private int year;
public Date(int day, int month, int year)
{
this.day = day;
this.month = month;
this.year = year;
}
public int getDay()
{
return day;
}
public int getMonth()
{
return month;
}
public int getYear()
{
return year;
}
public void setDay(int day)
{
this.day = day;
}
public void setMonth(int month)
{
this.month = month;
}
public void setYear(int year)
{
this.year = year;
}
public void setDate(int day, int month, int year)
{
this.day = day;
this.month = month;
this.year = year;
}
public override string ToString()
{
return String.Format("{0:00}", this.day) + "/" + String.Format("{0:00}",
this.month) + "/" + String.Format("{0:00}", this.year);
}
}
}
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Date B = new Date(25, 12, 2022);
Console.WriteLine(B.ToString());
B.setDay(10);
Console.WriteLine(B.ToString());
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bai5
{
class Author
{
private string name;
private string email;
private char gender;
public Author(string name, string email, char gender)
{
this.name = name;
this.email = email;
this.gender = gender;
}
public string getName()
{
return name;
}
public string getEmail()
{
return email;
}
public void setEmail(string email)
{
this.email = email;
}
public char getGender()
{
return gender;
}
public override string ToString()
{
return $"Author [{name}, {email}, {gender}]";
}
}
}
namespace Bai5
{
class book
{
private string name;
private Author author;
private double price;
private int qty = 0;
public book(string name, Author author, double price)
{
this.name = name;
this.author = author;
this.price = price;
}
public book(string name, Author author, double price, int qty)
{
this.name = name;
this.author = author;
this.price = price;
this.qty = qty;
}
public string getName()
{
return name;
}
public Author getAuthor()
{
return author;
}
public double getPrice()
{
return price;
}
public void setPrice(double price)
{
this.price = price;
}
public int getQty()
{
return qty;
}
public void setQty(int qty)
{
this.qty = qty;
}
public override string ToString()
{
return $"Book [{name}, {author}, {price}, {qty}]";
}
}
}
namespace Bai5
{
class Program
{
static void Main(string[] args)
{
Author A1 = new Author("Nguyen Van B", "[email protected]", 'M');
book B1 = new book ("Lap trinh co ban", A1, 1250);
Console.WriteLine(B1.ToString());
B1.setPrice(1200);
Console.WriteLine(B1.ToString());
Console.ReadLine();
}
}
}