0% found this document useful (0 votes)
51 views

PLF 101 Chapter 1 Module

This document provides an overview of a module on programming logic formulation using C++. It includes an introduction describing the purpose of the module and the topics to be covered. The module contains 8 chapters that will cover flowcharts and algorithms, Turbo C++, basic input/output statements, conditional statements, looping statements, functions, arrays, and strings. The module is designed to help students learn C++ programming and will be used for both lectures and laboratory work. It provides examples and exercises for students to practice the concepts taught. The overall goal is for students to gain proficiency in problem solving using object-oriented programming.

Uploaded by

Edrick Ancheta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

PLF 101 Chapter 1 Module

This document provides an overview of a module on programming logic formulation using C++. It includes an introduction describing the purpose of the module and the topics to be covered. The module contains 8 chapters that will cover flowcharts and algorithms, Turbo C++, basic input/output statements, conditional statements, looping statements, functions, arrays, and strings. The module is designed to help students learn C++ programming and will be used for both lectures and laboratory work. It provides examples and exercises for students to practice the concepts taught. The overall goal is for students to gain proficiency in problem solving using object-oriented programming.

Uploaded by

Edrick Ancheta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

PLF 101-Program Logic Formulation

This is a property of
PRESIDENT RAMON MAGSAYSAY STATE
UNIVERSITY
NOT FOR SALE
PLF 101 – Program Logic Formulation

right. Republic Act 8293 Section 176 provides that “No right shall subsist in any work of the
Government of the Philippines. However, prior approval of the government agency or office
wherein the work is created shall be necessary for exploitation of such work for profit. Such agency
or office may, among other things, impose as a condition the payment of royalties.

Borrowed materials included in this module are owned by their respective right holders. Every
effort has been exerted to reach and seek permission to use these materials from their respective
right owners. The University and authors do not claim ownership over them.

Learning Module Development Team

Assigned Chapter/Lesson Title Author/s


Chapter/Lesson 1: Introduction to Flowchart Amir Yasheen Madhi
and Algorithm
Chapter/Lesson 2: The Turbo C++ Copernicus P.Pepito
Chapter/Lesson 3: The Basic Input/output Copernicus P.Pepito
Statements of C
Chapter/Lesson 4: The Conditional Copernicus P.Pepito
Statements
Chapter/Lesson 5: The Looping Statement Copernicus P.Pepito
Chapter/Lesson 6: Functions as Subprograms Copernicus P.Pepito
Chapter/Lesson 7: Arrays Copernicus P.Pepito
Chapter/Lesson 8: Strings Copernicus P.Pepito

Evaluators:

(First Name, Middle Initial, Last Name), Position


(First Name, Middle Initial, Last Name), Position
(First Name, Middle Initial, Last Name), Position
Course Overview

Introduction
Intelligence is one of the key characteristics which differentiate a human being from other
living creatures on the earth. Basic intelligence covers day to day problem solving and making
strategies to handle different situations which keep arising in day to day life. One person goes
Bank to withdraw money. After knowing the balance in his account, he/she decides to with draw
the entire amount from his account but he/she has to leave minimum balance in his account. Here
deciding about how much amount he/she may with draw from the account is one of the examples
of the basic intelligence. During the process of solving any problem, one tries to find the necessary
steps to be taken in a sequence. In this Unit you will develop your understanding about problem
solving and approached.
But in Turbo C++ A C++ program is a collection of commands, which tell the computer to do
"something". This collection of commands is usually called C++ source code, source code or
just code. Commands are either "functions" or "keywords". Keywords are a basic building block
of the language, while functions are, in fact, usually written in terms of simpler functions--you'll
see this in our very first program, below. (Confused? Think of it a bit like an outline for a book;
the outline might show every chapter in the book; each chapter might have its own outline,
composed of sections. Each section might have its own outline, or it might have all of the details
written up.) Thankfully, C++ provides a great many common functions and keywords that you can
use.

But how does a program actually start? Every program in C++ has one function, always
named main, that is always called when your program first executes. From main, you can also call
other functions whether they are written by us or, as mentioned earlier, provided by the compiler

Course General Objectives


