Title: Application and Transfer of Fundamental Concepts to other Programming Languages
1Application and Transfer of Fundamental Concepts
to other Programming Languages
2Some Other Programming Languages
3Fundamentals
- Editing, compilation and running programs
- Input/Output
- Variables
- Declaring
- Initializing
- Types
- Conditionals
- if/else
- Loops
- for
- while
4Introduction to C
- C is a structured programming language. A
disciplined approach to writing software using a
methodological approach. - Edit (pico, vi, emacs)
- Name files with a .c extension
- Compile
- cc filename.c
- Run
- If the compilation was successful a a.out file
is produced - To run just type a.out
5C Comments and main()
- Documentation/Comments
- C uses / / Style comments
- Every program contains a main() - a program
building block, a function - C programs contain one or more functions, one of
which must be a main - Every program in C begins executing at the
function main
6C Functions for input/output
- printf()
- Prints a sequence of characters to the screen
- Example printf(Enter an integer\n)
- scanf
- Takes input from the standard input (usually the
keyboard. Two arguments d and (address
operator) followed by the variable name - when combined with the variable name tells
scanf the location in memory in which the
variable should be stored. - Example
- scanf(d, myinteger)
- (c or s for chars, strings)
7C Input and Output
- include ltstdio.hgt (include at the beginning of
your program) - This tells the preprocessor to include the
contents of the standard input/output header file
(stdio.h) in the program. This should be included
in any file that uses any input/output functions
such as printf or scanf.
8C Variables
- Declaring variables
- (int, double, float, char , char)
- Example
- int counter, index, totalArray10
- Important to initialize all variables
- Example
- counter0
- index0
9C Operators
- Logical Operators
-
-
- Equality
- !
-
- Relational Operators
- lt, gt, gt, lt
10C Conditionals and Iteration
- if
- if/else
- while
- do/while
- for
11include ltstdio.hgt /This program asks the user
for input, stores the input in an integer array,
traverses the array and prints out the output.
/ main() int i,integer1, counter,
totalArray10 integer10 counter
0 while (counter lt 10) printf ("Enter
an integer\n") scanf ("d", integer1) print
f("You entered d\n", integer1) totalArraycoun
ter integer1 counter for
(i0ilt10i) printf("Array element d
is d\n", i, totalArrayi)
12include ltstdio.hgt /This program asks the user
for input, stores the input in an integer array,
traverses the array and prints out the output.
/ main() int i,integer1, counter,
totalArray10 integer10 counter
0 while (counter lt 10) printf ("Enter
an integer\n") scanf ("d", integer1) print
f("You entered d\n", integer1) totalArraycoun
ter integer1 counter for
(i0ilt10i) printf("Array element d
is d\n", i, totalArrayi)
13include ltstdio.hgt /This program asks the user
for input, stores the input in an integer array,
traverses the array and prints out the output.
/ main() int i,integer1, counter,
totalArray10 integer10 counter
0 while (counter lt 10) printf ("Enter
an integer\n") scanf ("d", integer1) print
f("You entered d\n", integer1) totalArraycoun
ter integer1 counter for
(i0ilt10i) printf("Array element d
is d\n", i, totalArrayi)
14include ltstdio.hgt /This program asks the user
for input, stores the input in an integer array,
traverses the array and prints out the output.
/ main() int i,integer1, counter,
totalArray10 integer10 counter
0 while (counter lt 10) printf ("Enter
an integer\n") scanf ("d", integer1) print
f("You entered d\n", integer1) totalArraycoun
ter integer1 counter for
(i0ilt10i) printf("Array element d
is d\n", i, totalArrayi)
15include ltstdio.hgt /This program asks the user
for input, stores the input in an integer array,
traverses the array and prints out the output.
/ main() int i,integer1, counter,
totalArray10 integer10 counter
0 while (counter lt 10) printf ("Enter
an integer\n") scanf ("d", integer1) print
f("You entered d\n", integer1) totalArraycoun
ter integer1 counter for
(i0ilt10i) printf("Array element d
is d\n", i, totalArrayi)
16include ltstdio.hgt /This program asks the user
for input, stores the input in an integer array,
traverses the array and prints out the output.
/ main() int i,integer1, counter,
totalArray10 integer10 counter
0 while (counter lt 10) printf ("Enter
an integer\n") scanf ("d", integer1) print
f("You entered d\n", integer1) totalArraycoun
ter integer1 counter for
(i0ilt10i) printf("Array element d
is d\n", i, totalArrayi)
17Perl
- What is Perl
- Perl is a "Practical Extraction and Report
Language". - Perl is a high-level, free-form (for the most
part), object oriented programming language. - Interpreted language
- Edit
- test.pl
- Compile Run
- perl test.pl
18Java vs. Perl
- for single line comments
- No compiling (interpreted)
- Running perl programs
- perl .pl
- Variable declaration (type is known)
- Scalar
- Arrays (You can mix all kinds of data types in an
array) - _at_arrayname()
- arrayname0
- Hash
19!/usr/bin/perl -w _at_MyArray() counter0 myin
teger 0 while (counter lt 10) print("Enter
an integer \n") myinteger ltSTDINgt chomp
(myinteger) MyArraycounter
myinteger counter for (i0ilt10
i) print("Array element i is
MyArrayi.\n")
20Perl Resources
- On-line Tutorials
- Web Developer's Virtual Library has tutorials and
reference for HTML, VRML, XML, CSS, CGI, Perl,
Java, JavaScript and much more
wdvl.internet.com. - Tom's Object-Oriented Perl Tutorial
http//language.perl.com/all_about/perltoot.html - Randy's Column on OO Perl http//www.stonehenge.
com/merlyn/UnixReview/col13.html - Perl Introduction
- http//www.devlearn.com/perl/perlintro.html
21C
- Tutorial
- http//www.cplusplus.com/doc/tutorial/tut1-1.html
22Python
- http//www.python.org/doc/current/tut/tut.html