Application and Transfer of Fundamental Concepts to other Programming Languages - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Application and Transfer of Fundamental Concepts to other Programming Languages

Description:

Compile. cc filename.c. Run. If the compilation was successful a 'a.out' file is produced ... vs. Perl # for single line comments. No compiling (interpreted) ... – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 23
Provided by: CCN4
Category:

less

Transcript and Presenter's Notes

Title: Application and Transfer of Fundamental Concepts to other Programming Languages


1
Application and Transfer of Fundamental Concepts
to other Programming Languages
  • MSTU 4031

2
Some Other Programming Languages
  • C
  • C
  • Perl

3
Fundamentals
  • Editing, compilation and running programs
  • Input/Output
  • Variables
  • Declaring
  • Initializing
  • Types
  • Conditionals
  • if/else
  • Loops
  • for
  • while

4
Introduction 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

5
C 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

6
C 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)

7
C 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.

8
C Variables
  • Declaring variables
  • (int, double, float, char , char)
  • Example
  • int counter, index, totalArray10
  • Important to initialize all variables
  • Example
  • counter0
  • index0

9
C Operators
  • Logical Operators
  • Equality
  • !
  • Relational Operators
  • lt, gt, gt, lt

10
C Conditionals and Iteration
  • if
  • if/else
  • while
  • do/while
  • for

11
include 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)
12
include 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)
13
include 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)
14
include 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)
15
include 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)
16
include 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)
17
Perl
  • 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

18
Java 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")
20
Perl 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

21
C
  • Tutorial
  • http//www.cplusplus.com/doc/tutorial/tut1-1.html

22
Python
  • http//www.python.org/doc/current/tut/tut.html
Write a Comment
User Comments (0)
About PowerShow.com