Introduction To PPS

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 74

MALLA REDDY ENGINEERING COLLEGE FOR WOMEN

Autonomous Institution, UGC, Govt. of India


Programmes Accredited by NBA
Accredited by NAAC with A+ Grade
Affiliated to JNTUH, Approved by AICTE, ISO 9001:2015 Certified Institute
Maisammaguda (V), Dhullapally (Post), (Via) Kompally, Medchal Malkajgiri Dist. T.S-500100

PROGRAMMING FOR PROBLEM SOLVING


(B.TECH I YEAR - I SEM)
COURSE OBJECTIVES
 To understand the various steps in program development.

 To learn the syntax and semantics of C programming and Python.

 Understand Lists, Dictionaries and Tuples in Python.

 To learn the usage of structured programming approach in C


Programming.

2
COURSE OUTCOMES
 To code and test a given logic in C programming language.

 To use arrays, pointers, strings and structures to write C programs.

 To decompose a problem into functions and to develop modular


reusable code.

 Examine Python syntax and semantics and be fluent in the use of


Python flow control and functions.

 Create, run and manipulate Python Programs using core data


structures like Lists, Dictionaries.
3

 Demonstrate proficiency in handling strings and file Systems.


SYLLABUS
UNIT I
Introduction to C Programming: Structure of a C program, Identifiers,
Variables (with data types and space requirements), Operators, Precedence
and Expression evaluation, Type conversion.

UNIT II
Conditional Branching and Loops: Writing and Evaluation of Conditionals
with If, If-Else, else-if ladder Switch-Case, goto, Iteration with For, While,
Do While Loops

Arrays: One-Two-Dimensional Arrays, Creating, Accessing and


Manipulating Elements of Arrays.

Strings: Introduction To Strings, Handling Strings as Array of Characters,


4
Basic String Functions available in C (Strlen, Strcat, Strcpy, Strstr Etc.),
Arrays of Strings.
UNIT – III

Functions: Declaring a function, Parameters and return type of a


function, passing parameters to functions, Recursive Functions,
Storage Classes.

Structures: Defining structures, initializing structures, unions.

Pointers: Idea of pointers, Defining pointers, Pointer to Pointer,


Dynamic Memory Management functions (DMA)

File Handling in C: Creating and Reading and writing text and


binary files, Appending data to existing files, Writing and reading
structures using binary files, Random access using fseek, ftell and5
rewind functions.
UNIT – IV

Introduction to Python Programming: Modes: Interactive Mode,


Scripting Mode, Identifiers, Keywords, Variables, Comments, Lines
and Indentations, Quotations, Assigning Values to Variables, Data
Types in Python, Mutable Vs Immutable, Fundamental Data Types:
int, float, complex, bool, str, Advanced Data Types (List, Tuple,
Dictionary, set, etc..).

Decision Making Statements: if Statement, if-else Statement, elif


Statement. Looping Statements: For and While loops, Nested loops,
Using else Statement with loops, Control Statements: break
Statement, continue Statement, Pass Statement.

Python Slicing & Indexing: Forward Direction Slicing with +ve6


Step, Backward Direction Slicing with -ve Step, Built-in String
Functions.
UNIT – V

Python Functions: Creating a Function, Function Calling,


Parameters in Function, Types of Arguments, Scope of Variables,
Python Built-in Functions. Python Lambda Functions.

Python File Handling: Opening a File, Reading the File, Read


Lines of the File, Writing the File, creating a New File Using with
Statement with Files, File Pointer Position, Modifying File Pointer
Position Renaming the File & Removing the File, Writing Python
Output to the Files File Related Methods.

7
CONTENTS
 Introduction to Languages
 History and Applications of C
 Importance and Features of C
 Algorithm, flowchart and Basic Structure of C
 Create, Compile and Execute C program
 Introduction to Python programming
 Histroy and Features of Python
 Applications of Python
 Existing programming vs Python programming 8
INTRODUCTION TO LANGUAGES

What is Language?

What is Programming Language?

What is the need of Computer


language?

9
WHAT IS LANGUAGE?

The definition of language is speech or other


forms of communication.
 An example of language is words spoken.
 An example of language is words read in a
book.
 An example of language is people using their
hands to express themselves. 10
PROGRAMMING LANGUAGE
A programming language is a set of commands,
instructions, and other syntax use to create a
software program.

 Languages that programmers use to write code are


called "high-level languages."

 This code can be compiled into a "low-level


language," which is recognized directly by the
computer hardware. 11
TYPES OF PROGRAMMING LANGUAGES