The objective of course is to develop programming skills of students, using object oriented
programming concepts, learn the concept of class and object using C++ and develop classes for
simple applications.

At the end of the semester, 75% of the students have attained 80 % proficiency level for being
aware of their purpose for communication and their audience locally and globally.
I. Identify importance of object oriented programming and difference between structured
oriented and object oriented programming features.
II. Able to make use of objects and classes for developing programs.
III. Able to use various object oriented concepts to solve different problems.

Course Details:

 Course Code: PLF 101


 Course Title: Program Logic Formulation
 No. of Units (State the lecture and laboratory units): 3 (1hr) (1hr) lecture (2hrs) laboratory
 Classification (lecture-based, laboratory-based, ):
 Pre-requisite / Co-Requisite: CC 102
 Semester and Academic Year: 1st Semester, AY 2021-2022
 Schedule: MW- 3:30-4:30 Lec. TTH 3:30-5:00 Lab.
 Name of Faculty: DARYL JOHN C. RAGADIO
 Contact Details
Email: [email protected]
Mobile Number: 0919-095-6046
FB Account: [email protected]
 Consultation
Day: TTH
Time: 8:00-9:30AM

Learning Management System

The University LMS will be used for asynchronous learning and assessment. The link and class
code for LMS will be provided at the start of class through the class’ official Facebook Group.

 Zoom
 Google Classroom
 University LMS

Assessment with Rubrics


Students will be assessed in a regular basis thru quizzes, long/unit/chapter tests, individual/group
outputs using synchronous and/or asynchronous modalities or submission of SLM exercises.
Rubrics are also provided for evaluation of laboratory individual/group outputs.

Major examinations will be given as scheduled. The scope and coverage of the examination will
be based on the lessons/topics as plotted in the course syllabus.
0323

Module Overview

Introduction
This module aims to develop student’s to learn how to program in C programming language easily.
It contains introductory topics of C , from simple input/output statements up to two-dimensional
arrays and string manipulation. Mostly, the C programming class covers these topics. Further
more, this module is designed as lecture notes, reviewer, and laboratory manual. Most of the
examples presented here are collections of my notes, which I have used for my lecture and
laboratory classes in C programming subject.
As instructor of PLF, I felt that I have the responsibility to help our students to learn and
appreciate this powerful computer language.

Table of Contents. Mostly, the C programming class covers the topics,

Chapter/Lesson 1: Introduction to Flowchart and Algorithm


Chapter/Lesson 2: The Turbo C++
Chapter/Lesson 3: The Basic Input/output Statements of C
Chapter/Lesson 4: The Conditional Statements
Chapter/Lesson 5: The Looping Statement
Chapter/Lesson 6: Functions as Subprograms
Chapter/Lesson 7: Arrays
Chapter/Lesson 8: Strings
PROGRAM LOGIC FORMULATION
CHAPTER 1
Flowchart and Algorithm
Introduction
Intelligence is one of the key characteristics which differentiate a human being from other
living creatures on the earth. Basic intelligence covers day to day problem solving and making
strategies to handle different situations which keep arising in day to day life. One person goes
Bank to withdraw money. After knowing the balance in his account, he/she decides to withdraw
the entire amount from his account but he/she has to leave minimum balance in his account. Here
deciding about how much amount he/she may with draw from the account is one of the examples
of the basic intelligence. During the process of solving any problem, one tries to find the necessary
steps to be taken in a sequence. In this Unit you will develop your understanding about problem
solving and approaches.
Program Logic Formulation provides students the fundamental features and concepts
of programming languages. Topics include overview of programming languages, introduction to
language and translation, type systems, data and execution control, declaration and modularity,
and syntax and semantics. This course also discusses topics about the design and analysis of
algorithms, techniques in analyzing algorithms, algorithmic strategies, sorting and searching
algorithms. The students will develop their competencies as they engage in different activities that
will apply the different algorithms and execution control by presenting their plan of their program
using flowchart and pseudocode. They will strengthen their character through collaboration of
ideas and deeper analysis of their program. With that, they can be globally competent and become
responsive to the needs of societal transformation.

Specific Objectives

The objective of course is to develop programming skills of students, using flowchart and
algorithm concepts, learn the concept of class and object using C++ and develop classes for simple
applications.

