Vous êtes sur la page 1sur 33

01 INTRODUCTORY CONCEPTS

Spring 2017 CS 101 Introduction To Computing


B1:
Let Us C 13th Edition, BPB Publications, July 2016
Yashavant Kanetkar
Credits
 B1
 https://en.wikibooks.org/wiki/A-
level_Computing/AQA/Computer_Components,_The_Stored_Program_Con
cept_and_the_Internet/Fundamentals_of_Computer_Systems/Generations_
of_programming_language
 http://cprogrammingcodes.blogspot.in/2011/09/algorithms-and-
flowchart.html
 http://faraday.ee.emu.edu.tr/Eeng111/algorithmsandflowcharts1.ppt
 An Introduction to Bioinformatics Algorithms By Neil C. Jones and Pavel A.
Pevzner, MIT Press
 http://www.gcflearnfree.org/computerbasics/what-is-a-computer/1/
Assignment
Read:
https://en.wikibooks.org/wiki/A-
level_Computing/AQA/Computer_Components,_The_Stored_Program_Concept_and
_the_Internet/Fundamentals_of_Computer_Systems/Generations_of_programming_l
anguage
http://cprogrammingcodes.blogspot.in/2011/09/algorithms-and-flowchart.html
Emailed notes: “AlgorithmsAndPseudocodeFromPevznerBook.pdf”
Watch (for those interacting with a computer first time):
https://www.youtube.com/watch?v=e55EQ1xHYbI

Problems:
At the end of sides
What is a Computer
 A computer is an electronic device that manipulates
information, or data.
 It has the ability to store, retrieve, and process data.
 You may already know that you can use a computer to type
documents, send email, play games, and browse the Web.
 You can also use it to edit or
create spreadsheets, presentations, and even videos.
 Hardware vs. Software
A little video
 https://www.youtube.com/watch?v=7cXEOWAStq4
Why do we need a programming Language?
 We understand English/Hindi/Malayalam/Telugu
 Computer understands C/C++/Java (Programming Languages)
Generations of Programming Languages

Generation First Second Third Fourth


10101010011
00010
body.top {
10011010100
LDA 34 ADD color : red;
Code example 00001 x=x+1
#1 STO 34 font-style : italic
11111111101
}
00010

(HIGH) Visual
(LOW) Machine (LOW) (HIGH) SQL, CS
Language Basic, C, python
Code Assembly Code S, Haskell etc.
etc.
First Generation
 Just zero and ones 1010101001100010
 Fed through punch card etc.
 No need to translate – directly understandable by computer, hence,
fast.
 Object code or machine code.
 Difficult to understand /update/edit by human.
Second Generation
 Assembly Language
 Mnemonic codes

Assembly Code Object Code

000100110100
LDA A ADD #5 STA A JMP 001000000101
-> Assembler ->
#3 001100110100
010000000011
Third Generation (High Level Languages)
 Programmer-friendly features to code such as loops, conditionals,
classes etc.
 One line of third generation code can produce many lines of object
(machine) code, saving a lot of time when writing programs.
 Code are imperative: code is executed line by line, in sequence.
 Hardware independence, can be easily ported to other systems and
processors.
 Requires a Compiler or an Interpreter.
 Not possible with 1st and 2nd gen because they were machine dependent

 Time saving, programmer friendly, one line of 3rd gen is the


equivalent of many lines of 1st and 2nd gen
Fourth Generation
 Designed to reduce programming effort and the time it takes to
develop software
 Designed with a specific purpose in mind
 Query databases (SQL)
 Make reports (Oracle Reports)

 Construct user interface (XUL)


 What computation should be performed and not how to perform it.
--an example of a Structured Query Language (SQL) to
select criminal details from a database
SELECT name, height, DoB FROM criminals WHERE numScars = 7;
C Language
 Developed at AT & T’s Bell Laboratories of USA in 1972
 Designed and written by a man named Dennis Ritchie
 Third generation high level language.
Algorithms
 A typical programming task can be divided into two phases:
 Problem solving phase
 Produce an ordered sequence of steps that describe solution of problem
 An algorithm
 Implementation phase
 implement the program in some programming language
 Example 1: Write an algorithm to determine a student’s final grade
and indicate whether it is passing or failing. The final grade is
calculated as the average of four marks.

 Input a set of 4 marks


 Calculate their average by summing and dividing by 4
 if average is below 50
Print “FAIL”
else
Print “PASS”
Pseudocode
 Similar to algorithm but more programming language like yet
independent of any particular programming language

Input M1,M2,M3,M4
GRADE  (M1+M2+M3+M4)/4
if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif
Pseudocode Constructs
 A variable, written as x or total, contains some numerical value and
can be assigned a new numerical value at different points throughout
the course of an algorithm.
 An array of n elements is an ordered collection of n variables a1, a2, .
. . , an.
 In a = (a1, a2, . . . , an), a is the array and the individual elements are
denoted as ai, where i is between 1 and n.
 Write a pseudocode to calculate two roots of a quadratic expression
 Write a pseudocode to find the largest among n numbers.
Flowcharts
 Graphical representation of any program is called flowchart.
 There are some standard graphics that are used in flowchart as
following:
 Make a flowchart to input temperature, if temperature is less than 32
then print "below freezing" otherwise print "above freezing"?
 Draw a flowchart to check if a number is divisible by 5 and greater
than 100.
 Draw a flowchart to check if a number is prime.
 Draw a flow chart to find factorial of a number.
Assignment Problems
 Write pseudocode and draw a flowchart for the following problems
1. To swap two numbers.
2. To calculate simple and compound interest.
3. To find second largest numbers in a list of n numbers
4. To check if the given year is a leap year
5. In a list of n>4 positive numbers, print first four numbers less than
100. If four such numbers are not found, print appropriate message.