0% found this document useful (0 votes)
27 views9 pages

LECTURE 01 Bscs

F.g rawalpindi

Uploaded by

bc240222245rsh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views9 pages

LECTURE 01 Bscs

F.g rawalpindi

Uploaded by

bc240222245rsh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR.

SYED WAQAR UL QOUNAIN

CC-112 PROGRAMMING FUNDAMENTALS


2022-08-16 LECTURE 01 – INTRODUCTION TO PROGRAMMING, ALGORITHMS AND C – I

 contents
o course information
o programming
o flowchart and pseudocode
o dry run
o concepts discussed in the lecture
 course information
o first Programming course
o CC-112 – second computing core (CC) course after discrete structures (CC-111) offered in
the first year
o Textbook: Paul Deitel, Harvey Deitel, C How To Program, 9th Edition, Pearson, 2022
o google classroom: https://classroom.google.com/c/NTM4NDU3MTc3NDM2?cjc=t62dyhs
o Lecture Timings: Tuesday, Thursday at 9:45 AM in Class Room No. 15
o Lab Timings: Thursday at 2:30 PM in Lab A
 programming
o to instruct, command, and control machines / computers
o what to do and how to do things
o programmer should know
 objective to write a program
 programming language syntax
 programming software / tools to work
o significance of programming
 human
 enhance problem-solving skill
 helps in developing resilience
 to think differently and build alternatives
 expands creativity and innovation
 augment memory, mind, and thought
 high-end and highly paid skill of the current century
 science
 identify patterns in nature and predict the coming future
 create artificial intelligence
 future of human activities in the universe
 society
 offload repetitive and routine tasks
 solve high computational problems
 solve complex problems which a human mind cannot solve alone
 flowchart and pseudocode
o pseudocode and flowchart are used to conceive / plan a program
o pseudocode is a simple English like expression of a program flow

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE PAGE 1 OF 9


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

o flowchart is a simple graphical diagram of program flow


o read and write are two instructions commonly used on Pseudocodes or flowcharts for
taking input from user and writing output on the console
o a variable is a named memory (RAM) location to store user input, and processed data
for future use
o dry run is a walkthrough on a Pseudocode or a flowchart to understand and comprehend
program’s dynamics on various inputs
o a set of inputs / assumptions used to dry run a Pseudocode or a flowchart is called test
case.
o programmers usually design a set (number) of test cases to test or verify program
correctness and to identify their errors / bugs
o an error or a bug is an unintentional mistake committed by the programmer during the
course of programming
o a flowchart is comprised of various shapes connected with direction arrows
 ⬭: an oval is used for the start and end of a flowchart.
 ▱ : a parallelogram is used for taking input and giving output in a flowchart
 ▭: rectangle is used for processes like evaluating a mathematical expression,
assigning a value to a variable, etc.
 ♢: a diamond is used for decision-making using different conditions
 ○: a circle is used as a connector in flowcharting
 →: an arrow lines are used to connect various building blocks (oval, rectangle,
parallelogram, diamond etc.) of a flowchart and also to indicate direction of flow.
o (1) simplest flowchart is the one that has a start and an end statement without any other
instruction.
o (2) flowchart and pseudocode which outputs a string at the console.
 string is a set of characters like “Pakistan Zindabad”
 it uses parallelogram shape and WRITE instruction to output at the console
o (3) flowchart and pseudocode which takes an input value from the user, stores it into a
variable named “a” and outputs the value of the variable “a” at console.
 a variable is a named memory (RAM) location to store user input/data, and
processed data for future use
 different types of variables would be discussed in the upcoming lecture
 besides WRITE instruction READ instruction is used in parallelogram to take input
from the user and store it into a variable named “a”
 then the value of the variable “a” is displayed at the console.
o (4) flowchart and pseudocode which takes two inputs from the user, stores these into
two variables named “a” and “b”, perform sum the values in these two variables and the
sum into another variable “c” and finally outputs the value of the variable “c” at the
console.
 a rectangle is used to process a mathematical expression c = a + b which adds
values stored in variable a and b and assign their result to variable c
 mathematical expression is a combination of variables, numbers, and
mathematical operators in a valid mathematical form

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE PAGE 2 OF 9


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

 c = a + b has three variables namely a, b and c, and two operators namely addition
(+) and assignment (=)
 other types of operators and expressions would be discussed in the upcoming
