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:
- Vấn đề build ra file exe trong lập trình C#
- lỗi kết nối cơ sở dữ liệu
- Cách để chương trình chạy với net fame 3.5
- Tô màu background theo điều kiện chỉ dùng CSS
- tham chiếu vào mảng 2 chiều ở form khác (mảng 2 chiều toàn cục?)
- các bác xem hộ e cái này
- [C# Winform]
- chỉ giúp get url của hrml
- Vấn đề về login Mp3.zing.vn
- Tạo bộ đếm thời gian trong asp.net giống facebook.
-
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 ++.
Hướng dẫn vui nhộn về phương tiện nong lỗ đít Thuốc giãn hậu môn nghe có vẻ đáng sợ, nhưng đừng sợ! Hướng dẫn này sẽ đưa bạn qua hành trình hích khi dùng dụng cụ làm giãn lỗ đít, khiến nó trở...
Hướng dẫn vui nhộn về sản phẩm làm...