technicalsymposium


Free E-Mail Alerts

Placement Materials/Course Materials-Free Download

OOPS CONCEPTS

Introduction
The main pitfall with standard C has been identified as the lack of facilities for data abstraction. With the emergence of more abstract and modular languages like Modula-2 and Ada and Object-oriented languages like Small-Talk, BJARNE STROUSRUP at Bells Lab was motivated to develop C++ by upgrading C with appropriate mechanisms to create object like abstract data structures. The introduction of the class mechanism in C++ mainly provides the base for implementing abstract data types to suit object-oriented programming. The C++ language is thus considered as the superset of the standard C.

IDENTIFIERS AND KEYWORDS
Identifiers can be defined as the name of the variables and some other program elements using the combination of the following characters.
Alphabets : a…z, A…Z
Numerals : 0…9
Underscore : _

Eg.,
NAME, A23C, CODE, EMP_NAME


Special characters :
All characters other than listed as alphabets, numerals and underscore, are special characters.

Keywords
Keywords are also identifiers but cannot be user defined since they are reserved words.

Keywords in C++
Auto break case char const continue default do double else enum extern float for goto if long register return short signed sizeof static struct switch union unsigned void volatile while

Constants
• String constants
• Numeric constants
• Character constants

String constants
A string constant is a sequence of alphanumeric characters enclosed in double quotation marks whose maximum length is 255 Characters.
Eg. “The man”
“A343”

Numeric Constants
These are positive or negative numbers.
Types of Numeric constants are :

Integer
• Integer
• Short Integer(short)
• Long Integer(long)

Float
• Single precision(float)
• Double precision(double)
• Long double

Unsigned
• Unsigned char
• Unsigned integer
• Unsigned short integer
• Unsigned long integer

Hex
• Short hexadecimal
• Long Hexadecimal

Octal
• Short octal
• Long octal

Operators
• Arithmetic operators (+, -, *, /, %)
• Assignment operators (=, +=, -=, *=, /=, %=)
• Comparison and Logical operators (<, >, <=, >=, ==,!=, &&, ||, !)
• Relational operators (<, >, <=, >=)
• Equality operators (==, !=)
• Logical operators(&&, ||, !)
• Unary operators(*, &, -, !, ++, --, type, sizeof)
• Ternary operator (?)
• Scope operator(::)
• New and delete operators

Skeleton of typical C++ program
Program heading
Begin
Type or variable declaration
Statements of operation
Results
End

iostream
The “iostream” supports both input/output stream of functions to read a stream of characters from the keyboard and to display a stream of objects onto the video screen.
Input and Output statements
Output Statement

The syntax…
• cout << “Message”
• cout << variable_name
• cout << “Message” << variable_name

The ‘<<’ is called as “insertion” operator.

Eg. Cout << “god is great”
Cout << age
Cout << “name is …” << name
Input Statement

The syntax…..
Cin >> var1 >> var2 >> var3…..varn;
The ‘>>’ is called as “extraction” operator.
Eg.
Cout << “Enter a number”
Cin << a
Sample program to add, subtract, multiply and divide of the given two numbers


void main()
{
int a,b,sum,sub,mul,div;
cout << “Enter any two numbers “ << endln;
cin >> a >> b;
sum=a+b;
sub=a-b;
mul=a*b;
div=a/b;
cout << “Addition of two numbers is…” << sum;
cout << “Mulitiplication of two numbers is…” << mul;
cout << “Subtraction of two numbers is…” << sub;
cout << “Division of two numbers is…” << div;
}

CONTROL STATEMENTS

Conditional Statements
The conditional expressions are mainly used for decision making. The following statements are used to perform the task of the conditional operations.
• if statement
• if-else statement
• switch-case statement
if Statement

