Richard G Baldwin (512) 223-4758
 
SampleTest #3, CIS2204, Summer 1997 
 
The following problems are of the type, style, and general complexity  
that you can expect to find on your third exam.  However, the  
specification format may be different.  You should study them carefully.   
As explained in the preface to the first sample test, 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 real  
examination. 
======================================================================= 
 
 
/*CIS2204 Sample problem #26 
Put YOUR name on the screen and display a terminating message. 
 
Write a program which uses cout to prompt the user to enter 
a group of characters, uses cin to read the characters 
from the keyboard, and then uses cout to display the characters on 
the screen as a series of octal values. 
 
To confirm proper operation of the program, make certain that a 
lower case "j" displays as 0152. 
*/ 
 
 
 
 
/*CIS2204 Sample problem #27 
Put YOUR name on the screen and display a terminating message. 
 
Write a program which computes and uses cout to display 
a three-column table containing n, 2.5^n, and the fourth root 
of 2.5^n for 
 
	1 <= n <= 5 
 
The terminology 2.5^n means 2.5 raised to the nth power. 
 
Make the field width 11 columns. 
Set the precision to 5 digits to the right of the decimal 
	point. 
Force the values to display up to five zeros to the 
	right of the decimal point even if the value is a 
	whole number. 
*/ 
 
 
 
 
/*CIS2204 Sample problem #28 
Put YOUR name on the screen and display a terminating message. 
 
Create a class named data which begins as follows: 
 
class data { 
	char first[21]; 
	char last[21]; 
	int age; 
... 
... 
... 
}; //end class definition 
 
 
Add the necessary member functions, so that the following main() 
function will compile successfully and display the following 
line of text on the screen followed by a termination message. 
 
Dick Baldwin 58 
 
 
 
main() 
{ 
	data obj("Dick","Baldwin",58); 
	cout << obj; 
 
	cout << "\nTerminating, Dick Baldwin\n"; 
  return 0; 
}//end main() 
 
END COMMENTS 
*/ 
 
 
 
 
/*CIS2204 Sample program #29 
Put YOUR name on the screen and display a terminating message. 
 
Create a class named data which begins as follows: 
 
class data { 
	char first[21]; 
	char last[21]; 
	int age; 
... 
... 
... 
}; //end class definition 
 
 
Add the necessary member functions, such that the following 
main() function will run and ask you to enter your 
first name, last name, and age, and will then display 
them on a single line. 
 
 
main() 
{ 
	data obj; 
	cin >> obj; 
	cout << obj; 
 
	cout << "\nTerminating, Dick Baldwin\n"; 
  return 0; 
}//end main() 
 
 
END COMMENTS 
*/ 
 
 
 
 
/*CIS2204 Sample program #30 
Create an I/O manipulator named MyManipulator which will display 
the following information on the screen: 
 
This is my manipulator 
 
when included in the following statement in your program: 
 
	cout << MyManipulator; 
 
*/ 
 
 
 
 
/*CIS2204 Sample problem #31 
Put YOUR name on the screen and display a terminating message. 
 
DO NOT include stdio.h in your program.  Include iostream.h 
instead. 
 
Write a program which uses cout to prompt the user to enter 
the following string from the keyboard: 
 
	"My String" 
 
The program then reads the string from the keyboard and uses 
cout to display the characters on the screen. 
*/ 
 
 
 
 
/*CIS2204 Sample problem #32 
Put YOUR name on the screen and display a terminating message. 
 
Fill in the missing code to create a pure virtual function 
which is overridden in two derived classes named feet and 
yards so that the following main() program will execute 
properly to convert inches to (feet and inches) in one case 
and to (yards and inches) in the second case. 
 
The program should display the following: 
 
		26 inches represents: 2 feet and 2 inches 
		40 inches represents: 1 yard and 4 inches 
 
 
#include<iostream.h> 
class length{  //this is a base class 
public: 
	int inches; 
	... 
	... 
	... 
}; 
 
class feet : public length {  //derived class 
public: 
	feet(int x) : length(x) {}  //constructor 
	... 
	... 
  ... 
}; 
 
class yards : public length {  //derived class 
public: 
	yards(int x) : length(x) {}  //constructor 
	... 
	... 
  ... 
}; 
 
main() 
{ 
	length *pFeet, *pYards;//create pointers of type length 
	feet FeetObj(26);      //create and initialize object 
	yards YardObj(40);     //create and initialize object 
 
	pFeet = &FeetObj;    //assign address to pointer variable 
	pFeet->GetLength();  //call feet's GetLength 
 
	pYards = &YardObj;    //assign address to pointer variable 
	pYards->GetLength();  //call yards' GetLength 
 
	cout << "\nBaldwin terminating"; 
	return 0; 
} //end main() 
 
END COMMENTS 
*/ 
 
 
 
 
/*CIS2204 Sample problem #33 
Put YOUR name on the screen and display a terminating message. 
 
Without using explicit function overloading, write a single 
function named SqRt() which will compute and display the 
square root of its single argument, and which will run 
successfully with the following main() function. 
 
The program should display the following: 
	The square root of 5 is 2.236068 
	The square root of 3.14 is 1.772005 
 
 
#include<iostream.h> 
#include <math.h> 
 
//Put your one function named SqRt here. 
... 
... 
... 
 
main() 
{ 
	int abc = 5;       //declare an integer variable 
	float def = 3.14;  //declare a float variable 
 
	SqRt(abc);  //pass the integer value to the function 
	SqRt(def);  //pass the float value to the function 
 
	cout << "\nBaldwin terminating"; 
	return 0; 
} //end main() 
 
 
 
END COMMENTS 
*/ 
 
 
 
 
/*CIS2204 Sample program #34 
Put YOUR name on the screen and display a terminating message. 
 
Create a class named GenClass.	The class has a single 
private data member named data and two public member 
functions named sqr() and put().  put() is used 
to store a data value in the data member.  sqr() is used 
to compute and display the square of the value stored in 
the data member. 
 
The class must work properly with the following main() 
function.  When executed, the program should display 
the following: 
	The square of 1.414214 is 2 
	The square of 6 is 36 
 
 
 
#include<iostream.h> 
#include <math.h> 
 
//Put your class definition here. 
... 
... 
... 
 
main() 
{ 
	GenClass<float> FloatObj;  //Create float object 
	GenClass<int> IntObj;      //Create integer object 
 
	FloatObj.put(sqrt(2.0));//Put data in float object 
	FloatObj.sqr();     //Square and display it 
 
	IntObj.put(5);     //Put data in integer object 
	IntObj.sqr();       //Square and display it 
 
	cout << "\nBaldwin terminating"; 
	return 0; 
} //end main() 
 
 
END COMMENTS 
*/ 
 
 
 
 
/*CIS2204 Sample problem #35 
Put YOUR name on the screen and display a terminating message. 
 
Create a class named aClass.	The class has a single 
private data member named data and two public member 
functions named PutData() and GetData().  PutData() is used 
to store a data value in the data member.  GetData() is used 
to display the value stored in the data member. 
 
The class must work properly with the following main() 
function.  When executed, the program should display 
the following: 
	Value stored in Obj1.data is 234 
	Store 32 in Obj2.data. 
	Examine the data in Obj1 again. 
	Value stored in Obj1.data is now 32 
	Oops, how did it change? 
 
 
#include<iostream.h> 
 
//Put your class definition here. 
... 
... 
... 
 
main() 
{ 
 
	aClass Obj1, Obj2; //create two objects of type aClass 
	Obj1.PutData(234);  //store 234 in Obj1 
	cout << "Value stored in Obj1.data is "; 
	Obj1.GetData();     //display current value in Obj1 
	cout << "\nStore 32 in Obj2.data.\n"; 
	Obj2.PutData(32);   //store 32 in Obj2 
	cout << "Examine the data in Obj1 again.\n"; 
	cout << "Value stored in Obj1.data is now "; 
	Obj1.GetData();     //display current value in Obj1 again 
	cout << "\nOops, how did it change?\n"; 
 
	cout << "\n\nBaldwin terminating"; 
	return 0; 
} //end main() 
 
 
END COMMENTS 
*/ 
 
 
 
 
/*CIS2204 Sample problem #36 
Put YOUR name on the screen and display a terminating message. 
 
Create a class named MyString.	The class has two 
private data members as shown below along with a public 
paramaterized constructor. 
 
Fill in the missing parts so that the class will work 
properly with the following main() function.  When 
executed, the program should display the following: 
	Here is string: A test string. 
	Here is length of string: 14 
 
 
#include<iostream.h> 
#include<string.h> 
 
class MyString { 
	char str[80]; 
	int len; 
... 
... 
... 
};//end class definition 
 
main() 
{ 
	MyString s("A test string.");//create an object 
	char *p;  	//declare a pointer variable 
  int length;	//declare an integer variable 
 
	p = s;      //assign string pointer to p 
	length = s; //assign string length to length 
  //Display string and its length. 
	cout << "Here is string: " << p << '\n'; 
	cout << "Here is length of string: " << length; 
 
	cout << "\n\nBaldwin terminating"; 
	return 0; 
} //end main() 
 
 
 
END COMMENTS 
*/ 
 
 
 
 
-end of sample test -. 

