BASICS OF PROGRAMMING....

Post on 25-May-2015

69 views 3 download

Tags:

Transcript of BASICS OF PROGRAMMING....

Puzzled about programming languages????

Abhishek Mukherjee | VIT Spartans

What is programming?

• Think about a problem.• Any problem statement.• U will get a path to approach the problem.• Frame the path stepwise.• The same problem can be solved using your compiler.• The path of stepwise approaching the problem is called

algorithm.

THE STEPS OF CREATING A CODE

Decide the approach of your Problem statement.i.e. some predefined algorithm or your own idea

Choice of languagei.e. object oriented(java , c#) or modular(c)

Compile Time errorsSyntax errors…

Execute the program after successful compilationRun time errors???!!!! Logical errors

Successful CompilationProceed to next problem…..

Algorithmkl

Various compliers are available for various languagesi.e. turbo(c , c ++ ) , dev etc….

Choice?

Compiler?

Problems…

Run…

Executed….

ALGORITHMS

• JO DIMAAG ME AYE USE CODE KARO

•LIKHNE KI ZAROORAT NHI HAI

DIFFERENT APPRAOCHES

• Many types of data can be worked upon• U might want to encrypt ur name(string

type)• U might want to make your own

personalized calculator(various types of numbers)

• U might want to have a binary output for your program(Boolean type)

• Many permutations are available for optimizing ur code.

• U might want to create an excel sheet(2D array)

BASICS OF PROGRAMMINGVariables

CONSTRUCTOR

• INTEGER(int)• Many types of int are available in

all languages• This includes types based on sizes• Int32,int64,int16 are the few

available in c#• Int64 is normally used in place of

long type numbers as in other languages

• DOUBLE and FLOAT• Smaller decimal number of 6th

precision can be stored in float types

• Float can be used to store decimal numbers upto 12th precision

• Any type conversion from int to these types leads to the the digits after the point becoming zero

• Type conversion takes place only form a datatype of hIgher size to a data type of lower size

DATA TYPES TO BE USED FOR NUMBERS

• ARRAY(1 D)• Can be used to store multiple:• Integers• Strings• Double , Float• Boolean• Characters

• ARRAY(2 D)• The same data as 1d array can be

stored in a tabular form like data in rows and columns as in a excel sheet.

STORING MUTIPLE DATA IN A VARIABLE:

• Predefined functions:• Defined by the language we use• Defined to serve a specific purpose• Allows reusability of code• Makes program more efficient by

making debugging easier

• User defined functions:• Make the code according to our

own specifications

FUNCTIONS

• The coding will be operated on a specific operand/operands. These variables are called the parameters of the function

• The functionality of a function(coding of the function)

• The output value of the function i.e. the result of the operation preformation(if any) is called return value..

FUNCTIONS:Parts of a function:

• Characters:• Used to store a single character• We have a system to represent any

character called ASCII• The values vary from 0-255• Example all capital letters have

values ranging form 65-90• This concept comes from the

concept of a byte• A byte contains 8 bits each and

thus 2^8 (256) combinations available

• Strings:• Used to store multiple characters.• Can be manipulated• Always stored in double quotes• String s=“C#”• Many functions available to

manipulate strings• Example of functions used-Length ,

substring

Variables Contd……

• Call by reference:• The parameters which are

operated upon will change their value after function call

• In this case the memory reference of the parameter is sent which has the scope to change the original value of the variable bcoz the memory address is sent

• It has the advantage of returning multiple variables without actually returning them!!!!!!!!!!!!!!!

• Think yyy????

• Call by value:• It’s the normal function call where

we require normal function calls

FUNCTION CALLING:Two types:

• GLOBAL:• Scope is defined throughout the scope of the program.• Can be accessed by all the functions of the program.• A Constructor needs to be initialized to give default

values to these variables.

• LOCAL:• These variables can be accessed

only in their specific function definitions

Another classification of variables:Scope…………..