At the end of the lesson, the students should be able to:

-Identify importance of Flowchart and Algorithm difference between structured oriented and
object oriented programming features.
-Able to make use of objects and classes for developing programs.
- Able to use various object oriented concepts to solve different problems.
- Apply computer science in the development of problem solving skills.
- Develop the communication skills of the students through problem presentations
- Develop the programming communication skills of the students and experiences the nature of
solving programming problems.
- Apply knowledge of computing, logic, science and mathematics appropriate to the discipline.
- Analyze complex problems, and identify and define the computing requirements appropriate to
its solution.
- Design, evaluate and implement computer-based programs.
- Identify features of imperative languages and their implementation (including the use of static
memory, stack and heap for implementing variables).
- Identify various programming paradigms (functional, declarative, imperative, object
oriented) and their implementations).
- Describe the different phases in the language transition process.
- Design effective, elegant, efficient, and readable algorithm for various classes of computing
problems.
- Use various algorithm design techniques.

Duration

CHAPTER 1: Flowchart and Algorithm = 6 hours


(4 hours discussion; 2 hours
assessment)

Lesson 1

1. PROBLEM SOLVING
Can you think of a day in your life which goes without problem solving? Answer to this question
is of course, No. In our life we are bound to solve problems. In our day to day activity such as
purchasing something from a general store and making payments, depositing fee in school, or
withdrawing money from bank account. All these activities involve some kind of problem solving.
It can be said that whatever activity a human being or machine do for achieving a specified
objective comes under problem solving. To make it clearer, let us see some other examples.

Example1: If you are watching a news channel on your TV and you want to change it to a sports
channel, you need to do something i.e. move to that channel by pressing that channel number on
your remote.

Example 2: One Monday morning, a student is ready to go to school but yet he/she has not picked
up those books and copies which are required as per timetable. So here picking up books and
copies as per timetable is a kind of problem solving.
Example 3: If someone asks to you, what is time now? So seeing time in your watch and telling
him is also a kind of problem solving.

Example 4: Some students in a class plan to go on picnic and decide to share the expenses among
them. So calculating total expenses and the amount an individual have to give for picnic is also a
kind of problem solving.

Now, broadly we can say that problem is a kind of barrier to achieve something and problem
solving is a process to get that barrier removed by performing some sequence of activities
Here it is necessary to mention that all the problems in the world can not be solved. There are some
problems which have no solution and these problems are called Open Problems.
If you can solve a given problem then you can also write an algorithm for it. In next section we
will learn what is an algorithm.

2. ALGORITHM
Algorithm can be defined as: “A sequence of activities to be processed for getting desired output
from a given input.”

Webopedia defines an algorithm as: “A formula or set of steps for solving a particular problem.
To be an algorithm, a set of rules must be unambiguous and have a clear stopping point”. There
may be more than one way to solve a problem, so there may be more than one algorithm for a
problem.

Now, if we take definition of algorithm as: “A sequence of activities to be processed for getting
desired output from a given input.” Then we can say that:

1. Getting specified output is essential after algorithm is executed.


2. One will get output only if algorithm stops after finite time.
3. Activities in an algorithm to be clearly defined in other words for it to be unambiguous.
Before writing an algorithm for a problem, one should find out what is/are the inputs to the
algorithm and what is/are expected output after running the algorithm. Now let us take some
exercises to develop an algorithm for some simple problems: While writing algorithms we will use
following symbol for different operations:
‘+’ for Addition
‘-’ for Subtraction
‘*’ for Multiplication
‘/’ for Division and
‘ ’ for assignment. For example A X*3 means A will have a value
of X*3.

1.3.1 Example of Algorithm


Problem 1: Find the area of a Circle of radius r.
Inputs to the algorithm:
Radius r of the Circle.
Expected output:
Area of the Circle
Algorithm:
Step1: Read\input the Radius r of the Circle
Step2: Area PI*r*r // calculation of area
Step3: Print Area
Step2: Read\input the first num1.
Step3: Read\input the second num2.
Step4: Sum num1+num2 // calculation of sum
Step5: Print Sum
Step6: End

