COSC 1315

Programming Fundamentals

 Practice Text #130

Standard Input

Revised: February 3, 2007
By Richard G. Baldwin

File Pfsg00130.htm
Practice Text Index


Welcome

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.

Questions



130-1.  Assume that the user executes the program shown in Listing 130-1 and enters the three values shown below when prompted to do so by the program:

Enter three values separated by spaces
1 2 3

What output is produced by the program?

Listing 130-1.
#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

Answer and Explanation

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?

Listing 130-2.
#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

Answer and Explanation

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?

Listing 130-3.
#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

Answer and Explanation

130-4.  True or False.  The cout object provides a program input capability.

Answer and Explanation

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;

Answer and Explanation

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 << " ";

Answer and Explanation



Copyright 2007, Richard G. Baldwin.  Reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.

About the author

Richard Baldwin is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a combination of Java and XML. In addition to the many platform-independent benefits of Java applications, he believes that a combination of Java and XML will become the primary driving force in the delivery of structured information on the Web.

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.

Baldwin@DickBaldwin.com


Answers and Explanations

Answer 6

False

Back to Question 6

Explanation 6

Answer 5

False

Back to Question 5

Explanation 5

Answer 4

False

Back to Question 4

Explanation 4

Answer 3

D.  None of the above.

Back to Question 3

Explanation 3

Answer 2

C.  4 5 6

Back to Question 2

Explanation 2

Answer 1

C.  1 2 3

Back to Question 1

Explanation 1



Copyright 2007, Richard G. Baldwin.  Reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.

About the author

Richard Baldwin is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a combination of Java and XML. In addition to the many platform-independent benefits of Java applications, he believes that a combination of Java and XML will become the primary driving force in the delivery of structured information on the Web.

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.

Baldwin@DickBaldwin.com

-end-