Wednesday 9 February 2022

Procedural oriented programming / structured programming - The program blog

In this post, we will be going to discuss procedural-oriented programming, which is also called structured-oriented programming in detail. So let's get started to see what is procedural-oriented programming step by step.

-It is sometimes known as modular programming.

-Programs written are more efficient and easier to understand and modify.

-The procedural/structured programming languages are similar to solving a problem by humans. In a nutshell, humans attempt a problem by adopting a sequence of operations.

-It makes use of a top-down design model in which a program developer maps out the overall program structure into separate subsections.

-Large-size programs can be developed in structured programs such as pascal and c. Programs are divided into multiple sub-modules.

-Procedural/Structured programming languages such as FORTRAN, BASIC, ALGOL, COBOL, C, etc., are divided into a number of segments called subprograms. There is the main function and it invokes subprograms. Thus, it focuses on functions apart from data. here also the programmer can observe the lack of secrecy.

procedural oriented programming


-The control of the program can be transferred using an unsafe goto statement.

-This type of programming language uses different control structures that are as follows:
  • Decision/selection control statements
  • Iteration control statement
  • Jump control statement

-Data is global and all the sub-programs share the same data, i.e. data are globally accessible to all functions. Thus, any function operates on the global data and this directs to losing some vital information. We can conclude here that a module represents a function.

-Procedural structured/programming languages permit data transfer through messages by means of function.

-Least importance is given to the data in procedural/structured programming languages.

-Compiler and interpreter construction are easy and simple with this type of programming language. Furthermore, these compilers and interpreters need low memory to run on the computers.

-It is difficult to implement simultaneous processes/parallelization.

I hope you guys understand what is procedural-oriented programming. If you find any mistakes or have any doubts then please comment in the comment section. Thank you so much for reading the article.

Recommended post:

Tuesday 8 February 2022

Difference between C and C++ | C and C++ difference - The Program Blog

Hello readers in this post you guys will be going to see the difference between C and C++, and what are the similarity is there in C and C++. So guys let's see both differences and similarities available between C and C++.

difference between c and c++

Some differences between C and C++ is as follows:

-C is a procedure/function-oriented language and C++ language is driven by a procedure/object.

-Data is not protected in C, whereas data is secured in C++. The data hiding concept is absent in C.

-C uses a top-down approach while C++uses a bottom-up approach. The program is prepared step by step in c, and in C++ base, elements are prepared first.

-In C we cannot give the same name to two functions in a program, whereas due to the function overloading feature, the above concept is possible in C++. One can initialize a number of functions with the same name, but with different arguments. The polymorphism feature is built in C++, which supports this concept.

-C uses printf() and scanf() functions to write and read the data respectively, while C++ uses cout and cin objects for output and input operations, respectively. Further,the cout uses <<(insertion operator) and cin uses >> (extraction operator).

-C uses stdio.h file for input and output functions, whereas C++ uses iostream.h for these functions.

-Constructor and destructor are absent in C and the same are provided in C++.

-Inline functions are supported by C++, and the same is absent in C. Inline functions can be used as micros. They are stated by the word 'inline'.

I hope you guys get cleared what is the difference between C and C++. If you have any queries or any doubts regarding this then please do comment in the comment section below.


Recommended post:

Wednesday 23 September 2020

algorithm | algorithm in programming | algorithm in c - Online help

In this post, we are going to discuss in detail what is an algorithm in programming and what are all the basic factors that should follow or consider while writing an algorithm to solve a problem. So let's get started.

algorithm in programming

 Algorithm in programming:

An algorithm is a set of English-like statements, which is used to illustrate the logic of the program. The word algorithm is named after the Arabian mathematician Musa al Khowarismi, which means method, or recipe, or procedure.

The algorithm defines the logic of solving a problem and hence it should be organized properly, in such a way it is meaningful and unambiguous. The solution for the problem should be defined precisely and all the statements should be stated correctly and explicitly.


Factors to follow while writing an algorithm:

The following are the various factors that should be considered before writing an algorithm to solve the problem:
  • The nature of the problem should be clearly understood by defining the problem specification.
  • The various output that should be obtained.
  • The inputs available for obtaining the output.
  • The sequence of steps, known as an algorithm, to achieve the result, should be clearly written down.
  • The program should be tested for the different values and known results to find the errors, which may exist.
  • Debug the error if any.
  • Document the program to make the users understand the program better.