Machine language

 Natural language of a particular computer


 Consists of strings of numbers(1s, 0s)
 Instruct computer to perform elementary operations one at
a time
 Machine dependant

12
Assembly Language
 English like abbreviations

 Translators programs called “Assemblers” to convert


assembly language programs to machine language.

 E.g. add overtime to base pay and store result in gross pay

LOAD BASEPAY

ADD OVERPAY

STORE GROSSPAY

13
High-level languages

 To speed up programming even further.

 Single statements for accomplishing substantial tasks.

 Translator programs called “Compilers” to convert high-level


programs into machine language.

 E.g. add overtime to base pay and store result in gross pay
grossPay = basePay + overtimePay

14
HOW MANY TYPES OF APPLICATIONS
POSSIBLE USING COMPUTER
LANGUAGE

Standalone applications
Must be installed in computer
Compatible for single operating System

Web based applications


Through browser

15
WHAT IS C

C is a procedural programming language as well as a

general-purpose programming language that was developed

by Dennis Ritchie at AT&T’s Bell laboratories in 1972

16
 It is an amazing and simple language that helps us

develop complex software applications with ease.

 It is considered as the mother of all languages. C is a

high-level programming language that provides support to

a low-level programming language as well.

 It was mainly developed as a system programming


17
language to write an operating system.
History of C

18
HISTORY
 The root of all modern languages is ALGOL (introduced in
1960s).
 ALGOL uses a structured programming.
 ALGOL is popular in Europe.
 In 1967, Martin Richards developed a language called
BCPL
(Basic Combined Programming Language).
 Primarily BCPL is developed for system software.
 In 1970, Ken Thompson created a new language called B
 B is created for UNIX os at Bell Laboratories.
 Both BCPL and B were “typeless” languages. 19
 In 1972 Dennis Ritchie at Bell Labs wrote C and in 1978 the
publication of The C Programming Language by
Kernighan & Ritchie caused a revolution in the computing
world.

 In 1983, the American National Standards Institute (ANSI)


established a committee to provide a modern, comprehensive
definition of C. The resulting definition, the ANSI standard,
or "ANSI C", was completed in late 1988.

20
HISTORY

21
APPLICATIONS OF C

22
APPLICATIONS OF C

23
WHY C STILL USEFULL?
C provides:

 Efficiency, high performance and high quality softwares(s/w)

 flexibility and power

 many high-level and low-level operations  middle level

 Stability and small size code

 Provide functionality through rich set of function libraries

24
 Gateway for other professional languages like C  C++  Java
C is used:

 System software Compilers, Editors, embedded systems

 data compression, graphics and computational geometry,


utility programs

 databases, operating systems, device drivers, system level


routines

 Also used in application programs

25
IMPORTANCE OF ‘C’

26
IMPORTANCE OF ‘C’
 Rich set of built-in functions

 Operators can be used to write any complex program.

 The C compiler combines the capabilities of an assembly language with


the features of a high-level language.
 It is well suited for writing both system software and business
packages.
 Due to variety of data types and powerful operators programs
written in C are efficient and fast.

 Ability to extend itself.

 C is a Structured Programming Language (requiring the user to think


of a problem in terms of function modules or blocks). 27

 C is highly portable.
FEATURES OF C

28
FEATURES OF C

29
 Portability – It refers to the usability of the same fragment of
code in different environments. C programs are capable of being
written on one platform and being run on another with or without
any modification.

 Speed– Since it is a compiler-based language, it is comparatively

faster than other programming languages like Python, which are

interpreter based.

30
 A compiler considers the entire program as input and thereby
generates an output file with the object code whereas an
interpreter takes instruction by instruction as input and then
generates an output but does not generate a file
 Simple and efficient – The syntax style is easy to comprehend.
We can use C to design applications that were previously
designed by assembly language.

 Memory Management – It allows you to allocate memory at the


runtime, that is, it supports the concept of dynamic memory
31
allocation.
 Dynamic Memory Allocation- When you are not sure about the
memory requirements in your program and want to specify it at the run
time, that is, when you run your program, you can do it manually.
 Pointers – C language provides a pointer that stores the memory
address as its value. Pointers are useful in storing and accessing data
from memory.

 Case Sensitive – It is pretty clear that lowercase and uppercase


characters are treated differently in C. It means that if we write “if” and
“If”, both of them would give different meanings in C. The ‘i’ in “if” is
in lowercase format whereas, the ‘I’ in If is in uppercase format. 32
 Compiler Based – C is a compiler based language, that is, to
