Basic Programming Laboratory

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Introduction and Course Outline

Basic Programming (CS 1000)

Sumanta Pyne

Computer Science and Engineering Department


National Institute of Technology Rourkela
pynes@nitrkl.ac.in

August 25, 2023

Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 1 / 19


Basic Computer Organization

Address Bus

Memory I/O
CPU

Data Bus

Read/Write
Control Bus

Figure: 1 Block Diagram of a Basic Computer

Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 2 / 19


Some Important Terminologies

Computer Design - Hardware development using the fundamentals of Digital Electronics.


Formulation of Computer Specifications
What hardware parts should be used and how the parts should be connected
Computer Organization - The way hardware components are interconnected with each
other to form a computer system.
Operation of hardware components
Inter connection of hardware components to form a computer system
Verification of computer parts operate as intended
Computer Architecture - Structure and behavior of the various functional modules of the
computer and how they interact to provide the processing needs of the user.
Instruction format and Instruction sets
Techniques for addressing memory
Specifications of processors and memory

Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 3 / 19


Von-Neumann’s stored computer architecture

Main Memory

Central Processing
Unit (CPU)
Accumulator
Arithmetic
Control Logic Unit
Unit

I/O Device

Figure: 2 Von-Neumann’s stored computer architecture

Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 4 / 19


Von-Neumann’s stored computer architecture
In 1945, von Neumann proposed the design of a new stored-program computer, the EDVAC (Electronic
Discrete Variable Computer)
Data and instructions are stored in a single read-write memory
The contents of this memory are addressable by location, without regard to the type of data
contained there
Execution occurs in a sequential fashion (unless explicitly modified) from one instruction to the
next
In 1946, von Neumann and his colleagues began the design of a new stored-program computer, referred
to as the IAS computer, at the Princeton Institute for Advanced Studies.
A main memory, which stores both data and instructions
An arithmetic and logic unit (ALU) capable of operating on binary data
A control unit, which interprets the instructions in memory and causes them to be executed
Input and output (I/O) equipment operated by the control unit
Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 5 / 19
Hardware and Software in Modern Computers
Application Softwares
S O F T W A R E
System Softwares
ALU, CU, Memory,
Bus and I/O devices

Combinational
and Sequential circuits

Logic gates

Resistors
Capacitors
Inductors
Diodes
Transistors
Wires

H A R D W A R E

Operating System, Assembler, Compiler,


Interpreter, Linker, Loader,
Debugger, Text Editor
MySQL, MS-Word, Paint, Latex, NS2
Media Player, Games, Browser,
OpenGL, SPICE

Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 6 / 19


Why Is Programming Important?

Computer programming has an integral role in our world


Computer programs not only running in cell phones and smart TV
space-crafts, satellites
cardiac-pacemakers, robotic surgery, medical imaging
chemical reactions in laboratory and plants
safety in nuclear power plants
guided missile systems
auto pilot
video conferencing
railway reservation system
computer-aided design & manufacturing (CAD/CAM)

Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 7 / 19


What Is a Program?

a group of logical, mathematical and sequential functions


when they are grouped, these functions perform a task
program focuses on different types of tasks
each program instruction commands the machine
implementation of an algorithm
for given input algorithms produce correct output in finite time
a program may run for infinite time or produce incorrect output
all programs are not algorithms

Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 8 / 19


History of Programming Languages

First generation (programming) language (1GL)


machine level languages
used to program first-generation computers
instructions made of binary numbers, represented by 1s and 0s
difficult to interpret and learn by the human programmer
Secong generation (programming) language (2GL)
assembly languages
more human readable
Third-generation programming languages (3GL)
High-level programming languages or
more machine-independent and more programmer-friendly
first introduced in the late 1950s
Fortran, ALGOL, BASIC, C, COBOL, Fortran, Java, and Pascal

Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 9 / 19