algorithm tutorial:

Let's see an algorithm tutorial to write an algorithm to find the sum of the series 1+2+3+..........+10.

Step 1: Initialize sum=0

Step 2: Initialize num=1

Step 3: sum=sum+num

Step 4: num=num+1

Step 5: if num<=10 then go to step 3

Step 6: print sum

Step 7: stop

In the above algorithm, we have to set an initial value of 0 to the variable 'sum'. This process is called initialization.

Again in step 2, we have initialized the value of num to 1. In step 3, the value of 'sum' is added to the value of 'num' and the resultant value is stored in the variable 'sum'. This is called an assignment. Note that the left-hand side of the expression is a variable and the right-hand side of the expression is substituted by the value of the variable.

so the value of the 'sum' will be equal to 1. Next in step 4, the value of the 'num' is set to num+1, that is, the value 1 is added to the existing value of 'num', and the resultant value is stored in the variable 'num'. This process is called incrementing the value. Initially, the value of 'num' was 1. After processing step 4,  the value of 'num' will be equal to 2.

In step 5, we check whether the 'num' is less than or equal to 10. If this condition fails then the control is taken back to step 3. If the condition is true then step 6 is executed to print the value of 'sum'.


Basic algorithm for beginners: 

Let's discuss the process of writing an algorithm by choosing some of the day-to-day activities of our life.

Example 1: Write an algorithm to prepare a cup of coffee.

Step 1: take a container and pour a cup of milk.

Step 2: switch on the stove.

Step 3: place the container on the stove.

Step 4: is the milk boiling? if not, continue heating the milk.

Step 5: if the milk boils, then add one teaspoon of coffee powder to the container.

Step 6: Add two teaspoons of sugar to the container.

Step 7: stir the container with a spoon

Step 8: does sugar and coffee powder dissolve?

Step 9: if not, go to step 7.

Step 10: switch off the stove.

Step 11: pour the coffee into a cup

Step 12: serve or drink the coffee




Example 2:  Write an algorithm to go to your college by bus.

Step 1: Start from home and reach the bus stop.

Step 2: wait for the desired bus to come.

Step 3: if the bus has come, check whether it is the required bus.

Step 4: if not, go to step 2.

Step 5: board the bus.

Step 6: purchase the ticket.

Step 7: travel until your college stop is reached.

Step 8: Check whether your college stop has come.

Step 9: if not, go to step 7.

Step 10: get down from the bus.

Step 11: walk and reach your college.


Example 3: Write an algorithm to accept your name and age and print it.

Step 1: accept name

Step 2: accept age

Step 3: print "your name is:", name," and your age is:", age

Step 4: stop


Also read:  Javascript function


Example 4: Write an algorithm to two numbers and print the largest of two.

Step 1: accept a,b

Step 2: if a>b then print a "is greater" : go to step 4

Step 3: otherwise print b "is greater"

Step 4: stop

I hope you guys understand what is an algorithm in programming if you have any queries or you find any mistake then please comment below. Thank you so much for reading my article.

Monday 6 July 2020

conditional statements in javascript - Online Help

Conditional Statements in javascript:

Conditional statements in javascript are the set of commands used to perform different action s based on different conditions.  the conditional construct will either return a True or false depending upon how the condition is evaluated. There are two conditional statements in JavaScript:
  • if-else statement
  • switch statement

if-else statement :

Use this statement if you want to execute s set of code when a condition is true. If the condition is true the true statement is executed, otherwise, the false statement is executed.

The general format of the if-else statement is 

if (condition)
{
statement 1;                         
}           
else             
{             
statement 2;
}

The else clause allows you to specify a statement or group of statements that will be executed if the expression does not evaluate to true. Only one else clause is allowed in any if statement. Again, the statement can be used with or without the curly brackets.


Example:

<html>
<head>
<title> java script </title>
</head>
<body>
<b>RESULT</b>
<p> OPEN SOURCE SOFTWARE:
<script type=”text/java script”>
var m= 70;
if (m>=35 && m<=100)
{
document. write (“<span style=’ color: blue ‘> PASS</span>”);
}
else
{
document. write(“<span style=’color : red’>FAIL</span>”);
}
</script>
</body>
</html>


