Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Computing III: Lab Packet 9 Name___________________________________ SHORT ANSWER. Write the word or phrase that best completes each statement or answers the question. 1) A structure

Computing III: Lab Packet 9

Name___________________________________

SHORT ANSWER. Write the word or phrase that best completes each statement or answers the question.

1) A structure variable is a collection of smaller values called ________ values. 1)

2) When several items (variables or variables and functions) are grouped together into a 2) single package, that is known as ________.

3) The constructor of a class that does not have any parameters is called a ________ 3) constructor.

4) A structure definition ends with the closing brace and a ________. 4)

5) What can a constructor return? 5)

6) In the following class constructor definition, the part of the header starting with a single 6) colon is called the ________.

BankAccount::BankAccount( ): balance(0), interest(0.0)

7) If you have a class with a member function called display(ostream& out), that will send the 7) values in the class to the parameter stream, and you need to call that function from within another member function, how would you call it to print the data to the screen?

8) When a structure contains another structure variable as one of its members, it is known as 8) a ________.

9) A member function that allows the user of the class to change the value of a private data 9) type is called a ________.

10) A class in which modifications to the implementation appear to be invisible to the user of 10) the class is known as ________.

11) Who can access private members in a class? 11)

12) A member function that allows the user of the class to find out the value of a private data 12) type is called a(n) ________.

13) A member function that gets called automatically when an object of the class is declared is 13) called a ________.

14) The keyword ________ defines a structure type definition. 14)

15) The double colon (::) is known as the ________ operator. 15)

1 16) The name of a constructor is ________. 16)

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

17) Given the following class definition, how could you use the constructor to assign values to an object 17) of this class?

class CDAccount { public: CDAccount( ); CDAccount(float interest, float newBalance); float getBalance( ); float getRate( ); void setRate(float interest); void setBalance(float newBalance); private: float balance, rate; };

and the following object declaration CDAccount myAccount; A) myAccount = CDAccount {myRate, myBalance}; B) myAccount = CDAccount(myRate, myBalance); C) myAccount = CDAccount[myRate, myBalance]; D) myAccount = CDAccount(float myRate, float myBalance);

18) What is wrong with the following structure definition? 18) struct MyStruct { int size; float weight; } A) nothing B) Braces are not needed. C) missing semicolon D) cannot have mixed data types in a structure

2 19) Given the following class, what would be the best declaration for a mutator function that allows 19) the user of the class to change the age?

class Wine { public: Wine( ); int getAge( ); float getCost( ); private: int age; float cost; }; A) void setAge(int newAge); B) int getAge(int newAge); C) void setAge( ); D) Wine( );

20) Given the following class definition and the following member function header, which is the 20) correct way to output the private data? class Person { public: void outputPerson(ostream& out); private: int age; float weight; int id; };

void outputPerson(ostream& out) { //what goes here? } A) out << age << weight << id; B) out << person.age << person.weight << person.id; C) out << person; D) outputPerson(person);

21) A member function of a class should be made private 21) A) only if it will never be used. B) never; it is illegal to make a member function private. C) if it will only be used by other members of the class. D) always.

22) If you are designing a class for an ADT, you can tell if the class is an ADT if 22) A) you change the private part and the rest of the program using the ADT does not compile. B) when you change the interface of the class, nothing else needs to change. C) everything must be changed. D) when you change the implementation of the class, none of the rest of the program needs to change.

3 23) A member function that allows the user of the class to see the value in a data member is known as 23) A) a manipulator function. B) a mutation. C) an accessor function. D) a mutator function.

24) In a struct, all members are __________ by default. 24) A) public B) global C) private D) all of the above

25) Which of the following is the correct function definition header for the getAge function which is a 25) member of the Person class? A) int Person::getAge( ) B) int getAge( ) C) int Person:getAge( ) D) int getAge( );

26) Which part of the ADT tells the programmer using it how to use it? 26) A) the implementation B) the interface C) the scope resolution D) the abstractness

27) Member functions of a class 27) A) may be in either section. B) may not be in the private section. C) cannot be called in the main program. D) must be in the private section.

28) Given the following class definition, how would you declare an object of the class, so that the object 28) automatically called the default constructor? class ItemClass { public: ItemClass( ); ItemClass(int newSize, float newCost); int getSize( ); float getCost( ); void setSize(int newSize); void setCost(float newCost); private: int size; float cost; }; A) ItemClass( ) myItem; B) ItemClass myItem( ); C) ItemClass myItem(1, 0.0); D) ItemClass myItem; E) You cannot do this.