History of Programming Languages
Fortran, 1957 - scientific computing
Lisp, 1958 - AI research
ALGOL, 1958 - standard method for algorithm description
COBOL, 1959 - common business-oriented language
BASIC, 1964 - for students in fields other than science/mathematics
Prolog, 1972 - AI and computational linguistics
C, 1972 - general-purpose, procedural computer programming
Pascal, 1970 - structured programming and data structuring
C++, 1985 - extension of C, object oriented programming
Perl, 1988 - interpreted high-level general-purpose programming
Python, 1991 - interpreted high-level general-purpose programming
Ruby, 1995 - interpreted high-level general-purpose programming
Java, 1995 - general-purpose, object oriented programming
JavaScript, 1995 - website development
C#, 2000 - general-purpose, multi-paradigm programming
Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 10 / 19
History of Programming Languages

Fourth-generation programming languages (4GL)


advancement upon third-generation programming languages (3GL)
Support for
database management
report generation
mathematical optimization
GUI development
web development
Fifth-generation programming languages (5GL)
based on problem-solving using constraints given to the program
Constraint-based programming
Logic programming
Uses techniques from AI, CS and OR
Prolog, OPS5, Mercury, ICAD, Oz

Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 11 / 19


Important Computer Programming Languages to Learn
Computer/Electrical/Electronics Engineers
C, C++, Java, Python, Matlab
Assembly languages - Intel 8086x, ARM
Embedded C
SPICE, Verilog/VHDL - circuit design/hardware development
Physicists
Fortran, C, C++
Mechanical/Industrial/Civil Engineers
Fortran, C, C++, AutoCAD, Civil 3D
Other engineers/Mathematicians
Fortran, C, C++, Java, Python, Matlab, R
For applications of AI and machine learning in any discipline
Prolog, Python, Matlab
Robotics
Assembly languages - Intel 8086x, ARM
Prolog, Python, Embedded C
Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 12 / 19
A brief History of C language
Origin of C is closely tied to development of Unix OS
Implemented in assembly language on PDP-7
By Dennis Ritchie & Ken Thompson
Thompson created B from BCPL systems programming language
In 1972, Ritchie started to improve B
adding data typing for variables, resulted a new language C
K&R C
Kernighan and Dennis C standard
released in 1978, also known as C78
Features added
Standard I/O library
long int and unsigned int data types
compound assignment operators, =op
Standard C, 1985
ANSI C, 1989
ISO C, 1995
Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 13 / 19
Syllabus

1 C fundamentals
2 Operators and Expressions
3 Data Input and Output
4 Control Statements
5 Functions
6 Program Structure
7 Arrays
8 Pointers
9 Structures and Unions
10 File Handling

Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 14 / 19


Text and Reference Books

Essential Reading
Byron S. Gottfried, Programming with C, Schaum’s Outline Series, Tata Mc-Graw Hill, 3rd
Ed.
Yashavant Kanetkar, Let Us C, BPB Publicatons, 13th Ed, 2015.
Supplementary Reading
Brian Kernighan and Dennis Ritchie, The C Programming Language, Pearson Education, 2nd
Ed.
Herbert Schildt, C: The Complete Reference, Mc-Graw Hill, 4th Ed.
E. Balagurusamy, Programming in ANSI C, Tata Mc-Graw Hill, 3rd Ed.

Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 15 / 19


Evaluations and Marks Distribution

Assignments - 50%
Quiz - 25%
Viva voce - 25%

Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 16 / 19


Rules and Regulations
File name for assignments
A student’s roll number is 118EC0123
Program file name of for problem 1 of assignment 1
a1 p1 118ec0123.c
Program file name of for problem 5 of assignment 12
a12 p5 118ec0123.c
For every input statement, write an immediate print statement
a printf will follow a scanf
Follow proper indenting for better readability
Write a comment at first line of the program file/function
mention what it does - input and output
Write a comment after each statement
mention what it does - operation
Use meaningful identifier names
variables - SI = (P*R*T)/100
functions - get SI
arrays - mat[5][5]
Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 17 / 19
Software for C programming

MS Windows
Dev-C++
A free, portable, fast and simple C/C++ IDE
https://sourceforge.net/projects/orwelldevcpp/
Linux
GCC, the GNU Compiler Collection
https://gcc.gnu.org/
Latest version - GCC 11.2 released [2021-07-28]
Mac
Code::Blocks is a free C, C++, and Fortran IDE
Code::Blocks 20.03
https://macdownload.informer.com/codeblocks/

Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 18 / 19


Thank you

Sumanta Pyne (NITRKL) Autumn 2021, Introduction August 25, 2023 19 / 19

You might also like