Basic of Computer Programming C++, Essays (university) of Computer Science

Basic of Computer Programming C++

Typology: Essays (university)

2016/2017

Uploaded on 11/14/2017

bharti-sharma-1
bharti-sharma-1 🇮🇳

1 document

1 / 100

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Dr. Adarsh Anand
Department of Operational Research
University of Delhi
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Basic of Computer Programming C++ and more Essays (university) Computer Science in PDF only on Docsity!

Dr. Adarsh Anand

Department of Operational Research

University of Delhi

 C++ is an object oriented programming

language.

 C++ is an extension of C with a major addition

of the class construct feature.

 C++ is superset of C.

 Features like classes, inheritance, function

overloading, and operator overloading make

C++ a truly object-oriented language.

 OO features in C++ allow programmers to build

large programs with clarity, extensibility and

ease of maintenance, incorporating the spirit and

efficiency of C.

Since the invention of computer, many programming approaches

have occurred: Procedural Programming, Modular Programming,

Structural Programming and of-late the OOPS.

A program in a procedural language is a list of instructions where

each statement tells the computer to do something. The focus is on

the proessing, the algorithm needed to perform the desired

computation.

But this proved to be problematic as the data takes a back seat with

this paradigm. Furthermore, this approach does not model the real

world very well.

After this approach came OOPS. This approach views a problem in

terms of objects involved rather than procedure for doing it.

/* Simple hello world program*/

include // This is include directive

int main() { cout << “Hello World!”; //C++ statement return 0 ; } Note: Technically, in C or C++ main function has to return a value because it is declared as "int main“ which means "main function should return integer data type“ if main is declared like "void main", then there's no need of return

  1. Some compilers even accept and compile the code even if u don’t write return 0. varies from compiler to compiler

 Keywords

 Identifiers

 Constants

 Strings

 Operators

 Keywords

 Identifiers

 Constants

 Strings

 Operators

 Keywords

 Identifiers

 Constants

 Strings

 Operators

 Identifiers refers to the names of variables,

functions, arrays, classes , etc. created by the

programmer.

 Rules for creating it.

◦ Only alphabet characters, digits and underscore are permitted. ◦ The name cannot start with digit. ◦ Uppercase and lowercase letters are distinct. ◦ A declared keyword cannot be used as a variable.

Type Bytes Range

signed: - 2147483648 to

  • char 1 - 128 to
    • signed: - 128 to
    • unsigned: 0 to
  • short int 2 - 31768 to
    • signed: - 32768 to
    • unsigned: 0 to
  • int 2 - 32768 to
    • signed: - 31768 to
    • unsigned: 0 to
  • long int 4 - 2147483648 to
    • unsigned: 0 to
  • float 4 3.4E-38 to 3.4E+
  • double 8 1.7E-308 to 1.7E+
  • long double 10 3.4E-4932 to 1.1E+

 Structures and Classes

◦ Basis for OOP. ◦ Classes enable to combine data and procedures.

 Enumerated Data Type

◦ It provides a way to attaching names to the numbers ◦ Increase comprehensibility of the code. ◦ Alternative mean for creating symbolic constants ◦ Enumerates a list of words by assigning them values 0 , 1 , 2 and so on. enum shape {circle, square, triangle}; enum colour {red, blue= 4 , green= 8 };

Functions Set of statements to perform specific tasks. Pointers

  • Special variables to store the memory location of other variables.
  • Used in referencing memory.
  • Concept of constant pointer introduced in c++.
  • Defining a pointer, we use an asterisk between the data type and the variable name:
  • int *ptr; //a pointer to an integer value

Since pointers only hold addresses, when we assign a value to a pointer, the value has to be an address. To get the address of a variable, we can use the address-of operator (&): int nValue = 5; int *pnPtr = &nValue; // assign address of nValue to pnPtr Conceptually, you can think of the above snippet like this: int nValue = 5; int *pnPtr = &nValue; // assign address of nValue to pnPtr cout << &nValue << endl; // print the address of variable nValue cout << pnPtr << endl; // print the address that pnPtr is holding On the author’s machine, this is printed: 0012FF7C 0012FF7C

 Refer to fixed values that do not change in

the execution of the program.

◦ 123 //decimal integer ◦ 12.34 //floating point integer ◦ 037 //octal integer ◦ 0x2 //Hexa decimal ◦ “C++” //string constant ◦ ‘A’ //character constant ◦ L’ab’ //wide-character constant

 Using the qualifier const

◦ const float pi = 3. 14 ;

 Using enum

◦ enum{x,y,z}; ◦ enum{x= 200 ,y= 300 ,z= 400 }; ◦ enum{off,on};