Thursday, 17 October 2013

Declaration and Definition of a Function

Declaration and Definition of a Function


Declaration and definition are two different things. Declaration is the prototype of the function, that includes the return type, name and argument list to the function and definition is the actual function code. Declaration of a function is also known as signature of a function. As we declare a variable like int x; before using it in our program, similarly we need to declare function before using it. Declaration and definition of a function can be combined together if we write the complete function before the calling function. Then we don’t need to declare it explicitly. If we have written all of our functions in a different file and we call these functions from mani() which is written in a defferent file. In this case, the main( ) will not be compiled unless it knows about the functions declaration. There we write the declaration of functions before the main() function. Function declaration is a one line statement in which we write the return type, name of the function and the data type of arguments. Name of the arguments is not necessary. The definition of the function contains the complete code of the function. It starts with the declaration statement with the addition that in definition, we do write the names of the arguments. After this, we write an opening brace and then all the statements, followed by a closing brace.

If the function square is defined in a separate file or after the calling function, then we need to declare it:

Delaration:

Double square (double);


Definition:
Double square (double number)
{
            return (my_num * my_num);
}

Here is the complete code to elaborate the topic more:

#include <iostream.h>

//Here we are declaring the function.
double square(double);

main(){
            double num, result;
            result = 0;
            num = 0;
            cout<<”Please Enter a Number to calculate the square of.”;
            cin>>num;
            //now we are going to call the function
            result = square (num);
            cout <<”The square of ”<<num<<”is”<<result;
            // function to calculate the square of a number
            double square ( double num)
{
                        return (num * num ) ;
}

}

A function in a calling program can take place as a stand-alone statement, on hand side of a statement. This can be a part of an assignment expression.




Functions in C and C++ Programming

Functions in Programming 

The functions are like subtasks. They receive some information, do some procedure and provide a result. Functions are invoked through a calling program. Calling program does not require to know what the function is doing and how it is performing its task. There is a specific function-calling methodology. The calling program calls a function by giving it some information and receives the result.
We have a main () in every C program. ‘main()’ is also a function. When we write a function, it must start with a name, parentheses, and surrounding braces just like with main(). Functions are very important in code reusing.
There are two categories of functions:
a)      Functions that return a value
b)      Functions that do not return a value
Suppose, we have a function that calculates the square of an integer such that function will return the square of the integer. Similarly we may have a function which displays some information on the screen so this function is not supposed to return any value to the calling program.
A Function Structure
The declaration syntax of a function is as follows:
Return-value-type function-name (argument-list)
{
            Declarations and statements
}

The first line is the function header and the declaration and statement part is the body of the function.

Goto Statement in Programming

“goto” Statement

Up to now we have covered the basic programming constructs. These include sequences, decisions and repetition structures (i.e. loops). In sequences, we use the simple statements in a sequence i.e. one after the other. In decisions construct we use the if statement, if/else statement, the multi way decision construct (i.e. the switch statement). And in repetition structures, we use the while, do-while and for loops.
Sometime ago, two computer scientists Gome and Jacopi proved that any program can be written with the help of these three constructs (i.e. sequences, decisions and loops).

There is a statement in the computer languages COBOL, FORTRAN and C. This statement is goto statement is used to jump the control anywhere (back and forth) in a program. In legacy programming, the programs written in COBOL and FORTRAN languages have many unconditional branches of execution. To understand and decode such programs that contain unconditional branches is almost impossible. In such programs, it is very difficult, for a programmer, to keep the track of execution as the control jumps from one place to the other and from there to anywhere else. We call this kind of traditional code as spagatti code. It is very difficult to trace out the way of execution and figure out what the program is doing. And debugging and modifying such programs is very difficult. When structured programming was started, it was urged not to use the goto statement. Though goto is there in C language but we will not use it in our programs. We will adopt the structured approach. All of our programs will consist of sequences, decisions and loops.

Continue Statement in C Programming

Continue Statement

(continue statement in c, continue statement in java, continue statement python, continue statement php, continue statement in c programming)


