Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. (Multiple choice) Consider the following structure type definition and variab

ID: 3637288 • Letter: 1

Question


1. (Multiple choice)

Consider the following structure type definition and variable
declaration:

struct LetterGrade
{
char letter;
char sign;
};

LetterGrade exam = { 'B', ' ' };

Which code uses correct syntax to access a structure member *and*
increases the exam score one whole letter grade.

a. letter(exam) = 'C';

b. exam.letter--;

c. LetterGrade.sign = '+';

d. letter.sign++;


------
Use the following code to answer the next 4 questions. The
code includes a class definition, and just one member function
definition.

class Dimensions
{
public:
// Sets length and width.
void set(double newLen, double newWidth);

// Returns length portion.
double length();

// Returns width portion.
double width();

// Returns area based on dimensions.
double area();

// Sets the dimensions to zeros.
void clear();

private:
// Which dimension stored as len or width is arbitrary.
double lenDim;
double widthDim;
};

void Dimensions::set(double newLen, double newWidth)
{
lenDim = newLen;
widthDim = newWidth;
}


2. (Matching)

Match each identifier to its role in the C++ code.

For matching questions, always list your answers in the order in
which you would fill in the blanks.

___ length a. mutator

___ widthDim b. accessor

___ clear c. data type

___ Dimensions d. data member


3. (Short answer)

Label each of the following pieces of code (copied from above) as
being either part of the interface or implementation of the class.
Write "interface" or "implementation".

a. void Dimensions::set(double newLen, double newWidth)
{
lenDim = newLen;
widthDim = newWidth;
}

b. // Which dimension stored as len or width is arbitrary.

c. double area();

d. double lenDim;


4. (True/false)

The following syntax can be used to initialize a Dimensions object:

Dimensions dims1 = { 10.5, 20.0 };


5. (Code)

Write down a *definition* for member function "clear" that makes
both dimensions zero. I.e., write the function definition in C++.

------

6. (Fill-in-the-blanks)

Fill in the following paragraph with the terms: class, interface,
abstract data type, and implementation.

To know how to use a(n) _______ representing a bank account, you
simply need to know it allows the user to deposit and withdraw money.

In C++, that account could be encapsulated using a(n) _______ named
BankAccount. In the "public" part of BankAccount, 2 mutators are needed,
forming the _______ of the account. Within the "deposit" mutator, it
actually uses the "+=" operator, but that is a detail of _______.


7. (Short essay)

Compare and contrast structures and classes in C++. I.e., start off
by summarizing how they are the same, then highlight some important
differences.

Explanation / Answer

c. LetterGrade.sign = '+';