Docsity

Comparing Programming Languages: C/C++, Java, Fortran, Visual Basic, Ada, Pascal, Study notes of Computer Science

Toggle sidebar
bg1
Other Computing Languages
Although the Comp 106 course uses the C++ language for programming, the basic programming
ideas can be readily generalized to other programming languages. In particular, there is very little
difference between the C++ language elements learned in a beginning C++ course and the
similar elements in C. The main difference is the input/output functions. Different functions are
used in C. Libraries such as iostream and fstream (and the corresponding input and output
techniques, using cin, cout, and their equivalents for file input and output, are not used in C.
Instead the output routines are contained in a library known as stdlib.h and those routines have a
completely different form. Also, the C language does not have classes or references. Passing
variables by reference is a bit more complex in C. However the basic structures of if statements,
for loops, while loops and case statements is the same in C as it is in C++.
The attached table shows a variety of basic statements in several higher level languages. This
table illustrates the similarities and differences among the various languages. The main similarity
is that the basic control structures for choice and looping exist in all languages. All languages
require the specification of the data types for the individual variables and the declaration of
arrays. No object-oriented commands are included here.
The differences lie in the syntax that each language uses. Programmers who are familiar with
one language will usually not have any difficulty reading programs in another language.
However, it is easier to write code in the language that you use most frequently. Coding in a
language that a programmer uses only infrequently will be time consuming because the
programmer will not be intimately familiar with all the syntactical details of the language.
The languages that are compared on the following table are listed below:
C/C++ C++ is the language used in this course and is a major programming language in
use today for engineering and computer science applications, particularly in
computer operating systems and graphical user interfaces. C is used in programs
for some firmware devices.
Java Java is similar to C++; it is intended to be a platform-independent language for
use in internet browser applications.
Fortran 95 Fortran was the first higher-level language and is still widely used in large scale
numerical analysis programs for engineering systems.
Visual Basic Basic was intended to be a simple language for instruction in computer
programming. Visual Basic, by Microsoft, has become an important language for
user interfaces and as the macro language in Microsoft programs such as Excel.
Ada The U. S. Department of Defense developed this high-level language for a wide
range of applications including simulation programs and real-time computer
systems.
Pascal This was designed as a simple higher-level language to illustrate the basic
programming constructs. It once had wide use in education.
docsity.com
pf3

Partial preview of the text

Download Comparing Programming Languages: C/C++, Java, Fortran, Visual Basic, Ada, Pascal and more Study notes Computer Science in PDF only on Docsity!

Other Computing Languages

Although the Comp 106 course uses the C++ language for programming, the basic programmingideas can be readily generalized to other programming languages. In particular, there is very little

difference between the C++ language elements learned in a beginning C++ course and thesimilar elements in C. The main difference is the input/output functions. Different functions are

used in C. Libraries such as iostream and fstream (and the corresponding input and outputtechniques, using cin, cout, and their equivalents for file input and output, are not used in C.

Instead the output routines are contained in a library known as stdlib.h and those routines have acompletely different form. Also, the C language does not have classes or references. Passing

variables by reference is a bit more complex in C. However the basic structures of if statements,for loops, while loops and case statements is the same in C as it is in C++.

The attached table shows a variety of basic statements in several higher level languages. Thistable illustrates the similarities and differences among the various languages. The main similarity

is that the basic control structures for choice and looping exist in all languages. All languagesrequire the specification of the data types for the individual variables and the declaration of

arrays. No object-oriented commands are included here.

The differences lie in the syntax that each language uses. Programmers who are familiar withone language will usually not have any difficulty reading programs in another language.

However, it is easier to write code in the language that you use most frequently. Coding in alanguage that a programmer uses only infrequently will be time consuming because the

programmer will not be intimately familiar with all the syntactical details of the language.

The languages that are compared on the following table are listed below:

C/C++ C++ is the language used in this course and is a major programming language inuse today for engineering and computer science applications, particularly in

computer operating systems and graphical user interfaces. C is used in programsfor some firmware devices.

Java Java is similar to C++; it is intended to be a platform-independent language foruse in internet browser applications.

Fortran 95 Fortran was the first higher-level language and is still widely used in large scalenumerical analysis programs for engineering systems.

Visual Basic Basic was intended to be a simple language for instruction in computerprogramming. Visual Basic, by Microsoft, has become an important language for

user interfaces and as the macro language in Microsoft programs such as Excel.

Ada The U. S. Department of Defense developed this high-level language for a widerange of applications including simulation programs and real-time computer

systems.

Pascal This was designed as a simple higher-level language to illustrate the basicprogramming constructs. It once had wide use in education.

docsity.com

Statements in Various Higher Level Languages

Type ofstatement

C/C++

Java

Fortran

Visual Basic

Ada

Pascal

Syntax for singlestatement

May extend overmultiple lines. Ends ina semicolon.

May extend overmultiple lines. Ends ina semicolon.

Generally each line isone statement. Usean ampersand (&) atthe end of a line toextend a statementover multiple lines.

Generally each line isone statement. Usean underscore (_) atthe end of a line toextend a statementover multiple lines.

May extend overmultiple lines. Ends ina semicolon.

May extend overmultiple lines. Ends ina semicolon.

Statementblocks

Delimited by curlybrackets, { and }.

Delimited by curlybrackets, { and }.

No delimitationrequired. Codestructures providedelimitation.

No delimitationrequired. Codestructures providedelimitation.

No delimitationrequired. Codestructures providedelimitation.

Delimited by

begin

at

the start and

end

at

the end.

Main programstructure

void main(){ statements }

void main(){ statements }

program main statements end program main

Sub main() statements End Sub

procedure main isbegin statements end main

program main; statements end.

Integer datatypes

intshort intlong intunsigned int

byteshortintlong

integerinteger(kind=) where denotesmaximum size

IntegerLong

INTEGERLONG_INTEGER

ByteShortIntIntegerWordLongInt

real data types

floatdoublelong double

floatdouble

realreal(kind=) where denotesprecision

SingleDouble

FLOATSHORT_FLOATLONG_FLOAT fixed-point types

SingleRealDoubleExtended

logical orboolean datatypes

bool

boolean

logical

Boolean

BOOLEAN

Boolean

data type forsingle characters

char

char

character

(LEN=1)

String

CHARACTER

Char

data type for n-character strings

use array of char

character

(LEN=n)

String

array of characters

array of characterstype

String

in Turbo

array notation

a[j][k]

a[j][k]

a(j,k)

a(j,k)

a(j)(k)

a[j][k]

if statementswith singlestatement

if^ (x

)^ y

= x;

if

(x^

< 0^

)^ y^

= x;

if

(x^

< 0^

)^ y^

= x^

If^ x <

0 Then

y=x

if^ x <

0 theny := x end^

if;

if^ x <

0 then

y :=

x;

docsity.com