Chapter 3

C# Programming: From Problem Analysis to Program Design · 16 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

3 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 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) a. answer = Floor(87.2); b. answer = Math.Floor(87.2); c. Floor(87.2); d. Math.Floor(double); e. Math.Floor(87.2);

5 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)

4 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)

4 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 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 val1, out int val2) call: InputValues(out val1, out val2); b. heading: public void InputValues(int val1, int val2) call: InputValues(val1, val2); c. heading: public void InputValues(ref int val1, ref int val2) call: InputValues(ref val1, ref val2); d. heading: public int int InputValues( ) call: val1 = InputValues( ); val2ƒ=ƒInputValues(ƒ); e. none of the above

6 step solution

Problem 17

? a. const b. private c. public d. static e. protected # Which of the following is not a modifier in C#? a. const 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 v3:C) e. public static void DisplayValues(int v1, int v2, int v3)

5 step solution

Problem 19

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( )

4 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 DisplayResults( ) b. public DisplayResults(double) c. public static void DisplayResults( ) d. public static void DisplayResults(double taxAmount, double totalSales) e. public static void DisplayResults(taxAmount, totalSales)

5 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?

4 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 return 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

Show/ page