IMD114_Fall2024_midterm_practice_solutions.pdf

Full Transcript

Chapter 1 1. (1.1) What early mechanical computing device was created by Charles Babbage? a) The Antikythera b) Pascaline c) ENIAC d) Turing machine e) The Analytical Engine 2. (1.1) The first general-purpose electronic computer is notable for using which technology? a) beads...

Chapter 1 1. (1.1) What early mechanical computing device was created by Charles Babbage? a) The Antikythera b) Pascaline c) ENIAC d) Turing machine e) The Analytical Engine 2. (1.1) The first general-purpose electronic computer is notable for using which technology? a) beads b) lasers c) transistors d) registers e) vacuum tubes 3. (1.1) What is the notable feature of the Analytical Engine? a) Helped the Allies win World War 2 through code breaking of Axis encrypted communications. b) First computer to process the United States census. c) First commercially available computing device. d) Used both electronic and mechanical components. e) Considered the earliest prototype for a general-purpose computer. 4. (1.2) Software consists of programs, which are sets of instructions telling you how to use the computer. False. software contains instructions directing the actions of the computer 5. (1.3) During the first phase of software development, you should make sure you understand the problem definition. True 6. (1.4) Using the _object-oriented_ approach the focus is on determining the data characteristics and the methods or behaviors that operate on the data. 7. (1.3) A(n) _algorithm__ is a clear, unambiguous, step-by-step process for solving a problem. 8. (1.3) Like any programming language C# has a set of rules called __syntax__ that must be followed by the programmers. (The word grammar would suffice as well.) 9. (1.4) Procedural programming is also called structured programming. True 10. (1.4) Since C# is an object-oriented language, everything is designed around a class. True 11. (1.5) In the first step of.NET program compilation all programming languages compile into a lower- level language which is not the coding of the computer you are using. What is this language? a) Microsoft Intermediate Language or MSIL b) native code c) just-in-time compilation d) common language runtime or CLR e) bytecode 12. (1.8) The System namespace contains classes that define commonly used types or classes. True 13. (1.8) A method call is the same as a method declaration. False Method declaration defines the method while the method call invokes it. 14. (1.8) In a C# program the namespace is used to ____. e) group functionally related types under a single name Midterm Review Solutions Fall 2024 Page 1 15. (1.8) In the C# language the Console is a ____ and WriteLine( ) is a ____. e) class, method 16. (1.8) The method _Main()_ is the entry point for all applications. This is where the program begins execution. Chapter 2 Data Types 17. (2.1) The base-2 number system is also called the binary number system. True 18. (2.1) The binary representation of the value ten is 00001010. True 19. (2.1) A megabyte is approximately a(n) _million__ bytes. 20. (2.1) With a computer that has 40 gigabytes of hard disk space you can store a maximum of 40 million characters. False 40 billion characters. 21. (2.2) An identifier named total$Amount can be declared to store the total transaction amount. False The dollar sign character cannot be used within an identifier. Only typographical character allowed is the underscore. 22 (2.2) C# classes, methods, namespaces, and properties follow the Pascal programming language case naming convention, which specifies that the first letter in the identifier is lowercase and the first letter of each subsequent concatenated word is capitalized. False Pascal case has the first letter of the identifier in uppercase, not lowercase. 23 (2.2) Which one of the following represents a valid identifier? d+p score#1 finalGrade √ amount owed by student 4thExam 24 (2.2) Which one of the following is a valid compile-time initialization for amountDue, a floating point variable of the double type, which will initially be set to zero? double amountDue = 0; double amountDue = 0.0c; // the c is not valid double amountDue = 0m; // the m is for decimal data types double amountDue = '0'; // the ‘0’ is for char data types double amountDue = 0f; // the f is for float data types 25. (2.2) What naming standard do the following identifiers follow? LeaveMap ChooseTreasure ActionHero WizardCastingSpell e) Pascal case 26. (2.3) Every data type in C# has a corresponding class associated with it. True 27. (2.4) Both major categories of types: value and reference are part of the.NET _______. c) common type system Midterm Review Solutions Fall 2024 Page 2 28. (2.4) Reference types contain the address or location in which the sequence of bits is stored. T 29. (2.4) Which value type can hold the following data? '0' '1' '2' '3' 'x' 'y' 'z' d) char 30. (2.6) Given this C# statement: float totalAmount = 23.57; The float compile-time initialization above will produce a syntax error because it is missing the type specifier (f or F). True 31. (2.6) The value 3.42e-4 is equivalent to _____. -.000342.000342 √ 3400000 -3.420000 32. (2.6) In C# the default for floating-point numbers is double. True 33. (2.7) Use the decimal type to represent any currency or financial values. True 34. (2.13) An implicit conversion occurs when assigning an integer literal to a decimal type variable. T 35. (2.8) The C# bool data type can take on values of true/false or on/off. False. Bool is only true/false 36. (2.9) A valid string literal representing the last month of the year is ____. lastMonthOfTheYear “December” √ December 12 37. (2.9) C# has two built-in reference types: string and object. True 38. (2.10) You can assign a variable to a constant, when declaring the constant, but you cannot assign a constant to a variable, when declaring the variable. Assume both the variable and constant have the same type. True 39. (2.11) The value of the expression 25 % 4 is 6.25. False. The value is 1 because the remainder of 25 / 4 is 1. 40. (2.11) Given the following C# statements: int payment = 50; Console.WriteLine(payment++); The WriteLine statement displays the value 51. False. It is 50 because the ++ operator is performed after the variable is used. 41. (2.11) Which statement subtracts 100 from the original value of an answer? a) answer =- 100; // assigns -100 to answer b) answer--100; // invalid statement c) answer = 100 -; // invalid statement d) answer -= 100; // correct statement e) 100 -= answer; // invalid statement Midterm Review Solutions Fall 2024 Page 3 42. (2.11) Given the following C# statements: int payment = 50; Console.WriteLine(++payment); The WriteLine() statement displays the value 51. True 43. (2.12) What is the value of the expression below? 3 + 2 * 4 - 5 b) 6 44. (2.13) For a mixed expression equation involving an integer and a double, the result is a(n) ____. b) double 45. (2.13) In C# a statement that attempts to assign an integer value to a double variable will cause a syntax error. False 46. (2.13) Which cast operation(s) will work correctly without errors? There may be zero, one, or more answers. int bag = 500; byte step = (byte) bag; // no, 500 is too big for a byte type decimal price = 12.56M; int discount = (int) price; √ int hour = 15; short food = (short) int; // should be hour not int float balloon = 4.807f; decimal cost = (decimal) balloon; √ long age = 7L; int awake = (int) age; √ 47. (2.15) The C# statements below, when executed, prints $78,888.90 decimal amount = 78888.894; Console.Write($"{amount:c}"); False - the “c” (currency) format specifier will round up Chapter 3 Using Methods 48. (3.1) Methods are the members of a class that perform an action, and through writing methods you describe the behaviour of data. True 49. (3.1) Methods may be defined in any order and placed anywhere in the file, in or outside of the class. False must be in a class Midterm Review Solutions Fall 2024 Page 4 50. (3.1) In order to call a static method from another class, the class name must be used with the method name. True 51. (3.1) Methods can be defined globally outside of a class in C#. False 52. (3.1) A program may have only one Main() method defined. True 53. (3.1) Which keyword in the method heading below is the access modifier? public static void Main() static Main() unknown void public √ 54. (3.1) A method which does not return any value upon its exit,. a) must be declared to have a void return type 55. (3.2) If the method call contains no arguments, you can omit the parenthesis following the name of the method. False. All method calls require the parenthesis. 56. (3.3) The Parse() method returns the number representation of its string argument. True 57. (3.5) Which definition of the CalcPay() method is correct for this call? static void Main() { float myTaxRate = 0.06f; double mySalary = 180.25; CalcPay(myTaxRate, mySalary, out double myTaxPayable); Console.WriteLine("My tax is {0:c}", myTaxPayable); } static void CalcPay() { --- can’t be this because there are no parameters defined in the heading empTax = empSalary * empTaxRate; } _____________________________________________ static void CalcPay( empTaxRate, empSalary, out empTax) { – can’t be this, parameters have no types empTax = empSalary * empTaxRate; } ______________________________________________ static void CalcPay( float empTaxRate, double empSalary) { – can’t be this, missing a parameter empTax = empSalary * empTaxRate; } __________________________________________________ Midterm Review Solutions Fall 2024 Page 5 static double CalcPay( float empTaxRate, double empSalary, out double empTax) { – must be void not double return empSalary * empTaxRate; } ____________________________________________________ e) static void CalcPay( float empTaxRate, double empSalary, out double empTax) { empTax = empSalary * empTaxRate; } 58. (3.?) A method declared as type bool must return either a true or false. True 59. (3.5) C# offers both call by value and call by reference parameters. Call by value is the default type. T Chapter 4 Defining a Class 60. (4.1) A class is normally associated with a(n) , which often describes a person, place, or thing and is normally a noun. b) entity 61. (4.1) C# is an object-oriented language. All the C# statements defining an application must be placed within at least one. (Select best response) e) class 62. (4.3) Which of the following is true regarding methods of a class? b) They are called instance methods. 63. (4.1) You are defining a new class for representing students. Which of the following are likely data members for that class? b) student's first name c) student's school ID number d) student's address 64. (4.2) The keyword new is used as an operator when calling constructors. True 65. (4.2) All data members of an object are initialized to 0 when an object is constructed. False - some data members are not numeric, they could be strings so are initialized to null 66. (4.2) The default constructor normally has an empty body. True 67. (4.2) In general, constructors should be defined with a access modifier. b) public 68. (4.2) A constructor is used to instantiate a class from an object. False. It is the other way around. Midterm Review Solutions Fall 2024 Page 6 69. (4.2) The class Player() needs a default constructor. Which one of the following is correct? d) Player() { } 70. (4.3) A property looks like a method because it directly represents a storage location. False. It looks like field, not a method. 71. (4.3) Accessors are special types of methods in C# used to instantiate an object of the class. False. Accessors are used to access (or ‘get’) a value of the object. 72. (4.3) Instance methods manipulate data by. a) directly accessing the private data members of the class 73. (4.3) In order to provide a new definition for the ToString() method in a class, which special keyword is added to the method heading? b) override 74. (4.4) Which of the following would be the most appropriate way to invoke the CalculateAvg() method found in the Student class if an object named camStudent had been instantiated from the class in the Main() method? public double CalculateAvg( ) a) answer = camStudent.CalculateAvg(53.2, 83.5, 94.6); -- method does not specify arguments required b) CalculateAvg( camStudent ); -- method heading is not void c) answer = camStudent.CalculateAvg( ); √ d) answer = Student.CalculateAvg( ); -- method is not static e) camStudent = CalculateAvg( ); -- method returns a double; camStudent is not a double 75. (4.3) If proper naming conventions were used in the statement below, which one of the following statements is true? plush.PricePerSqYard = 40.99; a) PricePerSqYard is a property b) plush is an object c) 40.99 is a double type literal d) all of the above Midterm Review Solutions Fall 2024 Page 7

Use Quizgecko on...
Browser
Browser