Problem 3: Convert temperature Fahrenheit to Celsius


Inputs to the algorithm:
Temperature in Fahrenheit
Expected output:
Temperature in Celsius

Algorithm:
Step1: Start
Step 2: Read Temperature in Fahrenheit F
Step 3: C 5/9*(F32)
Step 4: Print Temperature in Celsius: C
Step5: End

Type of Algorithms
The algorithm and flowchart, classification to the three types of control
structures. They are:
1. Sequence
2. Branching (Selection)
3. Loop (Repetition)

These three control structures are sufficient for all purposes. The sequence is exemplified by
sequence of statements place one after the other – the one above or before another gets executed
first. In flowcharts, sequence of statements is usually contained in the rectangular process box.
The branch refers to a binary decision based on some condition. If the condition is true, one of
the two branches is explored; if the condition is false, the other alternative is taken. This is usually
represented by the ‘if-then’ construct in pseudo-codes and programs. In flowcharts, this is
represented by the diamond-shaped decision box. This structure is also known as the selection
structure.

Problem1: write algorithm to find the greater number between two numbers
Step1: Start
Step2: Read/input A and B
Step3: If A greater than B then C=A
Step4: if B greater than A then C=B
Step5: Print C
Step6: End

Problem2: write algorithm to find the result of equation: ( ) {


Step1: Start
Step2: Read/input x
Step3: If X Less than zero then F=-X
Step4: if X greater than or equal zero then F=X
Step5: Print F
Step6: End

Problem3: A algorithm to find the largest value of any three numbers.


Step1: Start
Step2: Read/input A,B and C
Step3: If (A>=B) and (A>=C) then Max=A
Step4: If (B>=A) and (B>=C) then Max=B
Step5:If (C>=A) and (C>=B) then Max=C
Step6: Print Max
Step7: End

The loop allows a statement or a sequence of statements to be repeatedly executed based on


some loop condition. It is represented by the ‘while’ and ‘for’ constructs in most programming
languages, for unbounded loops and bounded loops respectively. (Unbounded loops refer to those
whose number of iterations depends on the eventuality that the termination condition is satisfied;
bounded loops refer to those whose number of iterations is known before-hand.) In the flowcharts,
a back arrow hints the presence of a loop. A trip around the loop is known as iteration. You must
ensure that the condition for the termination of the looping must be satisfied after some finite
number of iterations, otherwise it ends up as an infinite loop, a common mistake made by
inexperienced programmers. The loop is also known as the repetition structure.

Examples:
Problem1: An algorithm to calculate even numbers between 0 and 99
1. Start
2. I ← 0
3. Write I in standard output
4. I ← I+2
5. If (I <=98) then go to line 3
6. End

Problem2: Design an algorithm which gets a natural value, n,as its input and calculates odd
numbers equal or less than n. Then write them in the standard output:
Start
2. Read n
3. I ← 1
4. Write I
5. I ← I + 2
6. If ( I <= n) then go to line 4
7. End

Problem3: Design an algorithm which generates even numbers between 1000 and 2000 and then
prints them in the standard output. It should also print total sum:
1. Start
2. I ← 1000 and S ← 0
3. Write I
4. S ← S + I
5. I ← I + 2
6. If (I <= 2000) then go to line 3
else go to line 7
7. Write S
8. End

Problem4: Design an algorithm with a natural number, n, as its input which calculates the
following formula and writes the result in the standard output:
S = ½ + ¼ + … +1/n
1. Start
2. Read n
3. I ← 2 and S ← 0
4. S= S + 1/I
5. I ← I + 2
6. If (I <= n) then go to line 4
else write S in standard output
7. End
Combining the use of these control structures, for example, a loop within a loop (nested
loops), a branch within another branch (nested if), a branch within a loop, a loop within a branch,
and so forth, is not uncommon. Complex algorithms may have more complicated logic structure
and deep level of nesting, in which case it is best to demarcate parts of the algorithm as separate
smaller modules. Beginners must train themselves to be proficient in using and combining control
structures appropriately, and go through the trouble of tracing through the algorithm before they
convert it into code.

1.3.2 Properties of algorithm


Donald Ervin Knuth has given a list of five properties for a, algorithm, these properties are:

1) Finiteness: An algorithm must always terminate after a finite number of steps. It means
after every step one reach closer to solution of the problem and after a finite number of
steps algorithm reaches to an end point.
2) Definiteness: Each step of an algorithm must be precisely defined. It is done by well
thought actions to be performed at each step of the algorithm. Also the actions are defined
unambiguously for each activity in the algorithm.

