Chủ đề: Mọi người chỉ e code này với ạ!
-
06-06-2016, 12:11 PM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Mọi người chỉ e code này với ạ!
Chào mọi người ạ, e có bài tập này mà e viết xong nó báo lỗi và không hiện kết quả. Đề bài là cho nhập vào chiều dài và rộng của hình chữ nhật, xuất ra chi vi và diện tích của nó, yêu cầu phải có các getter và setter, có phương thức khởi tạo cho mỗi biến và cắc phương thức để xuất kết quả. Mọi người chỉ e với, e săp thi mà e k biết gì về OOP cả, e cám ơn rất nhiều ạ.
Code của class
class manageClass
{
private double width, height;
private int xPos, yPos;
//Getter and setter
public double Width
{
get { return width; }
set { width = value; }
}
public double Height
{
get { return height; }
set { height = value; }
}
public int Posx
{
get { return xPos; }
set { xPos = value; }
}
public int Posy
{
get { return yPos; }
set { yPos = value; }
}
public manageClass()
{
Width = double.Parse(Console.ReadLine());
Height = double.Parse(Console.ReadLine());
Posx = int.Parse(Console.ReadLine());
Posy = int.Parse(Console.ReadLine());
}
public double getArea()
{
manageClass a = new manageClass();
double area = a.width * a.height;
return getArea();
}
public double getPerimeter()
{
manageClass a = new manageClass();
double perimeter = 2 * (a.width + a.height);
return getPerimeter();
}
}
class Program
{
static void Main()
{
Console.WriteLine("Ban hay nhap cac thong so can thiet");
manage.manageClass a = new manage.manageClass();
Console.WriteLine("Chieu dai va chieu rong la: {0}, {1}", a.Width, a.Height);
Console.WriteLine("Chu vi va dien tich la: {0}, {1}", a.getArea(), a.getPerimeter());
Console.ReadLine();
}
}
View more random threads:
- [JAVASCRIPT] Tìm define của hàm mặc định !
- Giúp mình Đóng gói phần mềm trên C#
- Ai rảnh giúp mình giải thích cái này với node.ForeColor = Color.FromArgb(255 - c.R, 255 - c.G, 255 - c.B) if (Math.Abs(c.ToArgb
- Lỗi font Unicode trong ASP.NET
- Mở mới 1 tabpage trong tabcontrol
- Chuyển mảng byte sang struct
- hỏi về ref trong tham chiếu biến
- bắt phím Keypress
- Các bác cho e hỏi tí về cách lấy time ạ
- kiểm tra có phải là ngày hay không và chuyển chuổi thành ngày trong datagridview
-
06-06-2016, 12:47 PM #2Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Mã:class manageClass{ private double width, height; private int xPos, yPos; //Getter and setter public double Width{ get { return width; } set { width = value; } } public double Height{ get { return height; } set { height = value; } } public int Posx{ get { return xPos; } set { xPos = value; } } public int Posy{ get { return yPos; } set { yPos = value; } } //.ctor public manageClass(){ Width = double.Parse(Console.ReadLine()); Height = double.Parse(Console.ReadLine()); Posx = int.Parse(Console.ReadLine()); Posy = int.Parse(Console.ReadLine()); } //methods public double getArea(){ manageClass a = new manageClass(); //double area = a.width * a.height; return a.width * a.height; //getArea(); } public double getPerimeter(){ manageClass a = new manageClass(); //double perimeter = 2 * (a.width + a.height); return 2 * (a.width + a.height); //getPerimeter(); }}
-
06-06-2016, 03:40 PM #3Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
E cám ơn a ạ, e đã sửa nhưng nó vẫn bị lỗi như hình.
-
06-06-2016, 03:52 PM #4Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Width = double.Parse(Console.ReadLine());
//
System.FormatException liên quan đến nhập số liệu.
https://msdn.microsoft.com/en-us/library/system.formatexception(v=vs.110).aspx
-
06-06-2016, 04:16 PM #5Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
A cho e ví dụ được k ạ, e đọc thấy lơ mơ quá ạ
-
06-06-2016, 04:17 PM #6Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Đã test :
Mã:using System;//csc c02.cs class manageClass{ private double width, height; private int xPos, yPos; //Getter and setter public double Width{ get { return width; } set { width = value; } } public double Height{ get { return height; } set { height = value; } } public int Posx{ get { return xPos; } set { xPos = value; } } public int Posy{ get { return yPos; } set { yPos = value; } } //.ctor public manageClass(){ Console.Write("width = "); width = double.Parse(Console.ReadLine()); Console.Write("height = "); height = double.Parse(Console.ReadLine()); //Console.Write("xPos = "); xPos = int.Parse(Console.ReadLine()); //Console.Write("yPos = "); yPos = int.Parse(Console.ReadLine()); } //methods public double getArea(){ //manageClass a = new manageClass(); //double area = a.width * a.height; return width * height; //getArea(); } public double getPerimeter(){ //manageClass a = new manageClass(); //double perimeter = 2 * (a.width + a.height); return 2 * (width + height); //getPerimeter(); } // static void Main(){ Console.WriteLine("Ban hay nhap cac thong so can thiet"); manageClass a = new manageClass(); Console.WriteLine("Chieu dai va chieu rong la: a = {0}, b = {1}", a.Width, a.Height); Console.WriteLine("Chu vi va dien tich la: P = {0}, S = {1}", a.getPerimeter(), a.getArea()); Console.Write(" Done, press enter to quit."); Console.ReadLine(); } }
-
06-06-2016, 04:27 PM #7Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Cuối cùng cũng dc, e cám ơn a ạ.
-
06-06-2016, 05:54 PM #8Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Không cần cám ơn.
//
Cái gì chưa cần, không nên đưa vào (xPos, yPos, Posx, Posy) nó chỉ làm rối - chi phối suy nghĩ.
Xong bước này, mở rộng sang bước khác, version ++.
Bất chấp những lầm tưởng phổ quát, hồ hết những người có âm đạo đều khó lên đỉnh khi bị kích thích âm đạo. Tuy nhiên, điều đó không có tức thị nó không thể vui được! Việc xâm nhập vào âm đạo bằng...
Quý bà giải tỏa bằng việc kích...