+ All Categories
Home > Software > Introduction to c++

Introduction to c++

Date post: 22-May-2015
Category:
Upload: himanshu-kaushik
View: 235 times
Download: 2 times
Share this document with a friend
Description:
Introduction to c++ tutorial c plus plus , c++
Popular Tags:
22
Introduction to C++ BY HIMANSHU KAUSHIK
Transcript
Page 1: Introduction to c++

Introduction to C++BY HIMANSHU KAUSHIK

Page 2: Introduction to c++

What is c++ ?

C++ is a object-oriented language

It is the “successor” to C, a procedural language (the “++” is called the successor operator in C++)

C was derived from a language called B which was in turn derived from BCPL

C was developed in the 1970’s by Dennis Ritchie of AT&T Bell Labs

C++ was developed in the early 1980’s by Bjarne Stroustrup of AT&T Bell Labs.

Most of C is a subset of C++

Page 3: Introduction to c++

People & Programs

User: an individual who runs, or executes, a program

Programmer: an individual who creates, or writes, a program

Page 4: Introduction to c++

C++ Programming

Consists of…Declarations

Define the use of various identifiers, thus creating the elements used by the program (computer)

Statements Or executable statements, representing actions the computer will take on

the user’s behalf

Page 5: Introduction to c++

Identifiers

Names for various entities used in a program; used for...

Variables: values that can change frequently Constants: values that never changes Functions: programming units that represents

complex operations Parameters: values that change infrequently

Page 6: Introduction to c++

A Simple c++ Program

#include <iostream.h>int main()

{// Declarations

// Statements

return 0;

}

Page 7: Introduction to c++

The Header File

#include <iostream.h>int main()

{

// Declarations

// Statements

return 0;

}

Compiler directive: Tells the compiler what to do before compiling

This one includes source code from another file

Page 8: Introduction to c++

The Main Statement

#include <iostream.h>

int main(){

// Declarations

// Statements

return 0;

}

Header for main function States…

data type for the return value

identifier for function list of arguments between

parenthesis(none for this function)

Page 9: Introduction to c++

The Braces

#include <iostream.h>int main()

{// Declarations

// Statements

return 0;

}

Braces enclose the body of the function

They represent the start and end of the function

Page 10: Introduction to c++

The Declaration Statement

#include <iostream.h>int main()

{

// Declarations

// Statementsreturn 0;

}

Declarations and statements

Main body of function (or main part)

“//” represents the start of a comment

Page 11: Introduction to c++

The return Statement

#include <iostream.h>int main()

{// Declarations

// Statements

return 0;}

Return statementspecifies the value

the function returnsAll (almost)

declarations and statements end with a semi-colon “;”

Page 12: Introduction to c++

Sample C++ Program

#include <iostream.h>void main()

{int number;

cout << “Enter a number” << endl;

cin >> number;

cout << “You entered: “ << number << endl;

}

What is the Output of this Program?

Page 13: Introduction to c++

The DataTypes

#include <iostream.h>void main()

{int number;

cout << “Enter a number” << endl;

cin >> number;

cout << “You entered: “ << number << endl;

}

Variable declarationThe identifier number is

declared as being of data type int, or integer

Page 14: Introduction to c++
Page 15: Introduction to c++

The Count ?

#include <iostream.h>void main()

{int number;

cout << “Enter a number” << endl;cin >> number;

cout << “You entered: “ << number << endl;

}

coutthe output statement for C++

Note the direction of “<<“endl represents an end-of-line

Page 16: Introduction to c++

Cin ?

#include <iostream.h>void main()

{int number;

cout << “Enter a number” << endl;

cin >> number;cout << “You entered: “ << number << endl;

}

cinthe input statement for C++Note the direction of “>>”

Page 17: Introduction to c++

Copy That Down

#include <iostream.h>void main()

{int number;

cout << “Enter a number” << endl;

cin >> number;

cout << “You entered: “ << number << endl;

}

Page 18: Introduction to c++

Value Assignment In c++

Assignment is an operation that assigns the value of an expression to a variable

Ex. Total = 2 + 3 + 5First, the expresssion “2 + 3 + 5” is

evaluatedThen, this value is assigned to the

variable “Total”

Page 19: Introduction to c++

Assignment When a variable is declared, space is

allocated in the computer’s memory for the variable

Each data type requires a different number of bytes in memory for storing a variable

int - 2float - 4double - 8char, bool - 1

Page 20: Introduction to c++

Arithmetic Operations

Addition: 2 + 3Subtraction: 5 - 2Multiplication: 10 * 4Division: 12 / 3

Page 21: Introduction to c++

I Have A problem for you

Problem: To determine the average of three numbers

Task: Request, from the user, three numbers, compute the average and the three numbers, and print out the original values and the computed average

Do it!You have 20 minutes!

Page 22: Introduction to c++

Any Queries ?


Recommended