3) Input: Any operation you perform need some beginning value/quantities associated with
different activities in the operation. So the value/quantities are given to the algorithm
before it begins.

4) Output: One always expects output/result (expected value/quantities) in terms of output


from an algorithm. The result may be obtained at different stages of the algorithm. If some
result is from the intermediate stage of the operation then it is known as intermediate result
and result obtained at the end of algorithm is known as end result. The output is expected
value/quantities always have a specified relation to the inputs.

5) Effectiveness: Algorithms to be developed/written using basic operations. Actually


operations should be basic, so that even they can in principle be done exactly and in a finite
amount of time by a person, by using paper and pencil only.

1.4 FLOWCHART
The flowchart is a diagram which visually presents the flow of data through processing
systems. This means by seeing a flow chart one can know the operations performed and the
sequence of these operations in a system. Algorithms are nothing but sequence of steps for solving
problems. So a flow chart can be used for representing an algorithm. A flowchart, will describe
the operations (and in what sequence) are required to solve a given problem. You can see a flow
chart as a blueprint of a design you have made for solving a problem.
For example suppose you are going for a picnic with your friends then you plan for the activities
you will do there. If you have a plan of activities then you know clearly when you will do what
activity. Similarly when you have a problem to solve using computer or in other word you need to
write a computer program for a problem then it will be good to draw a flowchart prior to writing a
computer program. Flowchart is drawn according to defined rules.

1.4.1 Flowchart Symbols


1.4.4 Some examples of Flowcharts
Now, we will discuss some examples on flowcharting. These examples will help in proper
understanding of flowcharting technique. This will help you in program development process in
next unit of this block.

Problem1: Find the area of a circle of radius r.

Problem 2: Convert temperature Fahrenheit to Celsius


Problem 3: Algorithm for find the greater number between two numbers.

Problem 4: Flowchart for the problem of printing even numbers between 9 and 100:
Problem 5: Flowchart for the problem of printing odd numbers less than a given number. It should
also calculate their sum and count
Problem 6: Flowchart for the calculate the average from 25 exam scores.

1.4.5 Advantages of using Flowcharts


As we discussed flow chart is used for representing algorithm in pictorial form. This pictorial
representation of a solution/system is having many advantages. These advantages are as follows:

1) Communication: A Flowchart can be used as a better way of communication of the logic of a


system and steps involve in the solution, to all concerned particularly to the client of system.
2) Effective analysis: A flowchart of a problem can be used for effective analysis of the problem.
3) Documentation of Program/System: Program flowcharts are a vital part of a good program
documentation. Program document is used for various purposes like knowing the components in
the program, complexity of the program etc.

4) Efficient Program Maintenance: Once a program is developed and becomes operational it needs
time to time maintenance. With help of flowchart maintenance become easier.

5) Coding of the Program: Any design of solution of a problem is finally converted into computer
program. Writing code referring the flowchart of the solution become easy.

Student Written Activity 1

1) What is an algorithm?

2) Explain need of an algorithm?

3) Write an algorithm to find average age of a group of 10 players?

4) Write algorithm to this problem: Ramshewak goes to market for buying some fruits and
vegetables. He shaving a currency of Rs 500 with him for marketing. From a shop he
purchases 2.0 kg Apple priced Rs. 50.0 per kg, 1.5 kg Mango priced Rs.35.0 per kg, 2.5 kg
Potato priced Rs.10.0 per kg, and 1.0 kg Tomato priced Rs.15 per kg. He gives the currency
of Rs. 500 to the shopkeeper. Find out the amount shopkeeper will return to Ramshewak.
and also tell the total item purchased.

5) Find factorial of N?

6) Explain steps involve in drawing of a flowchart.

7) Explain uses of Flowchart.