There is another statement relating to loops. This is the continue statement. Sometimes we have a lot of code in the body of a loop. The early part of this code is common that is to be executed every time (i.e. in every iteration of loop) and the remaining portion is to be executed in certain cases and may not be executed in other cases. But the loop should be continuous. For this purpose, we use the continue statement. Like the break statement, the continue statement is written in a single line. We write it as
                        Continue;
 The continue forces the immediate next iteration of the loop. So the statements of the loop body after continue are not executed. The loop starts from the next iteration when a continue statement is encountered in the body of a loop. One can witness very subtle things while using continue.
Consider the while loop. In while loop, we change the value of the variable of while condition so that it could make the condition false to exit the loop. Otherwise, the loop will become an infinite one. We should be very careful about the logic of the program while using continue in a loop. Before the continue in a loop. Before the continue statement, it is necessary to change (increment/decrement) the value of the variable on which the while condition depends. Similarly it is same with the do-while loop. Be careful to increment or decrement the conditional variable before the continue statement.
In for loop, there is a difference. In a while loop when continue is encountered, the control goes to the while statement and the condition is checked. If condition is true the loop is executed again else the loop exits. In a for loop, the three things i.e. initialization, condition and increment/decrement are enclosed together as we write
for (counter_variable = 0;  counter_variable <=5; counter_variable++).

In the for loop when a continue is encountered, the counter_variable (i.e. loop variable) is incremented at first before the execution of the loop condition. Thus, in for loop the increment to the loop variable is built in and after continue the next iteration of the loop is executed by incrementing the loop variable. The condition is checked with the incremented value of the loop variable. In while and do-while loop, it is our responsibility to increment the value of the loop variable to test the condition. In a for loop, the continue automatically forces this increment of value before going to check the condition. 

For What Purpose JavaSript and Jscript are Used | What Kinds of Things Can JavaScript and Jscript Do

For What Purpose JavaSript and Jscript are Used | What Kinds of Things Can JavaScript and Jscript Do

In mid 1990s the HTML or Hypertexttransfer protocol made people to use internet and create Web Pages to display some static contents. But over the years, HTML has lost much of its gleam. Markup languages are great for formatting the display of text, but they lack the capability to interact with visitors. People surfing the Internet have come to expect and demand more than a static presentation of data from Web sites. If you want people to visit your Web site, to enjoy themselves, and to return again, then you have to find ways to make it more interesting. One of the best ways to do this is with JavaScript. The use of JavaScript will make it more attractive for the user.
JavaScript provides your Web pages with the ability to do a lot of exciting things. The following list provides a preview of what you will learn how to do with JavaScript here in Programming Dost.
Ø  Show pop-ups  that display and gathers information from visitors
Ø  Make rotating banners
Ø  Open new windows
Ø  Redirect people using older browsers to non-JavaScript HTML pages
Ø  Identify the browsers and plug-ins being used by people visiting your Web site
Ø  Validate forms and package their contents in an e-mail message
Ø  Do simple animations such as rollovers
Ø  Use greater control over HTML frames and forms
Ø  Take control of the status bar and create scrolling messages
JavaScript can do a lot of different and exciting things. However, there is one thing that it cannot do. JavaScripts cannot run outside of the browser. This "limitation" helps make JavaScript more secure because users do not have to worry about somebody writing a JavaScript that might erase their hard drive or read their address book and extract private information.

NOTE
This JavaScript tutorial focuses on client-side scripting. By client-side scripting I means scripts that execute within the browsers of people that visit your Web pages. A server-side version of JavaScript also exists.This version of JavaScript is designed to run on Web servers and is used by professional Web site developers to create scripts that provide dynamic content based on information received from visitors, as well as from information stored in a server-side database

Like JavaScript, JScript is limited by the constraints of its implementation environment. When run by the WSH, JScripts don't have access to Web content. They don't work with HTML frames or forms. Instead, the WSH opens up a whole new execution environment that provides JScripts with the capability to access both local and network computer resources. In this context, JScript's primary reason for existing is to facilitate the development of scripts that automate tasks.
JScript provides an especially powerful tool for developing scripts that can automate repetitive and mundane tasks or tasks that are complicated and prone to error when performed manually. The following list provides a preview of what you will learn how to do with JScript in this book.
v  Make and configure desktop shortcuts
v  Produce text reports and log files
v  Manage the Windows file system by copying, moving, and deleting files and folders
v  Manage operating system resources such as Windows services, the registry, and event logs
v  Create and administer user accounts
v  Manage local and network resources such as network printers and disk drives
v  Work together with and control other applications


