Open Means Open Means

DATA INPUT AND OUTPUT

No comments on “DATA INPUT AND OUTPUT”
DATA INPUT AND OUTPUT:-  Input /output (I/o) functions are directly performed by C + +. These are the header files which help in performing input/output function. cin and cout functions help in performing input and output activities. Cin and cout remain present in iostream.h header file. # include C + + provides a large variety of functions to deal with characters and input/output operations. These functions are: 1    getchar ( ) 2    putchar ( ) 3    gets ( ) 4    puts ( ) These functions are also termed as unformatted console I/o functions. Character functions getchar ( ) and putchar ( ):- These functions are based on characters for input and output operations.   1. getchar ( ):- The function getchar ( ) reads a single character from the standard input device such as usually a key – board. It is worth noting when getchar is used; the execution of the program is temporarily suspended. When the character is typed by the user from the key-board, then this character is communicated to the program. The suspended execution starts again. No argument s/is/are required in the function because getchar function reads a simple character in given time.  ………….. ………….. char ch; ch = getchar ( ); ………….. ………….. The function char is included in stdio.h header file. Example: Write a small C ++ pgm which illustrates the use of getchar ( ). # include # include main ( ) { char character; cout

Preprocessor Directives

No comments on “Preprocessor Directives”
Preprocessor Directives: The processor directives are the Direction given to the compiler to carry out specific task even before compilation of the program start. Since we are directing the complier to carry out specific task before the compilation process start is refer as preprocessor director eves. The preprocessor directives are not statement of language. This directives starts with #.  The preprocessor directives never end with semicolon. Following are the commonly use predirectives: a )# define: The preprocessor # define is used to declare the symbolic constants.   Consider the following example  # define PI 3.14159 In the above example we define a symbolic constant name as PI whose equivalent value will be 3.14159 with this directives we have informed the compiler that the PI is symbolic constant with it’s own value. Once the compilation of the program start where are the PI occurs in the program, it will be request by it’s equivalent value. b) # include :  The preprocessor directives # include is used to include specific files within program.                There are the may facilities available in the core of C++ language. However, there are many more facilities which are available outside of the core of C + +. This files are called as header files and also called as the library files. Consider the following example: 1.To use the mathematically facilities such as sin ( ), COS ( ), log ( ), sqrt ( ) etc are called as the math h must be included so that if we use any of the above discussed facilities the compilation error will not error and facilities will become accessible. 2 .The scanf ( ) and printf ( ) are the function for reading and displaying data. To use these function are have to include a file called as stdio.h. The corresponding preprocessor directives will be given as follows        . The stdio.h to the standard input output file Once we include file stdio.h we can use scanf ( ) and printf ( ) in our program. 3.The cin ( ) and cout are the object which are used for reading and displaying the data. To use this object we have to include a file called as lostream.h the corresponding preprocessor directives will be given as follows.                                 # include < iostream.h > To isostream h refers to the input output stream header file. Once we include the file iostream.h we can used cin and cout in our program There are few more preprocessor directives used in C + + . Those are instead as follows. # if # else # elif # end if # ifdef # lfndef      

Concept of DataTypes in c++