The if statement is used to express conditional expressions. If the given condition is true then it will execute the statements; otherwise it will execute the optional statements.
If (expression)
{
Statement;
Statement;
;;
;;
}
if-else statement
Syntax
if (expression)
statement;
else
statement;
Syntax
if (expression)
{
block-of-statements;
}
else
{
block-of-statements;
}
Nested if
If (expression) {
If (expression) {
**********
**********
}
else {
*********
**********
}
else {
if (expression) {
*******
****
}
else {
*********
*********
}
}
A program to read any two numbers from the keyboard and to display the largest value of them.
#include
void main()
{
float x,y;
cout << “Enter any two numbers \n”;
cin >> x >> y;
if (x>y)
cout << “Biggest number is…” << x << endl;
else
cout << “Biggest number is…” << y << endl;
}
switch statement
The switch statement is a special multiway decision maker that tests whether an expression matches one of the number of constant values, and braces accordingly.
Syntax
switch (expression) {
case contant_1 :
Statements;
case contant_2 :
Statements;
;;
;;
;;
case contant_n :
Statements;
default :
Statement;
}
Loop Statements

A set of statements are to be executed continuously until certain condition is satisfied. There are various loop statements available in C++.
• for loop
• while loop
• do-while loop
for loop
This loop consists of three expressions. The first expression is used to initialize the index value, the second to check whether or not the loop is to be continued again and the third to change the index value for further iteration.
Syntax
for (initial_condition; test_condition; increment or decrement value)
{
statement_1;
statement_2;
;;
;;
}
A Program to find the sum and average of given numbers
void main(){
int n;
cout << “Enter the no. of terms…”;
cin >> n;
float sum = 0;
float a;
for (int i=0; i<=n-1;++i) {
cout << “Enter a number :\n”;
cin >> a;
sum = sum+a;
}
float av;
av = sum/n;
cout << “sum= “ << sum << endl’
cout << “Averave = << av << endl;
}
Nested For-Loops
for(i=0;i<=n; ++i){
for(j=0; j<=m ; ++j)
statements;
statements;
statements;
}
while loop
This loop is used when we are not certain that the loop will be executed. After checking whether the initial condition is true or false and finding it to be true, only then the while loop will enter into the loop operations.
Syntax
While (Condition)
Statement;
For a block of statements,
while(condition) {
Statement_1;
Statement_2;
----
----
}
Example
while ((character = cin.get()) != EOF )
cout.put (character);
do-while loop
Whenever one is certain about a test condition, then the do-while loop can be used, as it enters into the loop at least once and then checks whether the given condition is true or false.
Syntax
do{
Statement_1;
Statement_2;
------
------ } while (expression);
Example
Sum=0;
do
{
sum=sum+I;
i++;
}
while (i break statement
The “break” statement is used to terminate the control from the loop statements of the “case-switch” structure. This statement is normally used in the switch-case loop and in each case condition, the break statement must be used. If not, the control will be transferred to the subsequent case condition also.
Syntax
break;
Continue statement
This statement is used to repeat the same operations once again even if it checks the error.
Syntax
continue;
go to statement

This statement I used to alter the program execution sequence by transferring the control to some other part of the program.

Syntax
goto label;

There are two types of goto statements, which are conditional and unconditional goto statement.

Unconditional goto



This goto statement is used to transfer the control from one part of the program to other part without checking any condition. Example

void main(){
start:
cout << “God is Great”;
goto start;
}
Conditional goto
This will transfer the control of the execution from one part of the program to the other in certain cases.

Example
If (a>b)
goto big1;
big1:


Functions
A function definition has a name, a parentheses pair containing zero or more parameters and a body. For each parameter, there should be a corresponding declaration that occurs before the body. Any parameter not declared is taken to be an int by default.

Syntax
Function_type functionname(datatype arg1, datatype arg2,….)
{ body of function;
------
------
return value;
}

DOWNLOAD FULL QUESTION PAPER IN WORD FORMAT

C Program For FINDING POWER VALUE OF GIVEN NUMBER.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,r,c=1;
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
printf("Enter the r value:");
scanf("%d",&r);
for(i=1;i<=r;i++)
{
c=c*n;
}
printf("the power value is=%d",c);
getch();
}

Technicalsymposium.com- All Information Contents Given Below-Click & Get All Details

Hosting by Yahoo!

About-Us    Contact-Us    Site-map

©copyright All rights are reserved to technicalsymposium.com