Richard G Baldwin (512) 223-4758

Sample Test #1, CIS2204, Summer 1997

The following problems are of the type, style, and general complexity 
that you can expect to find on your first exam.  However, they may not 
be in the same specification format.  You should study them carefully.  
It is especially important that you pay attention to key terms such as 
public, private, parameterized, returns, etc.  If you dont understand 
the terminology, you wont understand the program specifications on the 
exam, and you cannot possibly do well.  After studying your textbook if 
there are still terms that are not clear to you. please let me know.  I 
will attempt to define or explain the terms for the benefit of you and 
the remainder of the class.

Although this sample test is fairly comprehensive in terms of topics 
covered, it is not exhaustive.  The fact that a topic does not appear on 
this sample test does not mean that it will not appear on the 
examination.

When the problem requests a termination message, that simply means that 
you should display a message on the screen indicating that the program 
has terminated, such as "bye".
***********************************************************************

/*Sample problem #1	samp01.cpp
Using cin and cout, write a program that requests a float value
from the keyboard, and then displays that value multiplied by 2.

Provide a termination message. Display your name on the screen.
*******************************************************************/


/*Sample problem #2	samp02.cpp
Using cin and cout, write a program that converts feet to miles.
Prompt the user for feet and display the equivalent number of
miles as a float.  Repeat the process until the user enters 0
(zero) for the number of feet.  (There are 5,280 feet in a mile.)

Make your program support floating input and output.

Put your name on the screen and display a terminating message.
***********************************************************************/


/*Sample problem #3	samp03.cpp
Rewrite the following C program so that it uses C++ style
I/O statements (cin and cout).  Be sure to put YOUR name
on the screen and display a termination message.  Don't
worry about matching the number of digits to the right of
the decimal point in the new version.
*/

#include<stdio.h>
//Section 1.2
//Console I/O
void main()
{
  float data;
  printf("Please enter a floating value less than 32,767:  ");
  scanf("%f",&data);
  printf("Twice your value is %f\n", 2*data);

  printf("Baldwin Terminating");
}
/**********************************************************************/



/*Sample problem #4	samp04.cpp
Put YOUR name on the screen and display a terminating message.

Create a class called DATA that can be used to maintain a
library of information about dogs.  Have the class store the
breed, the typical color, the typical weight in pounds, and the
average price.

Store the breed and color as strings up to 20 characters
in length.  Store the weight as an integer and the price as
a float.  Make this data private.

Provide a public member function called SAVE() to store data
into an object of the class and a public member function called
SHOW() to display the private data.

Write a driver program which creates an object of the class,
uses SAVE() to store the following information in the object,
and uses SHOW() to display the data on the screen.

  Collie
  brown
  35
  162.50
***********************************************************************/


/*Sample problem #5	samp05.cpp
Put YOUR name on the screen and display a terminating message.

Create a function named xdouble() that returns twice (as
an integer) its argument.  The argument can be either an
integer or a string consisting of numeric characters only.

Write a driver program which calls the function twice
using the following arguments:

	32
	"16"

and uses cout to display the xdouble of the argument on the screen.

***********************************************************************/


/*Sample problem #6	samp06.cpp
Put YOUR name on the screen and display a terminating message.

Create a class called dogs that can be used to maintain a
library of information about dogs.  Have the class store
the breed, weight, and price of a dog.

Store the breed as a string up to 20 characters in length.
Store the weight and price as floats.  Make this data private.

Provide a public member function called store() to store data
into an object of the class and a public member function called
look() to display the private data.

Provide a parameterized constructor and a destructor for
the class.

Cause the constructor to store the arguments when
an object of the class is declared with arguments for
breed, weight, and price.

Cause the destructor to use cout to display the
string "bye.", on a line by itself.

Write a driver program which creates an object of the class,
with the following arguments:

	Collie
	65
	135

Have the program use look() to display this data.

Then, have the program use store() to store the following
information in the object, and use look() to display the data
on the screen.

	Beagle
	15
	155
***********************************************************************/


/*Sample problem #7	file Samp07.cpp
Put YOUR name on the screen and display a terminating message.

Create a base class called circle that can be used to maintain
the radius of a circle as private float data.

Create two classes which are derived from the circle class.
The two derived classes should be called circumference and area.

Provide a public function called get_area() for the area
class which uses cout to display the area of the circle.

Provide a public function called get_circumference() for the 
circumference class which uses cout to display the circumference of the
circle.

Provide parameterized constructors for the area and circumference
classes which initialize the radius of the circle.

Provide a destructor for the circumference class which displays the
message "No more circle" on a line by itself.

Write a driver program which creates an object of the area
class with argument

	radius = 5

and then calls get_area() to display the area
of the circle.

Then have the driver program create an object of the circumference
class with argument

	radius = 6

and call get_circumference() to display the circumference of the circle.
***********************************************************************/


