COSC 1315

Programming Fundamentals

 Practice Text #120

Types of Errors

Revised: February 3, 2007
By Richard G. Baldwin

File Pfsg00120.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 #120 titled Types of Errors.

Questions



120-1.  True or False.  There are basically four types of errors that you must contend with when writing computer programs:

Answer and Explanation

120-2.  True or False.  syntax errors represent grammar errors in the use of the programming language.

Answer and Explanation

120-3.  True or False.  Runtime errors occur when a program with no syntax errors asks the computer to do something that the computer is unable to reliably do.

Answer and Explanation

120-4.  True or False.  Logic errors occur when there is a design flaw in your program causing the program to behave differently from the way it was intended to behave.

Answer and Explanation

120-5.  What output is produced by the program shown in Listing 120-5?

Listing 120-5.
#include <iostream>
using namespace std;

class Errors01{ 
  public:
  static void classMain(){
    //Instantiate an object of the Errors01 class 
    // and save its reference in a pointer 
    // variable.
    Errors01* ptrToObject = new Errors01();
    //Now invoke the instance function named 
    // doSomething belonging to the object.
    ptrToObject.doSomething();
  }//End classMain function
  //-------------------------------------------//

  //An instance function of the Errors01 class
  void doSomething(){
    cout << "Hello World\n";
  }//end doSomething function
};//End Errors01 class
//---------------------------------------------//

int main(){
  Errors01::classMain();
  return 0;
}//end main

Answer and Explanation

120-6.  What output is produced by the program shown in Listing 120-6?

Listing 120-6.
#include <iostream>
using namespace std;

class Errors02{ 
  public:
  static void classMain(){
    //Instantiate an object of the Errors02 class 
    // and save its reference in a pointer 
    // variable.
    Errors02* ptrToObject = new Errors02();
    //Now invoke the instance function named 
    // doSomething belonging to the object.
    ptrToObject -> doSomething();

  }//End classMain function
  //-------------------------------------------//

  //An instance function of the Errors02 class
  void doSomething(){
    int temp1;
    int temp2;
    temp1 = 6;
    temp2 = 0;
    cout << temp1/temp2 << endl;
  }//end doSomething function
};//End Errors02 class
//---------------------------------------------//

int main(){
  Errors02::classMain();
  return 0;
}//end main

Answer and Explanation

120-7.  The program shown in Listing 120-7 was intended to display the following text on the screen:

Hello World

What output is produced by the program shown in Listing 120-7?

Listing 120-7.
#include <iostream>
using namespace std;

class Errors03{ 
  public:
  static void classMain(){
    //Instantiate an object in dynamic memory
    // and save its reference in a pointer 
    // variable.
    Errors03* ptrToObject = new Errors03();

    //Invoke an instance function on the object.
    ptrToObject -> doSomething();
  }//End classMain function
  //-------------------------------------------//

  //An instance function of the Errors03 class
  void doSomething(){
    cout << "Goodbye Cruel World\n";
  }//end doSomething function
};//End Errors03 class
//---------------------------------------------//

int main(){
  Errors03::classMain();
  return 0;
}//end main

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 7

C.  Logic Error (Goodbye Cruel World)

Back to Question 7

Explanation 7

Answer 6

B.  Runtime Error

Back to Question 6

Explanation 6

Divide by zero error.

Answer 5

A.  Compiler Error

Back to Question 5

Explanation 5

Uses a dot operator (.) when the pointer-to-member operator (->) must be used instead.

Answer 4

True

Back to Question 4

Explanation 4

Answer 3

True

Back to Question 3

Explanation 3

Answer 2

True

Back to Question 2

Explanation 2

Answer 1

False

Back to Question 1

Explanation 1

Careless errors can result in any of the three major types of errors.  Therefore, I don't consider them to be in a category all their own.



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-