switch statement in javascript:

The switch statement evaluates an expression and compares the value to one or more case clauses. If you need to compare a variable against more than two or three values, the switch statement is the most efficient way.

The general format of the switch statement is

 switch (expression)
{
case labe11: block1
break;
case labe12: block2 
break;
 ……………
default:     def block;
}

Evaluate an expression and attempt to match the expression’s value to a case label. If a match is found, the program executes the associated statement.

 

Example:

<html>
<head>
<title>java script</title>
</head>
<body>
<h2><font Color=”red”>SUBJECT&CODE</h2></font>
<script type=”text/java script”>
var subject code=”UCA61”;
switch (subject code)
{
case”UCA61”: subject=”Open Source Software”;
break;
case”UCA62”: subject=”Multimedia”;
break;
case”UPCA66”: subject=Open Source Laboratory”;
break;
default: subject=” UNKNOWN SUBJECT”;
}
document. write(“<h2>code=& nbsp” +subject code+”
<br> subject =&nbsp” +</h2>”);tement
</script>
</body>
</htm1>

I hope you guys understand what is a conditional statement in javascript. If you find any mistake or having any queries then please comment down below.



Sunday 5 July 2020

Javascript data type | Primitive data type in javascript - Online Help

The data type in javascript describes the basic elements that can be used within that language. JavaScript supports four primitive data types:

Data types in JavaScript:

Javascript datatype | Primitive data type in javascript - Online Help

1. Numbers- are values that can be processed and calculated. You do not enclose them in quotation marks. The numbers can be either positive or negative. 

2. Strings- are a series of letters and numbers enclosed in quotation marks. JavaScript uses that string literally; it doesn't process it. You'll use string for the text you want to be displayed or values you want to be passed along.

3. Boolean (true/ false) - lets you evaluate whether a condition meets or doesn't meet specified criteria.

4. Null- is an empty value. Null is not the same as 0--0 is a real, calculable number, whereas null is the absence of any value.

Number:

The numbers and can be integers (such as 2, 22 & 2000) or floating point values (such as 23.42, -56.01, & 2e45).

We can represent an integer in one of the following three ways:

Decimal: The usual numbers which are having the base 10 are the decimal numbers.

Octal: octal literals begin with a leading zero, and consist of digits from 0 through 7. The following are all valid actual literals:

00 0777    024513600

Hexadecimal: hexadecimal literals begin with a leading 0x, and they consist of digits from 0 through 9 and letter A through F. The following are all valid hexadecimal literals:

0x0     0xF8f00 0x1a3C5e7

String:

String means a set of characters. In javascript, strings are enclosed in a pair of single quotes or double-quotes. The value of the can even contain space and maybe totally made from digits.

“Chris” “Chris bates” “234.56”

Boolean:

Boolean variables hold the values true and false. These are used to hold the result of conditional tests.

Null:

It consists of a single value, null, which identifies a null, empty, or nonexistent reference. Its null value is common in all JavaScript types.

I hope you guys understand what is javascript datatype and its primitive type. If you find any mistake or having any queries then please comment down below. Thank you for reading.

Saturday 4 July 2020

Variables in javascript | Declaring a variable - Online help

In this post, we are going to talk about what is variables in javascript? and how to declare the variables in javascript. So stay tuned till the end and let's get started.

Variable in Javascript:

A variable in javascript is a name assigned to the computer memory location to store data. As the name suggests, the value of the variable can vary, as the program runs. Before you use a variable in a JavaScript program, you must declare it.  Variables are declared with the var keyword.


Variables in javascript | Declaring a variable - Online help


Rules for variable names:

  • They must begin with a letter, digit, or underscore character.
  • We can’t use spaces in names.
  • Variable names are case sensitive.
  • We can’t use a reserved word as a variable name.


Declaring JavaScript variable:

To declare the variable using the var keyword. You can declare one variable at a time or more than one. You can also assign values to the variables at the time you declare them.


Different methods of declaring JavaScript variables:

//declaring one JavaScript variable