/*Sample problem # 8	file samp08.cpp
Put YOUR name on the screen and display a terminating message.

Create a class named HORSE containing a private variable
named SHEEP and two public functions.  One of the functions is
a constructor and the other, named GetSheep(), returns the value
of SHEEP.

Parameterize the constructor so that it receives one
floating argument and assigns it to the variable named SHEEP.

Write a driver program that declares an object named FARM
of the class HORSE with an argument of 25.6.

Have the program also declare a pointer to type HORSE, and
assign the address of FARM to the pointer.

Using cout, display the value of SHEEP using the object with
dot notation.

Using cout again, display the value of SHEEP using the pointer.
**********************************************************************/


/*Sample Problem #9	file samp09.cpp
Put YOUR name on the screen and display a terminating message.

Create a class named PIG containing a private variable
named COW and three public functions.  One of the functions is
a constructor.  The second public function, named GetCow(),
returns the value of COW.  The third public function is a
destructor which displays the following string on a separate
line:  "No More Cow"

Parameterize the constructor so that it receives one
char argument and assigns it to the variable named COW.

Write a driver program that declares an object named BIRD
of the class PIG with an argument of 'Z'.

Using cout, display the value of COW using the public
member function of the object.

Make all three of the public functions into in-line functions.
***********************************************************************/


/*Sample problem #10	file samp10.cpp
Put YOUR name on the screen and display a terminating message.

The following program may not compile and run properly.  If
not, show what can be done, WITHOUT modifying the statement
which reads "obj2 = obj1", to correct the problem.  Modify the
program to make it compile and run properly.  Also, explain in
the space below why it was necessary for you to change the
program, if it was necessary.

___________________________________________________________ 

#include<iostream.h>
class CITY{
	int STREET, ROAD;
public:
	void set(int CANINE, int FELINE){STREET = CANINE; ROAD = FELINE;}
	void show() {cout << STREET << ' ' << ROAD << '\n'; }
}; //end CITY

class COUNTY{
	int STREET, ROAD;
public:
	void set(int CANINE, int FELINE){STREET = CANINE; ROAD = FELINE;}
	void show() {cout << STREET << ' ' << ROAD << '\n'; }
}; //end COUNTY


main()
{
	CITY obj1;
	COUNTY obj2;
	obj1.set(15, 20);
	obj2 = obj1;
	obj1.show();
	obj2.show();
	cout << "Terminating, Dick Baldwin\n";
  return 0;
}//end main()	


END COMMENTS
***********************************************************************/


/*Sample program #11	file samp11.cpp
Put YOUR name on the screen and display a terminating message.

Create a class named Honda which contains one float data
member named Accord.

The class also contains three public member functions.

The public function named put() is used to assign a value to
Accord.

The public function named display() is used to display the value
of Accord.

The third public member function is a destructor which displays
the message "No more object."

Use automatic in-lining for all three public functions.

Provide a main() function which creates an object of
type Honda, sets the value of Accord to 51.6, and displays
the value of Accord.

After this, the main() function passes the object to another
function of your own design which changes the value of Accord
to 156.3 returning nothing to main().

Upon return, main() once again displays the value of Accord
which has now been changed to 156.3.

**********************************************************************/


/*Sample problem #12	file samp12.cpp
Put YOUR name on the screen and display a terminating message.

Create a class named HONDA which contains one data member
which is a char array, 81 characters in length, named CRX.

The class also contains four public member functions.

The public function named PUT() is used to store a string in
CRX.

The public function named DISPLAY() is used to display the string
in CRX.

The third public member function is a destructor which displays
the message "Destroying the object."

The fourth public member function is a constructor which
initializes CRX to the string "Starting with nothing".

Use automatic in-lining for all public functions.

Provide a main() function which creates an object, named CAR,
of type HONDA, and displays the value of CRX contained in
CAR immediately following creation.

After this, the main() function calls another function
of your own design which returns an object of type HONDA
in which the value of CRX has been set to the string
"Now we have an auto".  The object which is returned is
assigned to CAR in main and the value of CRX in CAR is
displayed again.
***********************************************************************/


/*Sample problem #13	file samp13.cpp
Put YOUR name on the screen and display a terminating message.

Create a class named HONDA which contains one private data member
which is a char array, 81 characters in length, named ACCORD.

The class contains three public member functions.

The public function named SHOW() is used to display the string
in ACCORD.

The second public member function is a destructor which displays
the message "Destroying the object."

The third public member function is a constructor which
initializes ACCORD to the string "Empty".

Use automatic in-lining for all public functions.

Provide a main() function which creates an object, named CAR,
of type HONDA, and displays the value of ACCORD contained in
CAR immediately following creation.

After this, the main() function passes CAR to another function
of your own design which stores the following string in ACCORD:
"Now we have an auto".

Note that the class does NOT contain a public member function
which can be used to store a string in the private member ACCORD.

The function returns nothing.

The value of ACCORD in CAR is displayed again upon return from
the function.
***********************************************************************/

-end of sample test -.