execute a code we first need to compile it.

 Structure Oriented/modular –C is a structured


programming language. This means we can divide our code
and task within a function to make it interactive. These
functions also help in code reusability.

33
COMPUTER SOFTWARES
 Software is a set of programs, which is designed to perform a
well-defined function. A program is a sequence of
instructions written to solve a particular problem.

 There are three types of software −


• System Software
• Utility software
• Application Software

34
SYSTEM SOFTWARE
 The system software is a collection of programs designed to
operate, control, and extend the processing capabilities of the
computer itself.
 System software is generally prepared by the computer
manufacturers.
 These software products comprise of programs written in low-
level languages, which interact with the hardware at a very basic
level.
 System software serves as the interface between the hardware
and the end users.
 Some examples of system software are Operating System,
Compilers, Interpreter, Assemblers, etc.
35
FEATURES OF A SYSTEM SOFTWARE

 Close to the system


 Fast in speed
 Difficult to design
 Difficult to understand
 Less interactive
 Smaller in size
 Difficult to manipulate
 Generally written in low-level language

36
UTILITY SOFTWARE
 Utility software is part of the system software and
performs specific tasks to keep the computer running.
Utility software is always running in the background.
Examples of utility software are security and optimization
programs.

 Security programs include anti-virus software that scans


and removes viruses. Most computers will include some
sort of anti-virus software, but we can add our own.

 Optimisation programs can include tools for system clean-


up, disk defragmentation, and file compression. These
tools are typically installed as part of the operating system.
37
They have access to the hard drive to keep it tidy.
APPLICATION SOFTWARE
 Application software products are designed to satisfy a particular
need of a particular environment.

 All software applications prepared in the computer lab can come


under the category of Application software.

 Application software may consist of a single program, such as


Microsoft's notepad for writing and editing a simple text.

 It may also consist of a collection of programs, often called a


software package, which work together to accomplish a task, such
as a spreadsheet package.
38
FEATURES OF APPLICATION SOFTWARE
 Close to the user
 Easy to design
 More interactive
 Slow in speed
 Generally written in high-level language
 Easy to understand
 Easy to manipulate and use
 Bigger in size and requires large storage space

39
EXAMPLES OF APPLICATION SOFTWARE

 Railways Reservation Software


 Microsoft Office Suite Software
 Microsoft Word
 Microsoft Excel
 Microsoft PowerPoint
 Payroll Software
 Student Record Software
 Income Tax Software

40
ALGORITHM
An algorithm is a mathematical process to solve a problem using a
finite number of steps.
Properties of Algorithms
 Input -An algorithm has input values from a specified set.

 Output -From each set of input values an algorithm produces

output values from a specified set.


 Definiteness -The steps of an algorithm must be defined precisely.

 Correctness -An algorithm should produce the correct output

values for each set of input values.


 Finiteness -An algorithm should produce the desired output after a

finite (but perhaps large) number of steps for any input in the set.
 Effectiveness -It must be possible to perform each step of an

algorithm exactly and in a finite amount of time.


 Generality -The procedure should be applicable for all problems

of the desired form, not just for a particular set of input values. 41
ALGORITHM : ADDITION OF TWO NUMBERS

 Step 1 : Start
 Step 2 : Declare variables num1, num2 and sum.
 Step 3 : Read values num1 and num2.
 Step 4 : Add num1 and num2 and assign the result to sum.

sum←num1+num2
 Step 5 : Display sum
 Step 6 : Stop
42
FLOWCHART

A flowchart can also be defined as a diagrammatic/graphical


representation of an algorithm.

43
FLOWCHART : ADDITION OF TWO NUMBERS

44
BASIC STRUCTURE OF C

45
BASIC STRUCTURE OF C PROGRAM

46
SIMPLE C PROGRAM

/* A first C Program*/

#include <stdio.h>

void main()

{
printf("Hello World \n");

}
47
DEVELOPMENT WITH C
Four stages

 Editing: Writing the source code by using some IDE or


editor

 Preprocessing or libraries: Already available routines

 compiling: translates or converts source to object code


for a specific platform
source code -> object code

 linking: resolves external references and produces 48


the executable module
EXECUTING A ‘C’ PROGRAM

1. Creating the program


2. Compiling the program
3. Linking the program with functions that are needed
from the C library
4. Executing the program

49
COMPILATION AND EXECUTION IN C

Compilation
Source Language
Code Compiler EXE

Execution
Native Code

50
CREATING, COMPILING AND EXECUTING
A PROGRAM

