请教几个初级问题,着急!着急!着急!在线等待帮助,谢谢!
通过设计墙壁绘画报价程序,学习和使用其他人的代码(如最后给出的代码例子),read和modify方法,尤其是formal parameters,pass arguments以及返回值;理解并且熟练使用out和ref关键字;使用try和catch 去ref actor代码。1)修改已经存在的方法参数:
Adapt the “CalSquare” method so you pass as an argument “WallLength”and “WallWidth” rather than return the “width” or “length” from the method.Namely “WallLength” declared in Main is to be modified in “CalSquare”.
2) Modify an existing method and the logic of method calls
目的: Change an existing static method to remove a return type and instead pass a reference parameter. Hint use the “try” and “catch" keywords.
Adapt "CalSquare" so that it returns True or False depending on whether the user has entered a valid number as a string.
3)Simplify and Ref actor
目的: Learn the meaning of “ref” actoring code. Learn that methods that return values can be passed themselves as argument to other methods.
Refactor (find out what this word means if you don’t know) the following
code to eliminate the use of the two identifiers MoneyEveryMeter and
TotalOfSquareMeters. Don’t forget to delete the identifier:
MoneyEveryMeter = CalMoney ();
TotalOfSquareMeters = DetermSquareMeter (WallWidth, WallLength);
FinalResult (TotalOfSquareMeters, MoneyEveryMeter);
4) Change formal parameters in the Main method header
目的: Add the appropriate formal parameters to the Main method so that an argument(s) can be passed from the DOS command line.
Modify the arguments to Main so that the your name can be passed to program via the command line argument in DOS 。
5)Learn to pass arguments from DOS and Test the code
目的: Pass arguments from the command line and use it internal to the console application.
Modify the DisplayInstructions method so that the argument passed to the program via Main can be passed to DisplayInstructions to create a personalised greeting message 。
给出的例子如下:==============================================================================================
using System;
namespace CarpetExampleWithClassMethods
{
class PaintingPrice
{
static void Main()
{
double WallWidth;
double WallLength;
double MoneyEveryMeter;
double TotalOfSquareMeters;
GreetingInfo();
WallLength = CalSquare("Length");
WallWidth = CalSquare("Width");
MoneyEveryMeter = CalMoney();
TotalOfSquareMeters =
DetermSquareMeter(WallWidth, WallLength);
FinalResult(TotalOfSquareMeters, MoneyEveryMeter);
}
public static void GreetingInfo()
{
Console.WriteLine("This program is designed to "
+ "determine how much money"
+ " you will paid for a wall painting.");
Console.WriteLine();
Console.WriteLine("You need to input "
+ "the size of the wall ");
Console.WriteLine("and the price for painting works, "
+ "in price every square meter");
Console.WriteLine();
}
public static double CalSquare(string side)
{
string sideValue;
double meter;
Console.Write("How Long is the {0} in Meters: ",
side);
sideValue = Console.ReadLine();
meter = double.Parse(sideValue);
return (meter);
}
public static double CalMoney()
{
string sideValue;
double money;
Console.Write("How much for every square"
+ "Meter: ");
sideValue = Console.ReadLine();
money = double.Parse(sideValue);
return money;
}
public static double DetermSquareMeter(double width,
double length)
{
double TotalOfSquareMeters;
TotalOfSquareMeters = length * width;
return TotalOfSquareMeters;
}
public static double DetermMoney(double SquareMeter,
double MoneyEverySquareMeter)
{
return (MoneyEverySquareMeter * SquareMeter);
}
public static void FinalResult(double SquareMeter,
double MoneyEverySquareMeter)
{
Console.WriteLine();
Console.Write("Total square is : ");
Console.WriteLine("{0:N2}", SquareMeter);
Console.Write("Pay rate is : {0:C} ",
MoneyEverySquareMeter);
Console.WriteLine(" You need to pay: {0:C}",
DetermMoney(SquareMeter, MoneyEverySquareMeter));
}
}
}
==============================================================================================
--------------------编程问答-------------------- 问题一共是上面5个,请哪位大虾能够指点指点,不胜感激 --------------------编程问答-------------------- 作业吧?
补充:.NET技术 , C#