Chapter 4

C# Programming: From Problem Analysis to Program Design · 19 exercises

Problem 1

Objects are instances of _______________ . a. data members b. parameters c. properties d. methods e. classes

4 step solution

Problem 4

Which of the following identifiers follows the standard naming convention for naming a class? a. Calculate Final Grade b. MilesPerGallon c. Students d. Reports e. Employee

7 step solution

Problem 6

Which of the following is one of the user-defined classes inherited from the object class? a. ToString( ) b. Main( ) c. CalculateAvg( ) d. EqualsHashCode( ) e. TypeHashCode( )

4 step solution

Problem 8

Which of the following is a valid overloaded method for CalculateAvg( )? intƒCalculateAvg(intƒval1,ƒintƒval2) a. void CalculateAvg(int val1, int val2) b. int CalculateAvg(int val1, int val2) c. int CalculateAvg(double val1, double val2) d. double CalculateAvg(int val1, int val2) e. int CalculateAverage(int val2, int val1)

8 step solution

Problem 9

What operator is used to instantiate the class a. method b. plus symbol c. ToString( ) d. new e. equal symbol

4 step solution

Problem 10

Instance variables are the same as: a. private member data b. local variables c. properties d. arguments e. parameters

4 step solution

Problem 11

Given the Employee class shown below, which of the following would be the most appropriate heading for its default constructor? public classƒEmployeeƒ{ a. public void Employee( ) b. public Employee( ) c. public static Employee( ) d. private void Employee( ) e. private Employee( )

7 step solution

Problem 12

The following is probably an example of a _________ public doubleƒGetYards(ƒ) a. constructor b. mutator c. property d. accessor e. class definition

4 step solution

Problem 14

Which of the following would be a valid call to the default constructor for the following class? public classƒEmployeeƒ{ a. Employee employee1 = new Employee( ); b. Employee employee1= new undergrad( ); c. Employee employee1; d. Employee employee1= new Employee(default); e. Not enough information is given to be able to answer.

7 step solution

Problem 15

Given the following class definition, what would be a valid heading for a mutator? public classƒStudent{ private stringƒname; private doubleƒgpa;} a. public double SetGpa(double gpaValue) b. public void SetGpa(double gpaValue) c. public double SetGpa( ) d. public void GetGpa(double gpaValue) e. public double SetGpa( )

4 step solution

Problem 17

is used with constructors? a. const b. private c. public d. static e. protected # Which of the following modifiers in C# is used with constructors? a. const b. private c. public d. static e. protected

5 step solution

Problem 18

Normally, member data uses a _______________ access modifier, and methods use a _______________ access modifier for object-oriented solutions. a. protected public b. private protected c. public protected d. public private e. private public

5 step solution

Problem 19

For a class called Account that has data members of accountNumber, balance, and transactionAmount, which would be the most appropriate instance method heading for a method that reduces the transaction amount from the current balance? a. static double ReduceAccount(double accountBalance, double transactionAmount) b. double ReduceAccount(double accountBalance, double transactionAmount) c. static ReduceAccount( ) d. void ReduceAccount( ) e. static void ReduceAccount( )

4 step solution

Problem 20

In order to provide a new definition for the ToString( ) method,what keyword is added to the method heading? a. static b. override c. new d. overload e. public

4 step solution

Problem 21

Given the following code snippet: public class Camera Line1 { Line2 private double zoom; Line 3 private double lensSpeed; Line 4 public double Zoom Line 5 { Line 6 get Line 7 { Line 8 return zoom; Line 9 } Line 10 } Line 11 public Camera ( ) Line 12 { Line 13 } Line 14 public Camera (double zCapacity, Line 15 double ls) Line 16 { Line 17 int xValue = 2; Line 18 zoom = zCapacity * xValue; Line 19 lensSpeed = ls; Line 20 } Line 21 public double GetLensSpeed(ƒ) Line 22 { Line 23 return lensSpeed; Line 24 } Line 25 Identify the following items by line number: a. method headings b. property identifier c. default constructors d. formal parameters e. local variables

5 step solution

Problem 22

Explain how instance methods differ from class methods.What differs when you want to invoke each different type? Which one requires an object in order for it to be called?

5 step solution

Problem 23

What does it mean to override a method? Why should the ToString( ) method be overridden for user-defined classes?

3 step solution

Problem 24

Explain the role of the constructor.What is the default constructor? When do you automatically get a default constructor?

3 step solution

Problem 25

The following program has several syntax errors as well as style inconsistencies. Correct the syntax errors and identify the style violations. public class Chair { private string type; private double weight; private double cost; private Chair() { } private Chair(weight, type, cost) { } public string ChairType { get { return type; } set { ChairType = value; } } public override ToString() { return “Type of Chair: “ + Chair.Type; } } }

4 step solution

Show/ page