51
INTRODUCTION TO PYTHON

What is PYTHON?
Python is a high-level, interpreted, interactive and object-oriented,
scripting language.

 Python is a high-level
It is a language that enables a programmer to write programs that
are more or less independent of a particular type of computer.
Such languages are considered as closer to human languages and
further from machine languages.
52
 Python is Interpreted
Python is processed at runtime by the interpreter. We do not
need to compile our program before executing it. This is similar
to PERL and PHP.
 Python is Interactive
You can actually sit at a Python prompt and interact with the
Interpreter directly to write your programs.
 Python is Object-Oriented
Python is an object-oriented language .It allows us to develop
applications using an Object-Oriented approach. In Python, we
can easily create and use classes and objects. 53
Python is scripting language
A scripting language is used to write scripts. These contain a
series of commands that are interpreted one by one at runtime
unlike programming languages that are compiled first before
running

Programming languages based applications are run by compiler


Programming languages based applications are required explicit compilation
Programming languages based applications can’t run directly without
compilation.
Ex: C,C++,JAVA .NET These languages are run by compiler

54
 Scripting language based applications are run by interpreter.
 Scripting language based applications are not required explicit compilation
Ex: shellscript, python , perl, Ruby, PowerShell
 These languages are run by interpreter.

Python is a dynamic programming language which supports several


different programming paradigms:
 Procedural programming(C)
 Object oriented programming(C++,java)
 Functional programming(LISP, Erlang…..)
 Scripting languages(shell script, PERL, Ruby, Powershell)
 Modular programming(Modula-3)
55
 Python= powerful programming language + powerful scripting
language
HISTORY OF PYTHON
Python was developed by Guido van Rossum, a Dutch
computer programmer in December 1989 at the National
Research Institute for Mathematics and Computer Science
(NRIMCS)in the Netherlands.

Python is said to have succeeded by ABC Programming


Language, which had the interfacing with the Amoeba
Operating System.
Python is derived from many other languages, including
ABC, Modula-3, C, C++,Algol-68, SmallTalk, and Unix shell 56

and other scripting languages


HERE INTERESTING FACT IS- PYTHON IS NAMED AFTER
THE BBC TV COMEDY SHOW MONTY PYTHON’S
FLYING CIRCUS.

It is not named after the Python snake

57
FEATURES OF PYTHON PROGRAMMING

 Easy to code and Easy to read


 Free and Open-Source
 High- Level
 Portable
 Interpreted
 Object-Oriented
 Embeddable
 Large Standard Library
 GUI Programming 58

 Dynamically Typed
Easy
 Easy to code
 Python is very easy to code. Compared to other popular languages
like Java and C++ . Anyone can learn python syntax in just few hours.
 Easy to read
 Being a high-level language, Python code is quite like English.
Looking at it, we can tell what the code is supposed to do.
Free and Open-Source
 Firstly, Python is freely available. You can download it from the
following link https://www.python.org/downloads/.

 Secondly, it is open-source. This means that its source code is available


59
to the public. You can download it, change it, use it, and distribute it.
This is called FLOSS(Free/Libre and Open Source Software).
High- Level
 It is a high-level language. This means that as programmers, we don’t
need to remember the system architecture. Nor do we need to
manage the memory. This makes it more programmer-friendly.

Portable
 We can take one code and run it on any machine, there is no need to
write different code for different machines. This makes Python a
portable language. However, we must avoid any system-dependent
features in this case.

60
Interpreted
 If we’re any familiar with languages like C++ or Java, we must first
compile it, and then run it. But in Python, there is no need to
compile it. Internally, its source code is converted into an immediate
form called bytecode.

 So, all we need to do is to run our Python code without worrying


about linking to libraries, and a few other things.

 By interpreted, we mean the source code is executed line by line,


and not all at once. Because of this, it is easier to debug our code.

61
Object-Oriented
 Python allows us to develop applications using an Object-Oriented
approach.

 Object-oriented programming (OOP) is nothing but that which allows the


writing of programs with the help of certain classes and real-time objects
 Python supports object-oriented programming concepts like
• Class
• Object
• Method
• Inheritance
• Polymorphism
• Data Abstraction 62
• Encapsulation

Embeddable
 We can put our Python code in a source code in a different language like
C++.
 It can be easily integrated with C, C++, COM, ActiveX, CORBA, and
Java.
 CPython is a python integrated with C/C++ language.
 Similarly JPython is a purely integrated language.

Large Standard Library


 Python downloads with a large library that we can use so we don’t have
