Revised: February 3, 2007
By Richard G. Baldwin
File Pfsg00130.htm
Practice Text Index
The practice tests in this series were written specifically for the benefit of my students in COSC 1315, Fundamentals of Programming. They consists of questions, answers, and explanations. The questions are based on the material covered in my series of online lecture notes for the course. Each practice test is keyed to a specific lecture. This practice test is keyed to lecture #130 titled Standard Input.
Enter three values separated by spaces 1 2 3
What output is produced by the program?
#include <iostream> using namespace std; class Input01{ public: static void classMain(){ //Instantiate an object in dynamic memory // and save its reference in a pointer // variable. Input01* ptrToObject = new Input01(); //Invoke an instance function on the object. ptrToObject -> doSomething(); }//End classMain function //-------------------------------------------// //An instance function of the Input01 class void doSomething(){ int first; int second; int third; //Display a prompt cout << "Enter three values separated by"; cout << " spaces\n"; //Get three input values. cin >> first >> second >> third; //Display the three input values cout << first << " " << second << " "; cout << third << endl; }//end doSomething function };//End Input01 class //---------------------------------------------// int main(){ Input01::classMain(); return 0; }//end main |
130-2. Assume that the user executes the program shown in Listing 130-2 and enters the three values shown below when prompted to do so by the program:
Enter three values separated by spaces 4 5 6
What output is produced by the program?
#include <iostream> using namespace std; class Input01{ public: static void classMain(){ //Instantiate an object in dynamic memory // and save its reference in a pointer // variable. Input01* ptrToObject = new Input01(); //Invoke an instance function on the object. ptrToObject -> doSomething(); }//End classMain function //-------------------------------------------// //An instance function of the Input01 class void doSomething(){ int first; int second; int third; //Display a prompt cout << "Enter three values separated by"; cout << " spaces\n"; //Get three input values. cin >> first; cin >> second; cin >> third; //Display the three input values cout << first << " " << second << " "; cout << third << endl; }//end doSomething function };//End Input01 class //---------------------------------------------// int main(){ Input01::classMain(); return 0; }//end main |
130-3. Assume that the user executes the program shown in Listing 130-3 and enters the three values shown below when prompted to do so by the program:
Enter three values separated by spaces 1 1.5 2
What output is produced by the program?
#include <iostream> using namespace std; class Input01{ public: static void classMain(){ //Instantiate an object in dynamic memory // and save its reference in a pointer // variable. Input01* ptrToObject = new Input01(); //Invoke an instance function on the object. ptrToObject -> doSomething(); }//End classMain function //-------------------------------------------// //An instance function of the Input01 class void doSomething(){ int first; int second; int third; //Display a prompt cout << "Enter three values separated by"; cout << " spaces\n"; //Get three input values. cin >> first; cin >> second; cin >> third; //Display the three input values cout << first << " " << second << " "; cout << third << endl; }//end doSomething function };//End Input01 class //---------------------------------------------// int main(){ Input01::classMain(); return 0; }//end main |
130-4. True or False. The cout object provides a program input capability.
130-5. True or False. The pair of right angle brackets (>>) taken together and shown in Listing 130-5 are commonly known as the insertion operator.
Listing 130-5.
cin >> first; |
130-6. True or False. The pairs of left angle brackets (<<) taken together and shown in Listing 130-6 are commonly know as extraction operators.
Listing 130-6.
cout << first << " " << second << " "; |
Richard has participated in numerous consulting projects involving Java, XML, or a combination of the two. He frequently provides onsite Java and/or XML training at the high-tech companies located in and around Austin, Texas. He is the author of Baldwin's Java Programming Tutorials, which has gained a worldwide following among experienced and aspiring Java programmers. He has also published articles on Java Programming in Java Pro magazine.
Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems.
Richard has participated in numerous consulting projects involving Java, XML, or a combination of the two. He frequently provides onsite Java and/or XML training at the high-tech companies located in and around Austin, Texas. He is the author of Baldwin's Java Programming Tutorials, which has gained a worldwide following among experienced and aspiring Java programmers. He has also published articles on Java Programming in Java Pro magazine.
Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems.
-end-