SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Introduction To Computers And C++ Programming
Exercise:
Programming Projects
Question:6 | ISBN:9780321531346 | Edition: 7

Question

The purpose of this exercise is to produce a catalog of typical syntax errors and error messages that will be encountered by a beginner, and to continue acquainting you with the programming environment. This exercise should leave you with a knowledge of what error to look for when given any of a number of common error messages. Your instructor may have a program for you to use for this exercise. If not,you should use a program from one of the previous Programming Projects.

Deliberately introduce errors to the program, compile, record the error and the error message, fix the error, compile again (to be sure you have the program corrected), then introduce another error. Keep the catalog of errors and add program errors and messages to it as you continue through this course.

The sequence of suggested errors to introduce is:

a. Put an extra space between the < and the iostream file name.

b. Omit one of the < or > symbols in the include directive.

c. Omit the int from int main().

d. Omit or misspell the word main.

e. Omit one of the (), then omit both the ().

f. Continue in this fashion, deliberately misspelling identifiers (cout,cin, and so on).

Omit one or both of the << in the cout statement; leave off the ending curly brace }.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

 

a)

Consider the following statement: "Put an extra space between the < and the iostream file name"

The sample C++ code for the above statement is:

#include<  iostream>
using namespace std;
int main()
{
     cout<<"Testing:"<<endl;
}

The above program cod e is executed perfectly after provide an extra space between the < and the iostream file name.. So, Its a valid statement.

b)

Consider the following statement: "Omit one of the < or > symbols in the include directive."

The sample C++ code for the above statement is:

#include iostream
using namespace std;     
int main()
{
 cout<<"Testing:"<<endl;
}

Compiler error occured due to omit one of the < or > symbols in the include directive. So, it is an error invalid statement.

c)

Consider the following statement: "  Omit the int from int main().".

The sample C++ code for the above statement is:

#include<iostream>
using namespace std;
main()
{
  cout<<"Testing:"<<endl;
} 

This program displays a warrning message as return type expected.   

d)

Consider the following statement: " Omit or misspell the word main."

The sample example code for the above statement is:

mnia()
{
  cout<<"Testing:"<<endl;
   return 0;
}

This program code displays "Unsolved external symbol" message.

e)

Consider the following statement: " Omit one of the (), then omit both the ()"

The sample example code for the above statement is:

#include<iostream>
using namespace std;
int main 
{
   cout<<"Testing:"<<endl;
   return 0;
}

This program code displays the main looks like a function.

f)

Consider the following statement: " 

Continue in this fashion, deliberately misspelling identifiers (cout,cin, and so on). Omit one or both of the << in the cout statement; leave off the ending curly brace }"

The sample example code for the above statement is:

#include<iostream>
using namespace std;
int main
{
   out<<"Testing:"<<endl;
   return 0;
}

This program displays Out undeclared identifier message.

0 0

Discussions

Post the discussion to improve the above solution.