to write our own code for every single thing.

 There are libraries for regular expressions, documentation-generation, 63


unit-testing, web browsers, threading, databases, CGI, email, image
GUI Programming
 We can use Tk or Tkinter to create basic GUIs.
.

Dynamically Typed
 Python is dynamically-typed. This means that the type for a value is decided
at runtime, not in advance. This is why we don’t need to specify the type of
data while declaring it.

64
PYTHON APPLICATIONS

 Web Applications

 Desktop GUI Applications

 Scientific and Numeric

 Business Applications

 Console Based Application

 Audio or Video based Applications

 3D CAD Applications

65
 Enterprise Applications


Web Applications
 We can use Python to develop web applications. It provides libraries to
handle internet protocols, HTML and XML, JSON, Email processing,
request, beautifulSoup, Feedparser etc.
 It also provides Frameworks such as Django, Pyramid, Flask etc to
design and develop web based applications. Some important
developments are: PythonWikiEngines, Pocoo, PythonBlogSoftware
etc.
Desktop GUI Applications
 Python provides Tk GUI library to develop user interface in python
based application.
 Some other useful toolkits wxWidgets, Kivy, pyqt that are useable on
66
several platforms. The Kivy is popular for writing multitouch
applications.
Software Development
 Python is helpful for software development process. It works as a support
language and can be used for build control and management, testing etc.
Scientific and Numeric
 Python is popular and widely used in scientific and numeric computing.
 Some useful library and package are SciPy, numpy, Pandas, IPython etc.
 SciPy is group of packages of engineering, science and mathematics.
Business Applications
 Python is used to build Business applications like ERP and e-commerce
systems.
 Tryton is a high level application platform.
Console Based Application
 We can use Python to develop console based applications. 67

For example: IPython.


Audio or Video based Applications
 Python is awesome to perform multiple tasks and can be used to develop
multimedia applications. Some of real applications are: TimPlayer, cplay etc.

3D CAD Applications
 To create CAD application Fandango is a real application which provides full
features of CAD.

Enterprise Applications
 Python can be used to create applications which can be used within an Enterprise
or an Organization.
 Some real time applications are: OpenErp, Tryton, Picalo etc.

Applications for Images


68
 Using Python several application can be developed for image.
 Applications developed are: VPython, Gogh, imgSeek etc.
WHY PYTHON?

 Python is also a cross platform language which means


that the code written for one operating system like
Windows ,will work equally well with Linux or MacOS
without any changes to the python code.

 Python has a simple syntax similar to the English


language. whereas the other languages use punctuations.

 Python has syntax that allows developers to write programs


69

with fewer lines than some other programming languages.


 Python is a programming language that allows us work
quickly and integrate systems more efficiently.

 Python is a great language for the beginner level


programmers and supports the development of a wide
range of applications.

70
ADVANTAGES OF PYTHON
Freeware: Python is open source language. It doesn't require any activation
key or subscription to work on it. It is free to use software and all the tools
available on python are absolutely free.

Less Coding: The syntax written in python is very simple and use common
English language which makes it more user-friendly.

Efficient: Python relies on indentation, using white space, to define scope;


such as the scope of loops, functions, and classes. Other Programming
Languages use curly-brackets for this purpose.

Portability: Python can be run on any operating system. Also, we use the
Python Code written on one system onto another system without making any
changes to the code 71
EXISTING PROGRAMMING VS PYTHON PROGRAMMING

--------C program------- --------Python program--------


num1 = 1.5; num2 = 6.3
#include<stdio.h>
sum = num1 + num2
int main()
print('The sum of two numbers”, sum))
{
int a, b, sum;
printf("\nEnter two no: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum : %d", sum);
return(0);
72
}
Text Books
 Computer Science: A Structured Programming Approach Using C,
B. A. Forouzan and R. F. Gilberg, Third Edition, Cengage Learning.
 Programming in C. P. Dey and M Ghosh, Second Edition, Oxford
University Press.
 Core Python Programming, Wesley J. Chun, Second Edition,
Pearson

Reference Books
 The C Programming Language, B.W. Kernighan and Dennis M.
Ritchie, Second Edition, Pearson education.
 Programming with C, B. Gottfried, 3rd edition, Schaum’s outlines,
McGraw Hill Education (India) Pvt Ltd.
 Programming Languages, A.B. Tucker, R.E. Noonan, TMH.
73
 Programming Languages, K. C. Louden and K A Lambert., 3rd
edition, Cengage Learning.
THANK YOU

74

You might also like