• Home
  • Textbooks
  • C# Programming: From Problem Analysis to Program Design
  • Methods and Behaviors

C# Programming: From Problem Analysis to Program Design

Barbara Doyle

Chapter 3

Methods and Behaviors - all with Video Answers

Educators


Chapter Questions

01:27

Problem 1

Functions or modules found in other languages are similar to _______________ in C#.
a. modifiers
b. parameters
c. arguments
d. methods
e. classes

Arin Asawa
Arin Asawa
Numerade Educator
00:46

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

Arin Asawa
Arin Asawa
Numerade Educator
00:31

Problem 3

Which of the following modifiers is the most restrictive?
a. private
b. static
c. public
d. internal
e. protected

Arin Asawa
Arin Asawa
Numerade Educator
01:45

Problem 4

Which of the following identifiers follows the standard naming convention for a
method?
a. Calculate Final Grade
b. MilesPerGallon
c. InValueMethod
d. PrintReport
e. Method1

Arin Asawa
Arin Asawa
Numerade Educator
03:25

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

Arin Asawa
Arin Asawa
Numerade Educator
01:37

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)

Ernest Castorena
Ernest Castorena
Numerade Educator
01:57

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

Arin Asawa
Arin Asawa
Numerade Educator
01:37

Problem 8

Which of the following is a valid method call for DetermineHighestScore?
voidƒDetermineHighestScore(intƒval1,ƒintƒval2)
a. void DetermineHighestScore(int val1, int val2)
b. DetermineScore(int val1, int val2)
c. DetermineHighestScore(val1, val2)
d. DetermineHighestScore(2, 3.5)
e. GetHighestScore( )

Ernest Castorena
Ernest Castorena
Numerade Educator
02:57

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)

Ernest Castorena
Ernest Castorena
Numerade Educator
01:11

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

Aditya Sood
Aditya Sood
Numerade Educator
03:25

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)

Arin Asawa
Arin Asawa
Numerade Educator
01:19

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

Manik Pulyani
Manik Pulyani
Numerade Educator
01:45

Problem 13

. 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

Arin Asawa
Arin Asawa
Numerade Educator
00:46

Problem 14

Which of the following would be a valid call to a method defined as shown below?
public static int void InitializeValues( )
a. void InitializeValues( );
b. Console.WriteLine(InitializeValues( ));
c. int returnValue = InitializeValues( );
d. InitializeValues( );
e. InitializeValues(aVariable );

Arin Asawa
Arin Asawa
Numerade Educator
01:03

Problem 15

Given the following method definition, what would be a valid call? The variable
someIntValue is defined as an int.
public static int GetData(out int aValue, ref int bValue)
a. someIntValue = GetData(aValue, bValue);
b. someIntValue = GetData(out aValue, ref bValue);
c. someIntValue = GetData(out, ref);
d. someIntValue = GetData(int out aValue, int ref bValue);
e. GetData(out aValue, ref bValue);

Vysakh M
Vysakh M
Numerade Educator
00:46

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

Arin Asawa
Arin Asawa
Numerade Educator
00:31

Problem 17

Which of the following is not a modifier in C#?
a. const
b. private
c. public
d. static
e. protected

Arin Asawa
Arin Asawa
Numerade Educator
01:37

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)

Ernest Castorena
Ernest Castorena
Numerade Educator
01:24

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

Caleb Hurlbert
Caleb Hurlbert
Numerade Educator
01:37

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)

Ernest Castorena
Ernest Castorena
Numerade Educator
00:46

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?

Arin Asawa
Arin Asawa
Numerade Educator
04:21

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

SS
Sarvesh Somasundaram
Numerade Educator
02:19

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

Ernest Castorena
Ernest Castorena
Numerade Educator
02:59

Problem 24

The following program has several syntax errors as well as style inconsistencies. Correct
the syntax errors and identify the style violations.

Ernest Castorena
Ernest Castorena
Numerade Educator