8) Draw a flowchart to find the sum of first 100 natural numbers.

9) Draw a flowchart to find the largest of three numbers x, y and z.


10) Draw flowchart for the problem of determining prime number?

11) Draw a flowchart which generates first 50 items of the Fibonacci series:
1, 1, 2, 3, 5, 8,…?

12) Design an algorithm to convert a decimal number, n, to binary format?


Activity and Quizzes
STUDENT QUIZ 1 Written

Name: ______________________Course/Year/Section: ___________ Score: _________

Direction: Identify the following concept of communication. (2pts each)


________________1. A two-way process by which information is exchanged between
and among individuals through a common system of symbols, signs
and behavior (Martinez 1).
________________2. It refers to the form of communication in which message is
transmitted verbally.
________________3. The sending or receiving of wordless messages.
________________4. The type of communication that deals in chats and conversations.
________________5. He decides on the message to be sent, the best/most effective way
that it can be sent.
________________6. He is responsible for the delivery of the chosen message form.
________________7. It is the role under non-verbal communication that can repeat the
message the person is making verbally.
________________8. It is the role under non-verbal communication that can substitute
for a verbal message.
________________9. It is anything that gets in the way of the message being accurately
received, interpreted and responded to.
________________10. The forming the communicative intent where the sender generates
an idea.

Direction: Match the items in column A to their descriptions in column B. write only the letter of
your choice on the space provided. (2pts each)
A B
_______________1. Transmission a. Message recipients take the lead in by crafting
a response to the message.
_______________2. Response b. Refers to the information and experiences that
are provided to the receiver of the
communication process.

_______________3. Reception c. This may be as simple as meeting with the


intended recipient of the message and orally
sharing the message, or calling the individual to
communicate orally over the phone.

_______________4. Translation d. After transmitting the message, the


communication duties change hands and fall
upon the receiver of the message.

_______________5. Content e. Once receiving the message, the recipient


must translate the messages into terms that s/he
can easily understand
STUDENT WRITTEN ACTIVITY 2
Frequently Asked Questions about Flowchart (5pts each)

1. What is a system flow chart?

2. What do the Symbols mean?•

3. What are the rules for flow charts?•

4. What are the rules for flow charts?•

5. What are the rules for flow charts?•

6. What are the rules for flow charts?

STUDENT QUIZ WRTTEN # 2.


A. Draw the flowchart of the following program (10 pts)

Test Your Knowledge Ordering Lunch• Can you identify Start where the Order a sandwich
following are in the flow chart: Want Yes Order crisps• Start Crisps? No• End Want Yes• All
processes drink? Order drink No• All decisions Sit down End

STUDENT QUIZ WRTIITEN # 3. (2pts each)


1. What is the difference between Algorithm and Flowchart?
If you compare a flowchart to a movie, then an algorithm is the story of that movie. In other words,
an algorithm is the core of a flowchart. Actually, in the field of computer programming, there are
many differences between algorithm and flowchart regarding various aspects, such as the
accuracy, the way they display, and the way people feel about them. Below is a table illustrating
the differences between them in detail?
ANSWERS.
Algorithm
It is a procedure for solving problems.
The process is shown in step-by-step instruction.
It is complex and difficult to understand.
It is convenient to debug errors.
The solution is showcased in natural language.

It is somewhat easier to solve complex problem.


It costs more time to create an algorithm.

Assessment (Rubrics for Student Activity 1 and Activity 2)

LEVEL DESCRIPTION

Well written and very organized.


Excellent grammar mechanics.
5 - Outstanding Clear and concise statements.
Excellent effort and presentation with detail.
Demonstrates a thorough understanding of the topic.

Writes fairly clear.


Good grammar mechanics.
4 - Good
Good presentation and organization.
Sufficient effort and detail.
Minimal effort.
Minimal grammar mechanics.
3 - Fair
Fair presentation.
Few supporting details

Somewhat unclear.
Shows little effort.
2 - Poor Poor grammar mechanics.
Confusing and choppy, incomplete sentences.
No organization of thoughts.

Very poor grammar mechanics.


Very unclear.
1 - Very Poor
Does not address topic.
Limited attempt.

You might also like