Write the following code using c #,Write a method with the following specifications: name: DisplayEquation arguments: none return value: nothing displays: the following table: x 5 3x -2x^2 y 0.0 5.0 0.0 0.0 5.0 0.3 5.0 0.8 -0.1 5.6 0.5 5.0 1.5 -0.5 6.0 0.8 5.0 2.3 -1.1 6.1 1.0 5.0 3.0 -2.0 6.0 1.3 5.0 3.8 -3.1 5.6 1.5 5.0 4.5 -4.5 5.0 1.8 5.0 5.3 -6.1 4.1 2.0 5.0 6.0 -8.0 3.0 This table is calculated using the quadratic equation y = 5 + 3x -2x2 The value of x starts at 0 and moves in increments of 0.25 to 2.0. (The first column is misleading because the last digit is rounded up i.e. 0.25 is displayed as 0.3and. 0.75 is displayed as 0.8) Modify your DisplayMenu method by adding another choice below the last item. In your main when the user enters the appropriate choice in response to the menu choices, you will invoke this method and to display the above values
时间: 2024-02-10 07:03:22 浏览: 173
Here's the code for the DisplayEquation method in C#:
```
public void DisplayEquation()
{
Console.WriteLine("x 5 3x -2x^2 y");
double x = 0;
while (x <= 2)
{
double y = 5 + 3 * x - 2 * x * x;
Console.WriteLine($"{x,-5:F1} 5.0 {3*x,-4:F1} {(-2*x*x),-5:F1} {y,-5:F1}");
x += 0.25;
}
}
```
And in the main method, you can call the DisplayEquation method when the user selects the appropriate choice:
```
int choice = 0;
while (choice != 3)
{
DisplayMenu();
choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
// call other method
break;
case 2:
DisplayEquation();
break;
case 3:
Console.WriteLine("Exiting program...");
break;
default:
Console.WriteLine("Invalid choice.");
break;
}
}
```
阅读全文