Showing posts with label Unit 2. Show all posts
Showing posts with label Unit 2. Show all posts

Unit 2 - Basic Input, Output and Format Code

Posted on Friday, May 7, 2010 by B[H] | 0 comments
Labels:

In the iostream C++ library, standard input and output operations for a program are supported by two data streams:

a. cin (console input) for input – normally assigned to the keyboard
b. cout (console input) for output – normally directed to the screen.

By handling these two streams you will be able to interact with the user in your programs since you will be able to show messages in the screen and to receive his/her input from the keyboard.

1- Output (cout )

The function cout is used with the overloaded operator << (a pair of “less than” signs). It follows the following format as in the following examples: Photobucket

2.Input ( cin )

Handling the standard input in C++ is done by applying the overloaded operator of extraction ( >> ) on the cin stream, followed by the variable that will store the data that is going to be read. It follows the following format:
Photobucket


3-Format Code ( Backslash Character Constant)

The backslash character constant is also known as the ‘Escape Sequence’. Certain characters such as the backspace and carriage return are not printable characters and these characters pose special problems when printing using text editor. The backslash character constant is used together with other character constant when such problems are encountered.

Photobucket

Photobucket

This example shows the use of the new line (\n) character constant to print characters on the next line.

Unit 2 - C ++ Program Characteristics

Posted on by B[H] | 0 comments
Labels:

Let us examine the program in detail. C++ program is made of a few components. They are:

1-Comments

Comments are used to insert remarks into the source code help to explain about what the program does. In C++, comments can be place anywhere in the programs. It can be used to include the details of the project and the programmer who wrote or modified the code.
There are two types of comment used. They are:

a. Multi-line Comment

This type of comment is begins with a /* (slash followed by an asterisk) symbol and ended with a */ (asterisk followed by an slash) symbol.

This type of comment is good to be used when comments written are longer than 1 line.

Example:
/* This is a program that computes the sum of two integer
numbers */



b. Single line Comment

This type of comment is used with the // (double slash) symbol and it stops at the end of that particular line.
This type of comment can be used when the remark is only 1 line in length.

Example:

// This is a preprocessor



2- Header Files

Header files contain information that is required to run a program. It is a pre written and tested function that comes together with the compiler and is available for the use of the programmers. The format or structure for using the header file is by using the #include directive. The second line in our program 2.1 #include is called an include preprocessor directive. As the file is placed before program the program proper , it is called a header file (with the file extension .h)

Example :
Photobucket



3-Functions

A function is a block of statements that is part of a large programme.

a. Function main( )

A C++ program must have at least the function main( ). Every C++ function, including main( ), must have a body enclosed in braces { }.

b. Function block { }

The function body, also called block can be of any size. The function always ends with the return command.

{ - begin block

} - end block


Example:

main ( )
{

}

Unit 2 - Introduction to C++ program

Posted on by B[H] | 0 comments
Labels:

Getting Started : Example of C++ program


To make C++ work for you, you must be able to write C++ program. To give C++ instructions to a computer, you will need and editor and a C++ compiler. An editor lets you type a C++ program, make changes and save it in a file. The compiler then translate your C++ program into a form that your computer can read. Then finally, you will be able to run your program.
To get started, we introduce in this chapter a simple C++ program and then go on to briefly explain the various parts that make up a C++ program.





Unit 2 - Introduction To The Concept And Basic Instruction Of Programming C++

Posted on by B[H] | 0 comments
Labels:

General Objective : To know the characteristics and using instructions of
C++ program basic language

Specific Objectives : At the end of the unit you will be able to :

- state what is the header file.

- state what is the statement ‘main ( )’.

- state and write comment line using backslash symbol

- define the function of input and output statement