Deck 6: Structures and Classes

Full screen (f)
exit full mode
Question
A sure test of whether you have succeeded in producing an Abstract Data Type (whether you have truly separated the interface from the implementation)is whether you can use the ADT then change either the implementation or the client code without being required to change the other.
Use Space or
up arrow
down arrow
to flip the card.
Question
A structure variable can be defined directly in the same statement that defines a structure definition.
Question
Consider these hierarchical structures.
struct Date
{
int year;
//members
};
struct Person
{
Date birthDay;
//other members
};
Person Bill;
The year of Bill's birthday may be accessed as Bill.year;
Question
Multiple public: and private: sections are prohibited in a class.
Question
There is no aggregate initialization available for structure variables.You must declare structure variables then use assignment to initialize the members.
Question
Structure definitions are usually global (defined outside any functions).
Question
A structure member is access using the index operator [ ],with the member name as index.[ ]
Question
No special syntax is necessary to define a function that uses a structure parameter.(This is unlike using an array parameter. )
Question
There is no access to private members of a class by any function defined outside the class.
Question
The following definition of the structure variables of type myStruct s and t could be made using several definitions using the structure tag.
struct myStruct
{
int i;
double d;
} s,t;
Question
Consider the class and struct definitions below.
struct myStruct
{
int i;
double d;
};
class myClass
{
int i;
double d;
};
myStruct a;
a.i = 3;
myClass b;
b.i = 3;
True or False: All these statements will compile with no problem.
Question
In defining a member function whose declaration is in a class,you use the dot operator to specify that the member function being defined belongs in the class,as
class foo
{
public:
// other members
void output( );
// other members
};
void foo.output( )
{
/* whatever */
}
Question
A data type is a collection of a set of values together with a set of basic operations defined on the values.
Question
The concept of class is central to Object Oriented Programming.
Question
An abstract data type is a collection of a set of values together with a set of basic operations defined on the values.
Question
A class type cannot be used in some ways that a built-in type can be used.
Question
A structure can have a member whose type is another structure.
Question
If,in a class,one uses the keyword public:,it affects only the member that immediately follows the keyword public,making this member accessible to any other function defined anywhere.
Question
A class is a type similar to a structure type that normally has member functions as well as member variables.
Question
A C++ structure,or struct,like the C++ array,is a homogeneous data structure.(i.e. ,all data is of the same type)
Question
What is the reason for separating the interface from the implementation of an ADT?
Question
The scope resolution operator can be used with an object to qualify a member function.
Question
Here are several different initializations of a structure variable.State what happens in each initialization.
struct WeatherData
{
int temperature;
int windChill;
int windSpeed;
};
a)WeatherData prediction ={ };
b)WeatherData prediction ={40};
c)WeatherData prediction ={40,-10,};
d)x WeatherData prediction ={40,-10,20 };
Question
What is the error in the following structure definition?
struct A
{
int b;
int c;
}
int main()
{
A x;
// other code
}
Question
In the structure definition
struct StudentRecord
{
int studentID;
char grade;
}
give the structure tag,and each of the member names.
Question
C++ allows the programmer to deal with data at a higher level of abstraction in part because related data of differing types can be treated as a unit in

A)a array variable
B)a structure variable
C)a function
D)a library
E)a class variable
Question
The dot operator is used between an object and a data member or between a calling object and a call to a member function from the class of the object.
Question
Given the ShoeType structure type-definition.Write a function for the declaration (prototype).
struct ShoeType
{
char style;
double price;
};
void setSalePrice(ShoeType& Item,double discountRate);
//discountRate =(discounted price)/(regular price)
//Adjusts sale price to reflect the specified discount.
Question
Carefully distinguish between the scope resolution operator,and the dot operator.
Question
It seems that mutator and accessor functions defeat the purpose of making the member variables private.Why is this not so?
Question
Carefully define mutator and accessor functions of a class.
Question
Given the ShoeType structure type definition.Write a function for the declaration (prototype).
struct ShoeType
{
char style;
double price;
};
void readShoeRecord(ShoeType& Item);
// Prompts for data and fills ShoeType argument members
Question
What is the output of the following program.?
#include
using namespace std;
struct ShoeType
{
char style;
double price;
};
int main()
{
ShoeType shoe1,shoe2;
shoe1.style = 'P';
shoe1.price = 98.98;
cout << shoe1.style << " $" << shoe1.price << endl;
shoe2 = shoe1;
//Put shoe2 on sale!
shoe2.price = shoe1.price/2;
cout << shoe2.style << " $" << shoe2.price << endl;
}
Question
Write a definition for a structure type for personnel records for hourly employees.The record contains an hourly wage rate,accrued vacation in an integer number of days,and employee status (use 'T' for temporary and 'P' for permanent).Part of the problem is appropriate choices of type and member names.
Question
Carefully identify,define each term and give differences between the implementation and the interface of an abstract data type (ADT).This requires a bit more writing of English than other question on this test.
Question
A member of a structure or of a class is accessed using the

