Introduction to Programming
With the concept of memory and processor it is easy to understand programming. This is next step in coding. Like when we translated a given problem in steps to solve. In next step we will convert it into final computer code and run it on computer. In this session we will learn basic functions that all programming languages provide.
Computer functionality has 2 basic parts. First part is interacting with user and second part is processing, storing or reading data.
Interacting with user:- To take data from user
- To give some feedback to user
- To process data (arithmetic, logical)
- To store data in memory
- To read data from memory
Every computer program does these basic functions like media players, games, calculator, MS office. Hence to write a program you need to implement the programming commands according to your code, pattern.
In any programming language we write set of commands which can- create memory to use
- get user input
- give user some output
- solve arithmetic operations on values
- compare data
- Commands end with semi-colon " ; "
- Commands run one by one on processor
- Commands has 2 general parts
- first being keywords, some words that are made standard for some basic functions. those are case sensitive i.e. if it is int you can not write it as Int or INT etc.
- second our declared part that we name to make code understand like we save data of names of students and we declare it like this:
int registration_number ;
- int being keyword
- registration_number being our declaration of this data so we can understand what it represents, in this case it's a registration number
So make sure to write language specific words as they are and your own declarations such that they make sense
Let's convert our code from 'introduction to coding' in commands.
To make calculator program
1. Take first user input:- reserve some memory of specific type and name
- int number1;
- tell user to enter value
- print("Enter first value: ");
- let user to enter value
- cin>>number1;
2. Take second user input:
- reserve some memory of specific type and name
- int number2;
- tell user to enter value
- print("Enter second value: ");
- let user to enter value
- cin>>number2;
Now we have 2 values of user saved as 'number1' and 'number2' in memory
3. Take operation choice:
- reserve some memory
- char operation;
- tell user to enter choice
- print("Enter choice: ");
- let user to enter choice
- cin>>operation;
- reserve some memory for answer
- int result;
- prepare result by taking values entered by user and performing operation
(for simplification let us say user entered +)
- result = number1 + number2;
5. Show output
- print(result);
Comments
Post a Comment