A(n) ________ function in C++ reports on the content (or part of the content) of an object. In other words, it can return information based on the values of data member(s), but does not change the object in any way.

A(n) ________ is a data structure that is a general container for objects. Objects enter at the back, and exit from the front, being processed in order.

What is an in-line function definition? Under what circumstances is one usually used?

 

Valid / Invalid

int Exercise17 (int &A, int &B); // prototype

double do_stuff(int param1 = 1, double param2 = 2.0); // a prototype

...

For questions 16-17, using the following function heading from the Junk class:

int Jeez2 (int a, int b, double &c); ...

and the following constant and variable declarations in the main program:

Junk z;

int num1 = 0;

int num2 = 1;

double val1 = 0.1;

which function calls are valid? If the function call is invalid, explain why.

17. num3 = z.Jeez2(num1, num2, val1);

 

Use the following class definition for the questions x-x+10.

class Thing {

public:

Thing();

Thing(Thing orig);

int GetVal();

void SetVal(int val);

private:

int Value;

};

 

VI#CL

. // client code using Thing class defined above

Thing X(4);

 

Doing and Understanding:

(3 points)

USEDF98mt2 30. What is the output of the following code?

int Junk (int a, int b) {

cout << "A" << endl;

return (a - b);

}

int Junk (int a) {

cout << "B" << endl;

return (a + a);

}

int main() {

int y = 9;

int z = 5;

int x = Junk(y,z);

cout << x << endl;

int x = Junk(z);

cout << x << endl;

}

 

 

 

 

Writing Code

(points as shown)

Given the attached Card, Deck, and Player class definitions:

If the game was to be played with each player using their own deck, write the statements in main to declare and shuffle the decks and declare the two players.

 

(X points) TOO LONG

Assuming that a class called Country has been defined as below, write a main function that 1) declares an array of 200 countries, 2) asks user for country name, population and land area of the country, 3) updates the country objects in the array with this information, and 4) displays the country name and land density for all of the countries.

class Country {

public:

Country(); // default country prototype

Country(string name, int pop, double area); // fully specified country prototype

string GetName(); // report county’s name

int GetPop(); // report country’s population

double GetArea(); // report country’s land area

double GetDensity(); // report country’s population density

void SetName(string nam); // set or change country’s name

void SetPop(int pop); // set or change country’s population

void SetArea(double area); // set or change country’s land area

private:

string cntryName;

int cntryPop;

double cntryArea;

};

 

There’ll be string stuff on the test too (up to what covered on 2/21) – just haven’t generated any string questions yet.