Revised: February 3, 2007
By Richard G. Baldwin
File Pfsg00120.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 #120 titled Types of Errors.
120-2. True or False. syntax errors represent grammar errors in the use of the programming language.
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.
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.
120-5. What output is produced by the program shown in 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 |
120-6. What output is produced by the program shown in 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 |
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?
#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 |
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.
Divide by zero error.
Uses a dot operator (.) when the pointer-to-member operator (->) must be used instead.
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.
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-