var firstname;


//declaring multiple JavaScript variables

var firstname, lastname;


//declaring and assigning one JavaScript variable

var firstname= ’homer’;


//declaring and assigning multiple JavaScript variable

var firstname= ’homer’, lastname= ’simpson’;


JavaScript variable scope:

The scope of a variable is the region of your program in which it is defined. JavaScript variable will have only two scopes.

  • Global variables:  A global variable has a global scope which means it is defined everywhere in the JavaScript code.
  • Local variables: A local variable will be visible only within a function where it is defined. Function parameters are always local to the function.

Within the body of a function, a local variable takes precedence over a global variable with the same name. if you declare a local variable or function parameter with the same name as a global variable, you effectively hide the global variable. The following example explains it:

<script type= “text/javascript”>
<!—
Var myvar=”global”; // declare a global variable
Function checkscope()
{
Var myvar=”local”; //declare a local variable 
Document.write(myvar);
}
//-->
</script>

This produces the following result:
local

I hope you guys understand what is variables in javascript. If you find any mistake or having any queries then please comment down below. Thank you for reading.


Recommended post:



Friday 3 July 2020

Javascript functions | how to call javascript function - Online Help

Hello reader, today from this post we are going to learn about what is JavaScript functions? and how to call a function in javascript so read the article till the end and yeah let's gets started.

Javascript functions | how to call javascript function - Online Help


JavaScript functions:

Functions are a block of code that gets executed when called. Every function has a name, this name is used to call the function, which in turn result in the execution of the associate block of code. It takes zero or more parameters.

Functions can be defined both in the <head> and in <body> section of a document. However, to assure that a function is read or loaded by the browser before it’s called, it could be wise to put a function in the <head> section.


Defining functions:

A JavaScript functions definition consists of a function keyword, followed by the name of the function. A list of arguments to the function is enclosed in parentheses and separated by a comma. The statement within the function is enclosed in curly brace {}. The general format to define a function is,

Function functionname (parameter1, parameter2, …………..)
{
Statements;
}

Whereas,
  • Functionname is the name of the function.
  • parameter1, parameter2, ………….. are arguments or parameters to the function.


How to call functions in javascript:

A function is not executed before it is called. You can call functions containing arguments. The general form is:

functionname (parameter1, parameter2, …………..)


Return statement:

The return statement can be used to return any valid expression that evaluates to a sign value. A function that will return a result must use the return statement. This statement specifies the value which will be returned to where the function was called from.
A javascript function can have an optional return statement. This is required if you want to return a value from a function. The general format is,

return(); 

return(parameter);


Example:

<html>
<body>
<script type=”text/JavaScript”>
function funexample(a, b)
{
return a+b;
}
document.write (funexample(10,20));
</script>
</body>
</html>


Explanation:

The function is being called from another javascript method document.write. funexample() is a function passing two arguments 10 and 20.

Where 10 is being passed into the function funexample() as ‘a ‘ and 20 is being passed into the function as ‘b’.  

Once they are both passed in it return the sum of the two-argument. “return” simply means that we will return something back to the method or function that called our function funexample(). 

As a result, you can return sent back 30. The final statement that executed was more like document.write(30).


Example 2:

<html>
<head>
<title>example2</title>
</head>
<body>
<h2>
<script type=”text/JavaScript”>
functionsum(a, b)
{
c= a+b;
return c;
}
d= sum(12,8);
document.write (“the returned value is :” + d);
</script>
</h2>
</body>
</html>

The output of the above program is:

the returned value is: 20


Recursive function:

Recursion refers to the situation, wherein function call themselves. In other words, there is a call to specific functions from within the same function. It is called a recursive function.

Example:

<html>
<head>
<title>recursive function</title>
</head>
<body>
<script type= “text/JavaScript”>
var num=5;
function fact(num)
{
if (num>1)
{
document.write(“fact=”+num*fact(num-1));
}
else
{
document.write(“fact=”+num);
}
}
</script>
</body>
</html>

The result of the above program is,

Fact=120

I hope you guys understand what is javascript functions and how to define and call javascript functions. If you have any queries or doubt or you know more information about this article then please comment down below. Thank you for reading and visiting my blog.
.