lecture
o (5) flowchart and pseudocode which takes a number from the user, stores it into a
variable named a, and displays its value if the value of the variable is greater than 10.
 a diamond is used to check if the value of the variable “a” is greater than 10, if
this value is greater than 10 then output the value of the variable at the console,
otherwise do nothing and end the program
 in diamond a relational operator (>) named greater than is used to form a
relational expression
 relational expression is a combination of variables, numbers and relational
operators (>, <, >=, <=, ==, !=) in a valid relational form
 a > 10 has one variable namely a, one constant namely 10, and one relational
operator namely greater than (>)
 if this expression is true which means the value stored in the variable a is actually
greater than 10 then the flow of this chart will move to the right direction and
display the value stored in a variable at the console.
 otherwise if this expression is not true (false) which means the value stored in the
variable a is actually not greater than 10 then the flow of this chart will move
downwards and the program will end.
 in the pseudocode instructions of IF THEN and ENDIF are used to represent a
diamond
 A relational expression is written in front of IF, and if this relational expression is
true then the instruction between THEN and ENDIF would be executed otherwise
this block of instructions between THEN and ENDIF would be skipped and the
flow will move ahead of it.
o (6) flowchart and pseudocode which takes a number from the user, stores it into a
variable named “a”, and displays a string “It is greater than 10” if the value of the variable
is greater than 10.
 after taking input from the user and storing it into a variable named “a”
 a diamond is used to check if the value of the variable “a” is greater than 10, if
the expression in the diamond is true which means the value stored in the
variable “a” is actually greater than 10 then the flow of this chart will move to the
right direction and display the string “It is greater than 10” at the console.
 otherwise if this expression is not true (false) which means the value stored in the
variable a is actually not greater than 10 then the flow of this chart will move in
the left direction and the program will end.
 in pseudocode instructions of IF THEN and ENDIF are used to represent a
diamond
 a relational expression is written in front of IF, and if this relational expression is
true then the instruction between THEN and ENDIF would be executed otherwise
this block of instructions between THEN and ENDIF would be skipped and the
flow will move ahead of it.

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE PAGE 3 OF 9


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

o (7) flowchart and pseudocode which takes a number from the user, stores it into a
variable named “a”, and displays a string “It is greater than 10” if the value of the variable
is greater than 10 and “It is less than 10” otherwise.
 after taking input from the user and storing it into a variable named “a”
 a diamond is used to check if the value of the variable “a” is greater than 10, if
the expression in the diamond is true which means the value stored in the
variable “a” is actually greater than 10 then the flow of this chart will move to the
right direction and display the string “It is greater than 10” at the console
 otherwise if this expression is not true (false) which means the value stored in the
variable “a” is actually not greater than 10 then the flow of this chart will move
in the left direction and the program display the string “It is less than 10” at the
console
 in the pseudocode, instructions of IF THEN ELSE and ENDIF are used to represent
this diamond.
 a relational expression (a > 10) is written in the front of IF, and if this relational
expression is true then the instruction between THEN and ELSE would be
executed otherwise this block of instructions between THEN and ELSE would be
skipped and the block of instruction between ELSE and ENDIF would be executed.
 in this flowchart two test cases are applied namely Test Case 1 and Test Case 2
 in Test Case 1 user entered input value 12 which displayed “It is greater than 10”
as desired.
 in Test Case 2 user entered input value 10 which displayed “It is less than 10”
which was not desired and is incorrect
 dry run of Test Case 2 helped in identifying an error/bug in the flowchart because
in Test Case 2 the output should be “It is equal to 10”
 this error or bug is addressed in the flowchart (8)
o (8) flowchart and pseudocode which takes a number from the user, stores it into a
variable named “a”, and displays a string “It is greater than 10” if the value of the variable
is greater than 10, otherwise displays “It is equal to 10” if the value of the variable is equal
to 10 and “It is less than 10” otherwise.
 after taking input from the user and storing it into a variable named “a”
 first diamond is used to check if the value of the variable “a” is greater than 10, if
the expression in the diamond is true which means the value stored in the
variable “a” is actually greater than 10 then the flow of this chart will move to the
right direction and display the string “It is greater than 10” at the console
 otherwise if this expression in the first diamond is not true (false) which means
the value stored in the variable “a” is actually not greater than 10 then the flow
of this chart will move in the left direction
 here the second diamond is used to check if the value of the variable “a” is equal