No comments on “Concept of DataTypes in c++”
Data types In c++: Computer is of various types. It may include integers, characters, string etc. Types of Datatypes: 1.Integers 2.Characters 3.Strings 4.Floating point type 1.Integers: Integers are whole number such as 7, 12, 27, -7, -12, -27 etc. No fraction as part is used in integers. Integers are generally constants. Range of values is -215 to 215 -1 (ie.-32768 to 32768) It also Divide into sub-types i.Unsigned integers      ii.Short integers        iii.Long integers i.Unsigned Integers: Unsigned integers are those non negative whose values varies from 0 to 65535. if we have to use a value of 32770, we have to use unsigned integers because ordinary integer provide a value to 0 maximum 32767. ii.Short Integers: Short integers are those integers having small range of value. The value of this integer varies between  -123 to 127. This type of integers take lesser space for storage. iii.Long Integers: Long integers are having wide range of value. The values varies between – 129467290 to 429467295. Data Type Size Bits Range Integers 16 Bits – 215 to 215–1 (32768 to 32768) Unsigned integers 16 Bits 0 to 216 – 1 (0 to 65535) Short integers 8 Bits – 27 to 27 – 1 (– 128 to 127) Long integers   32 Bits – 232 – 232 – 1 – 4294967296 to 4294967295   2.Character Types: Character (char) Types are one Byte size and character constant varies between  0 to 255. The characters are stored the computer memory as integers. Binary form. Each character is assigned a particular  value according to ASCII codes [ ASCII means – American standard code for information Interchange ] A table of ASCII codes has been provided at the end of the book. It’s worth noting that no computer language can use more than 256 characters [A to Z, numbers, punctuation marks etc], these, character are assigned coding from 0 -255. It also Divide into sub-types i.char ii.Unsigned char iii.Signe char Characters types Size Rank char 1 Byte -27 to 27-1 (-128 to 127) Unsigned Char 1 Byte 0 to 28-1 ( 0 to 255) Signed char 1 Byte -27 to -27-1 ( -128 to 127) Character can be written by writing the character in single quotes.  But some characters are written in C + + program by using Escape, carriage Return, Tab characters C++ compiler recognized these characters for formatting. Escape character ( ) Changes the meaning of the character which Follows it, e.g. The character b indicates the letter b when its preceded by escape character, it means Back space. Character                                          Meaning n                                                       New line t                                                       Horizontal Tab v                                                       Vertical Tab b                                                       Back space \                                                        Back slash ”                                                       Double Quotes ’                                                       Single Quote ?                                                       Question mark   3.String: String is a series of characters. The string is enclosed within double quotes. A string is used to write or store messages. “HELLO” The “HELLO” is string and the characters of string are stored in sequential location. H E L L O Φ         Null character The null character is added at the end of string automatically by the compiler.   Floating point constant(Float data type): A floating point constant may bear +ve or –ve sign. In case of no signed is used, the number is treated as positive. Decimal is number refer that is floating number. Floating form A provides greater range of integers between –ve or +ve. Type of Float Data types: i.Float ii.Double ii.Long Double Type Size Range float 4 Bytes 3.4*10-38 + 03.4*1038 double 8 Bytes 1.4*10-308 + 01.7*10308 long double 10 Bytes 3.4*10-4932 to .4*104932. Some valid floating point constant: 5.0 (with Decimal) + 0 . 1832 (With +ve signed) –12 . 18 (with – ve signed) Invalid floating point constant 1000 ( Decimal Missing ) h (fractional portion is absent) + 20.123 (Both signed not allowed) + 20.123 (Blank space after +ve signed not allowed) – 20.123 (Blank space after –ve signed not allowed) 20, 23.1516 (comma not allowed) 20, 23. 1516 ( Blank space bet digits not allowed) Floating point constants written in this form are called to be in       exponent form (B). notation. This notation is also called standard     form. Standard form 91360000                                9.136 * 106 0.9136                                     9.136 * 10–1 0.00009136                           9.136 * 10-5 Representation in exponent form C + + 9.136 * 106 can written as 9.136 E 6 9.136 * 10–6 can written as 9.136 E –6 9.136 * 106 can be written as 9.136 + 6 9.136 y 106 can be written as 9.136 E 06                    E Left Part           Right part Left part is called Mantissa Right part is call Exponent 9. 136 E is invalid notation because exponent is absent. E 6 is invalid notation because Mantissa is absent. Double Data Type occupied double memory than that of float number with much larger range.                                                          

Variables and cout,cin operator in c++

No comments on “Variables and cout,cin operator in c++”

As the name suggest, a variable is a quantity which varies during  a program execution. In C + +, a variable is 0 location where the information is stored. This location exist in a computer memory where the value information can stored and a case of need it can be retrieved.

Depending upon the size of variable, it can occupy the one more  memory address.

Variable can be change in any combination of letter without spaces.         Variable may be short or descriptive but descriptive variable names makes it easier to understand the flow of program some keyword are          reserved in C + + and cannot be used as variable, name like – if,      while, main for. We can create more than one variable of the same type   in a single stmt this can be done by the following syntax:

Syntax

Type varname, varname;

 eg. int A; here Int is datatype od variable and A is variable name.

 

# include < iostream .h >

main ( )

{

int a, b, sum ;

clrscr( );

cout << “ \ Enter the first number” ;

cin >> a ;

cout << ‘ \ Enter the second number

cin >> b ;

Sum = a + b ;

cout << sum << end 1 ;

return 0 ;

}

Explanation:

1.       A C + + program start with function called main ( ). The body of the function is enclosed between curly bracket ( {} ). A C+ + program consist of as many function as required.

2.       The explanation written after the characters 11 is know as comment, comment play an important role in development of program. In case    comment more than one line, it should be enclosed within symbols /* and */. There should be no space between / and * for example.

/* The program computes the perimeter of trapezium */

3.       The statement in program # include is called include processor Director. “The symbol # is called as hash symbol. The name of the file appears before the start of program is known as header file or hash extension h.

4.       The function cin is called console input its used with redirectional operator >>. It accepts the data from the input unit i.e. keyboard cin >> a ;

When this statement is executed it accepts the value from keyboard.

 

 

5.       The function coat is called consol output. Its used with redirection operator <<. It display the output on the screen

cout << sum << end 1;

When this statement is executed, it displays the value (sum) on the screen end 1; it used to show the end of the line. Its optional to use end 1.

End 1 is manipulator which frequently used. It has same effects as character h / nc1 due to clarity end 1 is preferred.

 

6.       Every statement in C++ should be follow by a semi – colon ( ; ) In case this semi colon is missed, an error message appears.

The cin operator ( >> ) extraction operator:

The operator is used to get in put from the standard input devices i.e. keyboard. When you write a C + + program and used cin, you do not know the value of the input until the program is run. You can also fill the value using assignment stmt such as i = 13; the difference between assignment statement and cin operator is that value of the input is known is case of assignment statement where as it is not known in case of cin operator.

Syntax : cin >> values ;

Look at the following program :

// INTRO . CPP

# Include

main ( )

{

int a, b ;

cout << “ Enter one value = ”<< end 1;

cin >> a ;

cout<< “ the sum is =” <

return 0 ;

}

 

 When you will run the above program the computer will ask you enter the value of a & b

enter one value = 10

enter second value = 20

This sum is 30

 

The cout operator: (<< inseration operator):

<< operator is used to obtain the output on a standard output devices.

The device may be screen of the monitor.

Syntax:

cout << data ;

Example :

cout << “ I am the student of 11th class” ;

cout << “I read in DAV school”;

 

C + + Tokens

No comments on “C + + Tokens”

C + + Tokens :

The group of characters that logically belong together is called Token.Tokens are of following 4 types:-

1. Identifiers

2.Keywords

3.Constants

4.Operators

1. Identifiers:

 A program can use various data items with symbolic names in C + +. Identifiers refer to the names of functions, arrays, variables, classes etc. created by a programmer. There are certain rules for naming these identifiers in each languages. An Identifier, generally contains symbolic name. These symbolic names are used in various C + + programs. The rule of naming Identifiers in C and C + + are similar.

Rules for naming identifiers:

1. Uppercase letters and lowercase letters are distinct.

There is a difference between Ravi and RAVI.

2.An Identifiers name is to be made up of alphabets and digits. No other special characters are allowed.

3.The Underscore ( _ ) is the only special characters that is allowed to form the name of an identifier.

4.The underscore is treated as an alphabet.

5.The keywords are not allowed to be used as identifier names.

 Following are some valid identifier names

a   abc     abc123        max_sal_law_weight

 Following are some invalid identifier names with the reasons of invalidity

break                    -    the keyword is not allowed as                                                         identifier name.

4XYZ                    -     the identifier name must not begin with digit.

max + sal              -    the character ‘+’ is not allowed.

hello welcome      -       the blank space is not allowed.

2. Keywords:-

The keywords are nothing but the words which has got predefined meaning in that language.As a programmer we can not change meaning of these keywords. These keywords must be used for their predefined purpose. The keywords are also called as reserved words.