A)Comma operator
B)The dot operator
C)The indexing operator
D)The ampersand operator
Question
Given the ShoeType structure type definition,write a function declaration (prototype)for a void function that uses a ShoeType structure variable as a value parameter.
struct ShoeType
{
char style;
double price;
};
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/37
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 6: Structures and Classes
1
A sure test of whether you have succeeded in producing an Abstract Data Type (whether you have truly separated the interface from the implementation)is whether you can use the ADT then change either the implementation or the client code without being required to change the other.
True
2
A structure variable can be defined directly in the same statement that defines a structure definition.
True
3
Consider these hierarchical structures.
struct Date
{
int year;
//members
};
struct Person
{
Date birthDay;
//other members
};
Person Bill;
The year of Bill's birthday may be accessed as Bill.year;
False
4
Multiple public: and private: sections are prohibited in a class.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
5
There is no aggregate initialization available for structure variables.You must declare structure variables then use assignment to initialize the members.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
6
Structure definitions are usually global (defined outside any functions).
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
7
A structure member is access using the index operator [ ],with the member name as index.[ ]
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
8
No special syntax is necessary to define a function that uses a structure parameter.(This is unlike using an array parameter. )
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
9
There is no access to private members of a class by any function defined outside the class.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
10
The following definition of the structure variables of type myStruct s and t could be made using several definitions using the structure tag.
struct myStruct
{
int i;
double d;
} s,t;
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
11
Consider the class and struct definitions below.
struct myStruct
{
int i;
double d;
};
class myClass
{
int i;
double d;
};
myStruct a;
a.i = 3;
myClass b;
b.i = 3;
True or False: All these statements will compile with no problem.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
12
In defining a member function whose declaration is in a class,you use the dot operator to specify that the member function being defined belongs in the class,as
class foo
{
public:
// other members
void output( );
// other members
};
void foo.output( )
{
/* whatever */
}
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
13
A data type is a collection of a set of values together with a set of basic operations defined on the values.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
14
The concept of class is central to Object Oriented Programming.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
15
An abstract data type is a collection of a set of values together with a set of basic operations defined on the values.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
16
A class type cannot be used in some ways that a built-in type can be used.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
17
A structure can have a member whose type is another structure.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
18
If,in a class,one uses the keyword public:,it affects only the member that immediately follows the keyword public,making this member accessible to any other function defined anywhere.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
19
A class is a type similar to a structure type that normally has member functions as well as member variables.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
20
A C++ structure,or struct,like the C++ array,is a homogeneous data structure.(i.e. ,all data is of the same type)
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
21
What is the reason for separating the interface from the implementation of an ADT?
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
22
The scope resolution operator can be used with an object to qualify a member function.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
23
Here are several different initializations of a structure variable.State what happens in each initialization.
struct WeatherData
{
int temperature;
int windChill;
int windSpeed;
};
a)WeatherData prediction ={ };
b)WeatherData prediction ={40};
c)WeatherData prediction ={40,-10,};
d)x WeatherData prediction ={40,-10,20 };
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
24
What is the error in the following structure definition?
struct A
{
int b;
int c;
}
int main()
{
A x;
// other code
}
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
25
In the structure definition
struct StudentRecord
{
int studentID;
char grade;
}
give the structure tag,and each of the member names.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
26
C++ allows the programmer to deal with data at a higher level of abstraction in part because related data of differing types can be treated as a unit in

A)a array variable
B)a structure variable
C)a function
D)a library
E)a class variable
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
27
The dot operator is used between an object and a data member or between a calling object and a call to a member function from the class of the object.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
28
Given the ShoeType structure type-definition.Write a function for the declaration (prototype).
struct ShoeType
{
char style;
double price;
};
void setSalePrice(ShoeType& Item,double discountRate);
//discountRate =(discounted price)/(regular price)
//Adjusts sale price to reflect the specified discount.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
29
Carefully distinguish between the scope resolution operator,and the dot operator.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
30
It seems that mutator and accessor functions defeat the purpose of making the member variables private.Why is this not so?
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
31
Carefully define mutator and accessor functions of a class.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
32
Given the ShoeType structure type definition.Write a function for the declaration (prototype).
struct ShoeType
{
char style;
double price;
};
void readShoeRecord(ShoeType& Item);
// Prompts for data and fills ShoeType argument members
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
33
What is the output of the following program.?
#include
using namespace std;
struct ShoeType
{
char style;
double price;
};
int main()
{
ShoeType shoe1,shoe2;
shoe1.style = 'P';
shoe1.price = 98.98;
cout << shoe1.style << " $" << shoe1.price << endl;
shoe2 = shoe1;
//Put shoe2 on sale!
shoe2.price = shoe1.price/2;
cout << shoe2.style << " $" << shoe2.price << endl;
}
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
34
Write a definition for a structure type for personnel records for hourly employees.The record contains an hourly wage rate,accrued vacation in an integer number of days,and employee status (use 'T' for temporary and 'P' for permanent).Part of the problem is appropriate choices of type and member names.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
35
Carefully identify,define each term and give differences between the implementation and the interface of an abstract data type (ADT).This requires a bit more writing of English than other question on this test.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
36
A member of a structure or of a class is accessed using the

A)Comma operator
B)The dot operator
C)The indexing operator
D)The ampersand operator
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
37
Given the ShoeType structure type definition,write a function declaration (prototype)for a void function that uses a ShoeType structure variable as a value parameter.
struct ShoeType
{
char style;
double price;
};
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 37 flashcards in this deck.