29) Given the following structure definition, what is the correct way to initialize a variable called 29) today? struct DateType { int day; int month; int year; }; A) DateType today = {1,1,2000 }; B) DateType today(1,1,2000); C) DateType today = [1,1,2000]; D) DateType today = {1,1,2000,0 };

4 30) In a structure definition, the identifiers declared in the braces are called 30) A) member names. B) classes. C) variables. D) structs.

31) A member function that allows the user of the class to change the value in a data member is known 31) as A) a mutator function. B) an accessor function. C) a manipulator function. D) a mutation.

32) A data type consisting of data members and operations on those members which can be used by a 32) programmer without knowing the implementation details of the data type is called A) an abstract data type. B) an available data type. C) a primitive data type. D) an abstract definition type.

33) Given the following class and object declaration, how would you print out the age and cost of a 33) bottle of wine?

class Wine { public: Wine( ); int getAge( ); float getCost( ); private: int age; float cost; }

Wine bottle; A) cout << bottle.age << bottle.cost; B) cout << bottle; C) cout << bottle.getAge << bottle.getCost; D) cout << Wine.age, Wine.cost; E) cout << bottle.getAge( ) << bottle.getCost( );

34) You specify an individual member of a struct by using 34) A) an ampersand. B) the dot operator. C) the assignment operator. D) an underscore.

35) Data members or member functions of a class that are declared to be private 35) A) are considered to be global variables. B) may only be accessed by the main program. C) may only be accessed by members of the class. D) may not be accessed by the class.

36) Developing an ADT means that the user of your class does not have to know the details about how 36) the class is implemented. This is known as A) information hiding. B) interface. C) implementation. D) testing and debugging.

5 37) Given the following class definition, what is missing? 37) class ItemClass { public: ItemClass(int newSize, float newCost); int getSize( ); float getCost( ); void setSize(int newSize); void setCost(float newCost); private: int size; float cost; }; A) accessor functions B) a default constructor C) nothing D) mutator functions

38) In a class, all members are __________ by default. 38) A) private B) public C) global D) all of the above

39) When defining a class, the class should be composed of the kind of values a variable of the class can 39) contain, and A) nothing else. B) member functions for that class. C) other class definitions. D) the keyword private.

40) To assign values to a structure variable, you use the 40) A) less than operator. B) assignment operator. C) equals operator. D) extraction operator.

41) If you design a class with private data members, and do not provide mutators and accessors, then 41) A) the data cannot be changed or viewed by anyone. B) the class cannot be used. C) none of the above D) A and B

42) A class member function that automatically initializes the data members of a class is called 42) A) an operator. B) a constructor. C) the init function. D) a cast.

6 43) Given the following structure definitions, what is the correct way to print the person's birth year? 43) struct DateType { int day; int month; int year; };

struct PersonType { int age; float weight; DateType birthday; };

PersonType person; A) cout << birthday.year; B) cout << person.birthday.year; C) cout << year; D) cout << person.year;

44) Given the following class, what would be the best declaration for a constructor that would allow 44) the user to initialize the object with an initial age and cost?

class Wine { public: Wine( ); int getAge( ); float getCost( ); private: int age; float cost; }; A) Wine( ); B) int getAge(int newAge); C) Wine(int age); D) Wine(int newAge, float newCost);

45) If you have a class named myPersonClass, which of the following correctly declare a constructor in 45) the class definition? A) cast( ); B) init( ); C) myPersonClass( ); D) myPersonClass::myPersonClass( );

46) Why do you want to usually make data members private in a class? 46) A) so that no one can use the class B) provide information hiding C) ensure data integrity D) provide data abstraction E) B, C, and D

TRUE/FALSE. Write 'T' if the statement is true and 'F' if the statement is false.

47) A class member function may be private. 47)

7 48) Different classes may not have member functions with the same name. 48)

49) A struct variable is declared differently from a predefined type such as an int. 49)

50) Class data members are almost always public. 50)

51) All constructors for a class must be private. 51)

52) Two different structure definitions may have the same member names. 52)

53) It is possible to have multiple private labels in a class definition. 53)

54) The assignment operator may not be used with objects of a class. 54)

55) A function may return a structure. 55)

56) A structure can only be passed to a function as a call-by-value parameter 56)

8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions