Programming elements:
- Software is a set of programs.
- Every program consists 3 things
- Identity
- Variables
- Methods
Identity:
- Every program has unique identity.
- We can access programs with identities only.
- For example Account Holder program can access uniquely using account number as identity.
Variable:
- Variables are used to store information.
- Programs share information in communication.
Function:
- Also called functions(In procedure oriented programming)
- Functions are used in communication.
Application: Banking project
- We design Account holder programs
- Account holder consists
- Identity: account number
- Variables: name, balance, pin, mobile, mail, address…
- Methods: withdraw(), deposit(), transfer()….
Variables:
- Setting identities to memory locations by which we can store and process the data(modify, delete, print) easily.
- Named memory location(simple definition)
Methods:
- A block of instructions performs a task.
- We can access the block using its identity
- Method takes input, process input and return output.
Syntax:
returntype identity(arguments)
{
-> Process arguments (input)
-> Return output
}
Example:
int add(int a, int b)
{
int c = a+b;
return c;
}
Banking App:
message withdraw(atm, pin, amount)
{
-> ATM card is authorized or not
-> PIN is valid or not
-> Amount is present or not
-> Process account
-> Update account
-> Release cash
}
Every Method consists:
- Method definition:
- It is a block
- It contains method logic to perform task
- It will not execute automatically.
- Method call:
- It is a single statement.
- It is used to access method logic.