Chapter 3
C# Programming: From Problem Analysis to Program Design · 20 exercises
Problem 1
. a. modifiers b. parameters c. arguments d. methods e. classes # Functions or modules found in other languages are similar to ______ in C#. a. modifiers b. parameters c. arguments d. methods e. classes
4 step solution
Problem 2
Which of the following is placed in a method heading to indicate that no value will be returned? a. public b. static c. arguments d. void e. return
3 step solution
Problem 3
Which of the following modifiers is the most restrictive? a. private b. static c. public d. internal e. protected
4 step solution
Problem 4
Which of the following identifiers follows the standard naming convention for a method? a. Calculate Pinal Grade b. MilesPerGallon c. InvalueMethod d. PrintReport e. Method1
3 step solution
Problem 5
Which of the following would be the most appropriate way to invoke the predefined Floor () method found in the Math class? public static double Floor (double) answer \(=F 100 \times(87.2)\) b. answer \(=\) Math. Ploor (87.2) c. \(\quad\) Ploor (87.2) d. Math. Floor (double) e. Math. Floor (87.2)
4 step solution
Problem 6
Given the following statement, what would be the best heading for the DetermineAnswer( ) method? int aValue, result; result = DetermineAnswer(27.83, aValue); a. public void DetermineAnswer(27.83, aValue) b. public int DetermineAnswer( ) c. public int DetermineAnswer(double v1, int v2) d. public double int DetermineAnswer( ) e. public void DetermineAnswer(double v1, int v2)
3 step solution
Problem 7
After completing the called method's body, control is returned: a. back to the location in the calling method that made the call b. to the last statement in the method that made the call c. to the first statement in the method that made the call d. to the Main() method e. to the method that is listed next in the printed source code
4 step solution
Problem 9
What is the signature of the following method? public void SetNoOfSquareYards(double squareYards) { noOfSquareYards = squareYards; } a. public void SetNoOfSquareYards(double squareYards) b. public SetNoOfSquareYards(double squareYards) c. SetNoOfSquareYards d. public SetNoOfSquareYards(double) e. SetNoOfSquareYards(double)
5 step solution
Problem 10
Variables needed only inside a method should be defined as ______ a. private member data b. local variables c. properties d. arguments e. parameters
4 step solution
Problem 11
. Given the call to the method ComputeCost( ) shown below, which of the following would be the most appropriate heading for the method? The variable someValue is declared as an int. someValue = ComputeCost(27.3); a. public static void ComputeCost(double aValue) b. public static int ComputeCost( ) c. public static double ComputeCost(int someValue) d. public static int ComputeCost(double aValue) e. public static int ComputeCost(int aValue)
3 step solution
Problem 12
The following is probably an example of a ______ DIsplayInstructions ( ) a. call to a value-returning method b. call to a void method c. method heading d. method definition e. call to a method with multiple arguments
5 step solution
Problem 13
naming conventions, the local variable names: a. follow the Camel case convention b. should use an action verb phrase c. begin with an uppe… # If you follow the standard C# naming conventions, the local variable names: a. follow the Camel case convention b. should use an action verb phrase c. begin with an uppercase character d. are named like namespace identifiers e. are defined inside parenthesis of the method header
3 step solution
Problem 16
If a method is to be used to enter two values that will be used later in the program, which of the following would be the most appropriate heading and call? a. heading public void InputValues (out int vall, out \(\ln t\) val2) call: InputValues (out vall, out val2); b. heading: public void InputValues (int vall, int val2) call: InputValues(val1, val2); c. heading: public void InputValues (ref int vall, ref int val2) call: InputValues (ref val1, ref val2); d. heading: public int int InputValues ( ) call: val1 = Inputvalues( ) val \(2=\) Inputvalues () e. none of the above
6 step solution
Problem 17
? a. int b. private c. public d. static e. protected # Which of the following is not a modifier in C#? a. int b. private c. public d. static e. protected
3 step solution
Problem 18
Given the following task, which would be the most appropriate method heading? A method displays three integer values formatted with currency. a. public static int int int Displayvalues ( ) b. public static int DisplayValues (int v1, int v2, int v3) c. public static void DisplayValues ( ) d. public static void DisplayValues (int v1:C, int v2:C, Int \(v 3: C\) ) e. public static void DisplayValues (int v1, int v2, int v3)
3 step solution
Problem 19
9\. Given the following task, which would be the most appropriate method heading? A method receives three whole numbers as input. The values represent grades. They should be unchangeable in the method. The method should return the average with a fractional component. a. static double DetermineGrade(int grade1, int grade2, int grade3) b. static int DetermineGrade(int grade1, int grade2, int grade3) c. static int int int DetermineGrade(double finalAverage) d. static double DetermineGrade(ref int grade1, ref int grade2, ref int grade3) e. static void DetermineGrade( )
7 step solution
Problem 20
Given the following task, which would be the most appropriate method heading? Results have been calculated for taxamount and totalsales. Write a method heading that accepts these values as input for display purposes. a. public static D1splayResults ( ) b. public DisplayResults (double) c. public static void DisplayResults ( ) d. public static void DisplayResults (double taxamount, double totalsales) e. public static void D1splayResults (taxamount, totalsales)
4 step solution
Problem 21
Use the following method headings to answer the questions below: public static int DetermineResult(int value1, ref double value2) public static void DisplayResult(int value1, double value2) public static int GetValue( ) a. How many parameters does each method have? b. What is the return type for each of the methods? c. Which of the preceding methods will have a return statement as part of its body?
7 step solution
Problem 22
Write methods to do the following: a. Display three full lines of asterisks on the screen. b. Accept as an argument your age, and display that value along with an appropriate label. c. Accept two floating-point values as arguments. Display the values formatted with three digits to the right of the decimal. d. Accept three int arguments and return their sum. e. Accept no arguments and retum no values. Initialize a local Boolean variable to true. Have the method print the Boolean's value.
5 step solution
Problem 23
What will be produced from the following predefined Math class method calls? a. Console.WriteLine(Math.Abs(-98887.234)); b. Console.WriteLine(Math.Pow(4,3)); c. Console.WriteLine(Math.Sign(-56)); d. Console.WriteLine(Math.Sqrt(81)); e. Console.WriteLine(Math.Min(-56, 56));
5 step solution