Introduction to JavaScript and Introduction to Jscript

Introduction to JavaScript and Introduction to Jscript

JavaScript in a programming language and it is specifically made for the web browsers to use. It is used in HTML to create interactivity between the web pages. There is a very similar language called Jscrpit which is made by Microsoft. Microsoft has provided a version of Jscript for the desk top users it means for the local use in a machine and it can be used with the help of Windows Script Host (WSH).
The Windows Script Host (WSH) is an optional scripting environment that supplies Windows operating systems with the capability to run scripts directly on the Windows desktop. Both languages support the same collection of programming statements.
JavaScript and JScript are interpreted languages. This means that scripts written in these languages are not compiled before they are executed (as is typical of most programming languages such asC++). Every script statement must first be converted into binary code (a computer language made up of 0s and 1s that the computer can understand) in order to execute. Unlike complied programs, which are converted to binary code in advance, JavaScript and JScript statements are processed at execution time. This means that they run a little slower than compiled programs. The upside is that this makes writing and testing JavaScripts and JScripts very intuitive and easy. You simply write a few lines of code, save your script, and test it without having to stop and compile it into executable code.
Both JavaScript and Jscript are object-based scripting languages not truly object oriented languages. They have almost everything as object. Everything in JavaScript is an object, for JavaScript a browser, a window, a button etc are objects. JScript has access to a different set of objects. For example, JScript has the capability to access objects such as files, drives, and printers.
Every object has properties, and you can use JavaScript and JScript to manipulate these properties. For example, with JavaScript you can change the background color of a browser window or the size of a graphic image. In addition to properties, objects have methods. Methods are the actions that objects can perform. For example, JavaScript can be used to open and close browser windows. By manipulating their properties and executing methods, you can control objects and make things happen.
JavaScripts support event-driven programming. An event is an action that occurs when the user does something such as click on a button or moves the pointer over a graphic image. JavaScript enables you to write scripts that are triggered by events. Did you ever wonder how buttons dynamically change colors on some Web sites when you move the mouse over them? It's simply a JavaScript technique known as a rollover. The event is the mouse moving over the button (object). This triggers the execution of an event handler, which is a collection of JavaScript statements that replaces the button with another one that uses a different color.

JavaScripts and JScripts that run inside Web browsers have access to objects placed on Web pages. On the other hand, JScripts that run within the WSH have access to desktop resources such as toolbars, files, printers, and the Windows registry.

What is JavaScript | JavaScript Programming Language | JavaScript History

JavaScript History

JavaScript is a powerful scripting dialect that, when blended with HTML, permits you to create stimulating and mighty world wide web pages. You can use these world wide web sheets to run a small enterprise or to share data with family and friends over the Internet. JScript is a Microsoft implementation of JavaScript that can be utilized as a scripting language for automating repetitive or convoluted desktop and system jobs.
What you are likely asking yourself is, "Can I actually discover to program utilizing JavaScript and JScript in a single weekend?" The response is "Yes!" I am not promising that you will become a programming guru in just a couple of days, but if you will dedicate a full weekend to this book and pursue along with its demonstrations, you will be adept to write your own JavaScripts and JScripts. In no time you will be adept to make dramatic improvements to your world wide web sheets as well as evolve scripts that automate any number of Windows desktop tasks.
Syntactically, JavaScript and JScript are virtually equal. So by learning how to compose JavaScripts, you are furthermore learning how to work with JScript as well. Where the two languages disagree is in the environments in which they execute. JavaScripts are embedded interior HTML sheets and run by world wide web browsers. JScripts, on the other hand, are written as simple text files that are performed exactly from the Windows desktop by the Windows Script owner or WSH.
JavaScript is a versatile language. It can be utilized to create meal lists, validate forms, supply interactive calendars, mail the current day's headlines, produce background consequences on a world wide web page, track a visitor's annals on your site, and play games, amidst numerous other things. That's likely why it's one of the most popular dialects on the World broad world wide web.
Netscape conceived JavaScript in 1995. initially called "LiveScript," it was conceived to make Web pages more interactive. In the beginning the language was inundated with security problems which, for the most part, have been overcome.