to 10, if the expression in the diamond is true which means the value stored in
the variable “a” is actually equal to 10 then the flow of this chart will move to the
right direction and display the string “It is equal to 10” at the console
 otherwise if this expression in the second diamond is not true (false) which means
the value stored in the variable “a” is actually not equal to 10 then the flow of

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE PAGE 4 OF 9


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

this chart will move in the left direction and the program will display the string “It
is less than 10” at the console
 in pseudocode, instructions of IF THEN ELSE and ENDIF are used to represent
these diamonds.
 a relational expression (a > 10) is written in the front of IF, and if this relational
expression is true then the instruction between THEN and ELSE would be
executed otherwise this block of instructions between THEN and ELSE would be
skipped and the block of instruction between ELSE and ENDIF would be executed.
 in this ELSE and ENDIF another IF THEN ELSE EDNIF structure is used which is
called nested structure
 if the relational expression (a = 10) written in the front of the second IF is true
then the instruction between THEN and ELSE would be executed otherwise this
block of instructions between THEN and ELSE would be skipped and the block of
instruction between last ELSE and ENDIF would be executed.
 in this flowchart two test cases are applied namely Test Case 1 and Test Case 2
 in Test Case 2 user enters input value 10 which displays “It is equal to 10” which
is as desired.

FLOWCHART PSEUDOCODE TEST CASES


START
END

(1)
START Pakistan Zindabad
WRITE Pakistan Zindabad
END

(2)
START User input
5
READ a
Output
WRITE a 5
END

(3)

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE PAGE 5 OF 9


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

START Test Case 1


User input
READ a, b
5
c =a +b 12
WRITE c
Output
END 17
------------------------
Test Case 2
User input
-5
12
Output
7
(4)
START Test Case 1
User input
READ a
12
IF a > 10 THEN
Output
WRITE a
12
ENDIF
------------------------
END
Test Case 2
User input
5

Output

(5)
START Test Case 1
User input
READ a
12
IF a > 10 THEN Output
It is greater than 10
WRITE "It is greater than 10"
ENDIF ------------------------
Test Case 2
END
User input
5

Output

(6)

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE PAGE 6 OF 9


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

START Test Case 1


User input
READ a
12
IF a > 10 THEN Output
It is greater than 10
WRITE "It is greater than 10"
------------------------
ELSE Test Case 2
User input
WRITE "It is less than 10"
10
ENDIF Output
(7) It is less than 10
END
This is a bug in the
program identified
through test case 2
START Test Case 1
User input
READ a
5
IF a > 10 THEN Output
It is less than 10
WRITE "It is greater than 10"
ELSE ------------------------
Test Case 2
IF a = 10 THEN
(8) User input
WRITE "It is less than 10" 10
Output
ELSE
It is equal to 10
WRITE "It is equal to 10"
ENDIF
ENDIF
END

 dry run
o dry run is a walkthrough on a Pseudocode or a flowchart to understand and comprehend
the program’s dynamics on various inputs
o in a dry run a table of program variables is maintained which is updated after the
execution of each instruction, such a table is called variable state table
o in LARP use Execute step-by-step (Shift + F7) in the Execute menu to perform a dry run
o following is a dry run of flowchart no. 4, it contains three screens
 first from left is the flowchart,
 second is a console
 and the third is Step Execution which contains
 variable state table or the variables inspection panel displays the value
contained in each variable during step executing the current program

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE PAGE 7 OF 9


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

 the call stack inspection panel which lists all modules in the call stack
along with their respective parameter values (would be explained in the
modular programming section of the course
o the animation panel allows to visualize the evaluation process of algorithmic instructions.
o observation of variable state table during a dry run helps in identifying an error or bug
o an error or bug in flowchart 7 could be identified when test case 2 is run (marked as red).
Where the programmer has missed to program the condition when user will input 10
o a modified version of the flowchart 7 is depicted in flowchart 8 which resolved this error

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE PAGE 8 OF 9


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

 concepts discussed in the lecture


o programming and programmer, flowchart and pseudocode, READ and WRITE, input and
output, variable, dry run, test case, error or bug, START and END, string, mathematical
expression, mathematical operators, relational expression, relational operators, IT THEN
ENDIF, IF THEN ELSE ENDIF, nested structure, LARP (Logic of Algorithms for Resolution of
Problems), execute step-by-step, variable state table, variables inspection panel, call
stack panel, animation panel

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE PAGE 9 OF 9

You might also like