7.1 Fill in the blanks in each of the following statements:
A method is invoked with a(n) .
A variable known only within the method in which it’s declared is called a(n) .
The statement in a called method can be used to pass the value of an expression back to the calling method.
The keyword indicates that a method does not return a value.
Data can be added to or removed from only the of a stack.
Stacks are known as data structures—the last item pushed (inserted) on the stack is the first item popped off (removed from) the stack.
The three ways to return control from a called method to a caller are , and .
An object of class produces pseudorandom numbers.
The program-execution stack contains the memory for local variables on each invocation of a method during an app’s execution. This data, stored as a portion of the program-execution stack, is known as the or of the method call.
If there are more method calls than can be stored on the program-execution stack, an error known as a(n) occurs.
The of a declaration is the portion of an app that can refer to the entity in the declaration by its unqualified name.
It’s possible to have several methods with the same name that each operate on different types or numbers of arguments. This feature is called method .
The program-execution stack is also referred to as the stack.
A method that calls itself either directly or indirectly is a(n) method.
A recursive method typically has two components: one that provides a means for the recursion to terminate by testing for a(n) case and one that expresses the problem as a recursive call for a slightly simpler problem than does the original call.
In an expression-bodied method or read-only property, the symbol introduces the method’s or read-only-property get
accessor’s body.
Types are either types or types.
7.2 For the class Craps
in Fig. 7.8, state the scope of each of the following entities:
the variable randomNumbers
.
the variable die1
.
the method RollDice
.
the method Main
.
the variable sumOfDice
.
7.3 Write an app that tests whether the examples of the Math
class method calls shown in Fig. 7.2 actually produce the indicated results.
7.4 Give the method header for each of the following methods:
Method Hypotenuse
, which takes two double-precision, floating-point arguments side1
and side2
and returns a double-precision, floating-point result.
Method Smallest
, which takes three integers x
, y
and z
and returns an integer.
Method Instructions
, which does not take any arguments and does not return a value. [Note: Such methods are commonly used to display instructions to a user.]
Method IntToDouble
, which takes integer argument number
and returns a double
value.
7.5 Find the error(s) in each of the following code segments. Explain how to correct the error.
void G()
{
Console.WriteLine("Inside method G");
void H()
{
Console.WriteLine("Inside method H");
}
}
int Sum(int x, int y)
{
int result;
result = x + y;
}
void F(float a);
{
float a;
Console.WriteLine(a);
}
void Product()
{
int a = 6, b = 5, c = 4, result;
result = a * b * c;
Console.WriteLine("Result is " + result);
return result;
}
7.6 Write a complete C# app to prompt the user for the double
radius of a sphere, and call method SphereVolume
to calculate and display the volume of the sphere. Write an expression-bodied method containing the following expression to calculate the volume:
(4.0 / 3.0) * Math.PI * Math.Pow(radius, 3)