auto             do               inline            short            typedef

break           double         int                signed          union

case             else             long             sizeof          unsigned

catch           enum           new              static           virtual

char             extern          operator       struct           vopd

class            float             private         switch          volatile

const           for               protected     template       while

continue       friend           public            this             throw


3.Constants:-

The items whose values are not changed during the execution of the program are called constants. If an attempt is made to change their values, the program will not successfully execute and generate errors.

Each constant is determined by its value and form C + + has threetypes of constants:

1)Numeric constant

2)Character Constant

3)String Constant.


4. OPERATORS:-

 An operator is a symbol or letter which causes the complier to take an action and yield a value.An operator acts on different data items entities called Operands.

For example,

X + Y is an expression in which sign + is an operator which specifies the operation of addition.

 

Types Of Operators:

1.Arithmetical Operators

2.Increment  Decrement Operators

3.Binary Operators

4.Logical Operators

5.Conditional Operators

 

1.Arithmetical Operators:

 Arithmetical Operators are used for various mathematical calculations. The result of an arithmetical expression is a numerical value. An arithmetical expression may be a variable or a constant or a combination of both. These variables or functions are connected with arithmetical operators.

Arithmetical operators are of following types.

i) Unary Arithmetic Operator

ii) Binary Arithmetic Operator

2. Increment and Decrement Operator:

 Increment operator:- (+ +) The increment operator (+ +) is used to increment the value of a variable by 1.

The increment operator is either used as pre-increment operator or post-increment operator.

Consider the following example

Pre–increment                                    Post – increment

x = 3                                                  x = 3

+ + x ;                                               x + + ;

Due to pre – increment              Due to post –increment operator

operator the value of x            the value of x will be incremented

will be incremented by 1            by 1 and it will become 4.

and it will become 4.

 

Decrement Operator (--)

The decrement operator (--) is used to decrement the value of a variable by 1.

The decrement operator is either used as pre-increment operator or post-decrement operator.

Consider the following example.

Pre-decrement                                           Post-decrement

x = 3                                                           x = 3;

- - x;                                                            x - -;

Due to pre-decrement                                 Due to post-decrement

operator the value of                                 operator the value of x

x will be decremented by                         will be decremented by 1

1 and it will become 2.                               and it will become 2.

 

3. Relational Operators:

Relational operators are used to determine the relationship between different operands. These are used in the work of comparison also . There are two mathematical expression and these are connected by a relational operator. The relational expression returns O if the relation is false and returns 1 if the relation is true. The six relational operators are shown in the following table.

Symbol                                    Meaning

>                                    Greater then

<                                    Less then

>=                                  Greater than , equal to

< =                                 Less than, equal to

= =                                 Equal to

!                                     Not equal to


4. Logical Operators :

Logical operators combine the results of two or more than two expressions. The mode of connecting relationship in these expressions refers as logic and the expressions are called as logical expressions.

The logical expression returns 1 if the result is true and it returns 0 if the result is false.

C + + provides three logical operators which are listed below.

Symbol                                              Meaning

!                                          Logical negation

II                                         Logical OR

i                                         Logical Operator (!)

 

5. CONDITIONAL OPERATOR:

Conditional operator is also called ternary operator. It is represented by (? :). This is the only operator in C + + which takes three terms (Operands) and returns 0 value. The value of an expression using this operator is the value of either tits second operand or third operand, depending upon the value of first operand. However, ternary operator is some times o confused control structure.

(expression 1) ? (expression 2) : (expression3);

If expression 1 is true, the result of the operator is the value of expression 2; otherwise it results in the value of expression 3.

Simply speaking, the first operand is a test condition, the second and the third operands represent the final value of the expression and out of these values, one is selected depending upon the value of first operand.

 

 

 

More Articles …

  1. CHARACTERISTICS OF C + +
  2. General OOP concepts
  3. Constructors Vs. Destructors
  4. passing strings to funcation in c pro.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

Page 4 of 21

  • About Us
  • Faqs
  • Contact Us
  • Disclaimer
  • Terms & Conditions