SlideShare a Scribd company logo
1 of 35
STRUCTURED PROGRAMMING
With
C_Python_#
AJAYI, O. O.
CHAPTER TWO: THE PRINCIPLE OF
GOOD PROGRAMMING STYLE
• PROGRAMMING STYLE
• GENERAL GUIDELINES / RULES GOVERNING GOOD PROGRAMMING
STYLE
• THE STRUCTURE OF C; ITS DATA TYPES & COMMON I/O STATEMENTS
• THE STRUCTURE OF PYTHON; ITS DATA TYPES & COMMON I/O
STATEMENTS
• THE STRUCTURE OF C#; ITS DATA TYPES & COMMON I/O STATEMENTS
1.1 PROGRAMMING STYLE
•Programming style can be regarded as
guiding rules that govern writing of source
code for a computer program.
•Programming Style = English Composition
•With good programming style, debugging is
never a bug to the debugger!
-PROGRAMMING STYLE CONT’D
•Programming styles are usually designed for a
specific programming language / family language.
•C & C++: Same Style
•Basic (QBasic, GW-Basic) & VB: Same Style
•Style in C != Style in QBasic
-PROGRAMMING STYLE CONT’D
•BUT:
•We have general principles/rules which
every programming language must
conform with.
-PROGRAMMING STYLE CONT’D
•Pin-Point
•What is the essence of programming
style?
1.2 GENERAL GUIDELINES / RULES
GOVERNING GOOD PROGRAMMING STYLE
1. PROGRAM HEADER
2. INDENTATION & BRACING STYLE
3. USE OF APPROPRIATE VARIABLE NAMES
4. CONSISTENCY IN THE USE OF VARIABLE NAMES
5. NON-USAGE OF KEYWORD/RESERVED WORD
-THE RULES…
•THE PROGRAM HEADER
This rule says that, every good programming
language must have, at or near the beginning
of the program, a header block indicating the
program filename, program library header,
program purpose and other identifications
that pertain to the program (e.g. the
comment block).
• In COBOL, we have:
PROGRAM-ID. AJAYI-PRO.
PROGRAM-NAME. AJAYI-PROGRAM.
SOURCE-MACHINE. IBM-370.
OBJECT-MACHINE. IBM-370.
/* This program calculates CGPA of students*/
-PROGRAM HEADER CONT’D….INSTANCES
• Look at PASCAL:
PROGRAM. AJAYI-PROGRAM (INPUT, OUTPUT)
{* Description : This program calculates CGPA of students*}
-PROGRAM HEADER CONT’D….INSTANCES
• Consider JAVA:
Public Class AJClassPro
{
Public Static Void Main (String args[ ])
{
/* This program calculates CGPA of students */
// 2nd version of the commenting style
} }
-PROGRAM HEADER CONT’D….INSTANCES
• Now to C:
#include<stdio.h>
/* This program calculates CGPA of students */
OR
#include<stdio.h>
#include<stdlib.h>
/* This program calculates CGPA of students */
-PROGRAM HEADER CONT’D….INSTANCES
‘GET TO LIBRARY’
•Describe the compliance of the under-listed
programming languages in terms of the
program header rule:
i. C++
ii. PHP
iii. RUBY
iv. ALGOL
v. ADA
‘PIN POINT’
•Why is QBasic not considered as a
standard programming language, but
rather, a teaching and learning
language?
-THE RULES…
• INDENTATION & BRACING STYLE
Indentation helps in identifying errors in control flow
statements as well as in blocks of codes.
In a well and properly indented program, errors in
codes are easily traced.
It enhances program readability!
-THE RULES…
•INDENTATION & BRACING STYLE…
If (condition) {
// code block - Your program goes here
}
The above is called IMMEDIATE Bracing Style
-THE RULES…
•INDENTATION & BRACING STYLE…
If (condition)
{
// code block - Your program goes here
}
The above is called DIRECT Bracing Style
-THE RULES…
•USE OF APPROPRIATE VARIABLE NAMES
The use of appropriate variable name is very
important in a good programming style. Poorly-
named variables make code (program) difficult to
read and understood.
-THE RULES…
•USE OF APPROPRIATE VARIABLE NAMES…
Consider this:
get a, b, c
if a < 24 && b < 60 && c < 60
return true;
else
return false;
-THE RULES…
•USE OF APPROPRIATE VARIABLE NAMES…
Now compare with this:
get hrs, mins, secs
if hrs < 24 && mins < 60 && secs < 60
return true;
else
return false;
The latter enhances readability and understandability. However, the former can be made
better by including comments indicating/conveying the variables’ representation.
-THE RULES…
•CONSISTENCY IN THE USE OF VARIABLE NAMES
Consistency in the use of variable name implies
sticking to the use of a set of variable names
throughout your program, regardless of the case-
sensitivity or otherwise of the language.
-THE RULES…
• CONSISTENCY IN THE USE OF VARIABLE NAMES…
e.g.
int sum;
float avg;
SUM = (num1 + num2) **2
avg = Sum/2
average = average + 1
-THE RULES…
• NON-USAGE OF KEYWORD/RESERVED WORD
For a good programming style, a programmer should as much
as possible avoid the use of words that are close to or that are
reserved words or keywords. The best way of not entering into
this trap or error is by being acquainted with the language’s
keywords or reserved words.
e.g.
int get; /*where get is a reserved word in C*/
-THE STRUCTURE OF C; ITS DATA TYPES
AND COMMON I/O STATEMENTS
•THE STRUCTURE OF C
•C language comprises majorly of three (3)
structures/components. These are:
- Program header
- Declaration section
- Program Statement (Simple/Compound, enclosed in brace(s))
-THE STRUCTURE OF C; ITS DATA TYPES
AND COMMON I/O STATEMENTS
• THE STRUCTURE OF C…
• Program header
#include<stdio.h>
#include<stdlib.h>
{
……..code goes here!
}
-THE STRUCTURE OF C; ITS DATA TYPES
AND COMMON I/O STATEMENTS
•THE STRUCTURE OF C…
•Declaration Section
/* declaration section */
int x;
float y;
-THE STRUCTURE OF C; ITS DATA TYPES
AND COMMON I/O STATEMENTS
• THE STRUCTURE OF C…
• Declaration Section….fuller version
#include<stdio.h>
#include<stdlib.h>
{
int x;
float y;
…real coding goes here!
…on and on, as much as your finger can type!
}
-THE STRUCTURE OF C; ITS DATA TYPES
AND COMMON I/O STATEMENTS
• THE STRUCTURE OF C…
• Program Statement
This could be as simple as simple statement:
• Sum = x + y
OR
…as compound as the compound statement
{
Sum = x + y
Avg = Sum/2
}
-THE STRUCTURE OF C; ITS DATA TYPES
AND COMMON I/O STATEMENTS
• THE STRUCTURE OF C…
• Program Statement….Expression
EXPRESSION
Expression forms statements. The following expressions are used
in C Language:
-THE STRUCTURE OF C; ITS DATA TYPES
AND COMMON I/O STATEMENTS
• THE STRUCTURE OF C…
• Program Statement….Expression
Arithmetic expression
+, -, *, /, ^, **
Relational expression
<, >, <=, >=, <>, !=
Logical expression
OR, AND, = =, !!, &&
Assignment Expression
=
Incremental/Decremental Value
++ (INCREMENTAL – increment a value by 1); --(DECREMENTAL – decrement a value by
1)
-THE STRUCTURE OF C; ITS DATA TYPES
AND COMMON I/O STATEMENTS
• THE STRUCTURE OF C…
• DATA TYPES
We have:
i. int /* meaning integer value - i */
ii. float /* meaning float/real data type - f */
iii. double /* meaning float/real data type - d */
iv. string/char /* meaning alphanumeric data type - c/s */
-THE STRUCTURE OF C; ITS DATA TYPES
AND COMMON I/O STATEMENTS
• THE STRUCTURE OF C…
• COMMON I/O STATEMENTS
INPUT STATEMENT
• Scanf: This is an input statement that is used to supply value from the
computer screen unto computer memory. This is equivalent of the Input
Statement in Basic program.
Scanf (“%datatype”, &variable name);
e.g. Scanf (“%f”, &area);
-THE STRUCTURE OF C; ITS DATA TYPES
AND COMMON I/O STATEMENTS
• THE STRUCTURE OF C…
• COMMON I/O STATEMENTS
OUTPUT STATEMENT
• Printf: This is an output statement that retrieves processed data
from the computer memory and output to the computer screen.
Printf (“%f”, area); /*for values of variable*/
Printf (“Enter value for length: ”); /*for literals*/
Printf (“Enter value for breadth: ”); /*ditto*/
-THE STRUCTURE OF C; ITS DATA TYPES
AND COMMON I/O STATEMENTS
• THE STRUCTURE OF C…
• COMMON I/O STATEMENTS
Class Exercises
1. Write a C program that captures the values of three (3)
variables: m, n, q; computes and output the sum of their
squares.
2. Write a C program that accepts the value of a variable, x, detects
its even and prime status.
-DOWNLOAD @
• https://www.researchgate.net/publication/325860500_STRUCTURED_PROGRAMMI
NG_-_Chap2

More Related Content

What's hot

Decision Making Statements, Arrays, Strings
Decision Making Statements, Arrays, StringsDecision Making Statements, Arrays, Strings
Decision Making Statements, Arrays, StringsPrabu U
 
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Bhavin Darji
 
Techniques & applications of Compiler
Techniques & applications of CompilerTechniques & applications of Compiler
Techniques & applications of CompilerPreethi AKNR
 
Toy compiler
Toy compilerToy compiler
Toy compilerhome
 
2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life CycleFrankie Jones
 
Program logic and design
Program logic and designProgram logic and design
Program logic and designChaffey College
 
INTRODUCTION TO C++, Chapter 1
INTRODUCTION TO C++, Chapter 1INTRODUCTION TO C++, Chapter 1
INTRODUCTION TO C++, Chapter 1Mubarek Kurt
 
Digital Logic Design Lecture 01
Digital Logic Design Lecture 01Digital Logic Design Lecture 01
Digital Logic Design Lecture 01shahzad ali
 
Lecture2 general structure of a compiler
Lecture2 general structure of a compilerLecture2 general structure of a compiler
Lecture2 general structure of a compilerMahesh Kumar Chelimilla
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem slovingMani Kandan
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language ProcessingHemant Sharma
 
Introduction to programming principles languages
Introduction to programming principles languagesIntroduction to programming principles languages
Introduction to programming principles languagesFrankie Jones
 

What's hot (20)

Decision Making Statements, Arrays, Strings
Decision Making Statements, Arrays, StringsDecision Making Statements, Arrays, Strings
Decision Making Statements, Arrays, Strings
 
System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
 
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
 
Techniques & applications of Compiler
Techniques & applications of CompilerTechniques & applications of Compiler
Techniques & applications of Compiler
 
Toy compiler
Toy compilerToy compiler
Toy compiler
 
C programming
C programmingC programming
C programming
 
2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle
 
Program logic and design
Program logic and designProgram logic and design
Program logic and design
 
Chap1
Chap1Chap1
Chap1
 
Cs111 ch01 v4
Cs111 ch01 v4Cs111 ch01 v4
Cs111 ch01 v4
 
Graphical programming
Graphical programmingGraphical programming
Graphical programming
 
INTRODUCTION TO C++, Chapter 1
INTRODUCTION TO C++, Chapter 1INTRODUCTION TO C++, Chapter 1
INTRODUCTION TO C++, Chapter 1
 
Digital Logic Design Lecture 01
Digital Logic Design Lecture 01Digital Logic Design Lecture 01
Digital Logic Design Lecture 01
 
Lecture2 general structure of a compiler
Lecture2 general structure of a compilerLecture2 general structure of a compiler
Lecture2 general structure of a compiler
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem sloving
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language Processing
 
Algorithms - Introduction to computer programming
Algorithms - Introduction to computer programmingAlgorithms - Introduction to computer programming
Algorithms - Introduction to computer programming
 
Introduction to programming principles languages
Introduction to programming principles languagesIntroduction to programming principles languages
Introduction to programming principles languages
 
Mcs lec2
Mcs lec2Mcs lec2
Mcs lec2
 
Flowcharts
FlowchartsFlowcharts
Flowcharts
 

Similar to STRUCTURED PROGRAMMING Chap2

Similar to STRUCTURED PROGRAMMING Chap2 (20)

DMA Chap2
DMA Chap2DMA Chap2
DMA Chap2
 
c-introduction.pptx
c-introduction.pptxc-introduction.pptx
c-introduction.pptx
 
Structure
StructureStructure
Structure
 
c#.pptx
c#.pptxc#.pptx
c#.pptx
 
C_Programming_Notes_ICE
C_Programming_Notes_ICEC_Programming_Notes_ICE
C_Programming_Notes_ICE
 
Presentation c++
Presentation c++Presentation c++
Presentation c++
 
Basics of C Prog Lang.pdf
Basics of C Prog Lang.pdfBasics of C Prog Lang.pdf
Basics of C Prog Lang.pdf
 
C prog ppt
C prog pptC prog ppt
C prog ppt
 
Unit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxUnit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptx
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
 
Copy of UNIT 2 -- Basics Of Programming.pptx
Copy of UNIT 2 -- Basics Of Programming.pptxCopy of UNIT 2 -- Basics Of Programming.pptx
Copy of UNIT 2 -- Basics Of Programming.pptx
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
Chapter 1: Introduction
Chapter 1: IntroductionChapter 1: Introduction
Chapter 1: Introduction
 
Introduction of c programming unit-ii ppt
Introduction of  c programming unit-ii pptIntroduction of  c programming unit-ii ppt
Introduction of c programming unit-ii ppt
 
PROGRAMMING IN C - SARASWATHI RAMALINGAM
PROGRAMMING IN C - SARASWATHI RAMALINGAMPROGRAMMING IN C - SARASWATHI RAMALINGAM
PROGRAMMING IN C - SARASWATHI RAMALINGAM
 

More from Bro Shola Ajayi

More from Bro Shola Ajayi (12)

DMA113 Chap1
DMA113 Chap1DMA113 Chap1
DMA113 Chap1
 
CSC431_Chap1
CSC431_Chap1CSC431_Chap1
CSC431_Chap1
 
Csc303 part1 chap1
Csc303 part1 chap1Csc303 part1 chap1
Csc303 part1 chap1
 
INTRO TO SQL
INTRO TO SQLINTRO TO SQL
INTRO TO SQL
 
Intro to Web Prog
Intro to Web ProgIntro to Web Prog
Intro to Web Prog
 
Database: An Intro
Database: An IntroDatabase: An Intro
Database: An Intro
 
Database: An Introduction
Database: An IntroductionDatabase: An Introduction
Database: An Introduction
 
Seminar on cgpa calculation
Seminar on cgpa calculationSeminar on cgpa calculation
Seminar on cgpa calculation
 
CSC426 - SDLC Models
CSC426 - SDLC ModelsCSC426 - SDLC Models
CSC426 - SDLC Models
 
CSC426 - Software Engineering Lecture Note Cont'd
CSC426   - Software Engineering Lecture Note Cont'dCSC426   - Software Engineering Lecture Note Cont'd
CSC426 - Software Engineering Lecture Note Cont'd
 
CSC426 - Software Engineering Lecture Note
CSC426   - Software Engineering Lecture NoteCSC426   - Software Engineering Lecture Note
CSC426 - Software Engineering Lecture Note
 
Requirement analysis
Requirement analysisRequirement analysis
Requirement analysis
 

Recently uploaded

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

STRUCTURED PROGRAMMING Chap2

  • 2. CHAPTER TWO: THE PRINCIPLE OF GOOD PROGRAMMING STYLE • PROGRAMMING STYLE • GENERAL GUIDELINES / RULES GOVERNING GOOD PROGRAMMING STYLE • THE STRUCTURE OF C; ITS DATA TYPES & COMMON I/O STATEMENTS • THE STRUCTURE OF PYTHON; ITS DATA TYPES & COMMON I/O STATEMENTS • THE STRUCTURE OF C#; ITS DATA TYPES & COMMON I/O STATEMENTS
  • 3. 1.1 PROGRAMMING STYLE •Programming style can be regarded as guiding rules that govern writing of source code for a computer program. •Programming Style = English Composition •With good programming style, debugging is never a bug to the debugger!
  • 4. -PROGRAMMING STYLE CONT’D •Programming styles are usually designed for a specific programming language / family language. •C & C++: Same Style •Basic (QBasic, GW-Basic) & VB: Same Style •Style in C != Style in QBasic
  • 5. -PROGRAMMING STYLE CONT’D •BUT: •We have general principles/rules which every programming language must conform with.
  • 6. -PROGRAMMING STYLE CONT’D •Pin-Point •What is the essence of programming style?
  • 7. 1.2 GENERAL GUIDELINES / RULES GOVERNING GOOD PROGRAMMING STYLE 1. PROGRAM HEADER 2. INDENTATION & BRACING STYLE 3. USE OF APPROPRIATE VARIABLE NAMES 4. CONSISTENCY IN THE USE OF VARIABLE NAMES 5. NON-USAGE OF KEYWORD/RESERVED WORD
  • 8. -THE RULES… •THE PROGRAM HEADER This rule says that, every good programming language must have, at or near the beginning of the program, a header block indicating the program filename, program library header, program purpose and other identifications that pertain to the program (e.g. the comment block).
  • 9. • In COBOL, we have: PROGRAM-ID. AJAYI-PRO. PROGRAM-NAME. AJAYI-PROGRAM. SOURCE-MACHINE. IBM-370. OBJECT-MACHINE. IBM-370. /* This program calculates CGPA of students*/ -PROGRAM HEADER CONT’D….INSTANCES
  • 10. • Look at PASCAL: PROGRAM. AJAYI-PROGRAM (INPUT, OUTPUT) {* Description : This program calculates CGPA of students*} -PROGRAM HEADER CONT’D….INSTANCES
  • 11. • Consider JAVA: Public Class AJClassPro { Public Static Void Main (String args[ ]) { /* This program calculates CGPA of students */ // 2nd version of the commenting style } } -PROGRAM HEADER CONT’D….INSTANCES
  • 12. • Now to C: #include<stdio.h> /* This program calculates CGPA of students */ OR #include<stdio.h> #include<stdlib.h> /* This program calculates CGPA of students */ -PROGRAM HEADER CONT’D….INSTANCES
  • 13. ‘GET TO LIBRARY’ •Describe the compliance of the under-listed programming languages in terms of the program header rule: i. C++ ii. PHP iii. RUBY iv. ALGOL v. ADA
  • 14. ‘PIN POINT’ •Why is QBasic not considered as a standard programming language, but rather, a teaching and learning language?
  • 15. -THE RULES… • INDENTATION & BRACING STYLE Indentation helps in identifying errors in control flow statements as well as in blocks of codes. In a well and properly indented program, errors in codes are easily traced. It enhances program readability!
  • 16. -THE RULES… •INDENTATION & BRACING STYLE… If (condition) { // code block - Your program goes here } The above is called IMMEDIATE Bracing Style
  • 17. -THE RULES… •INDENTATION & BRACING STYLE… If (condition) { // code block - Your program goes here } The above is called DIRECT Bracing Style
  • 18. -THE RULES… •USE OF APPROPRIATE VARIABLE NAMES The use of appropriate variable name is very important in a good programming style. Poorly- named variables make code (program) difficult to read and understood.
  • 19. -THE RULES… •USE OF APPROPRIATE VARIABLE NAMES… Consider this: get a, b, c if a < 24 && b < 60 && c < 60 return true; else return false;
  • 20. -THE RULES… •USE OF APPROPRIATE VARIABLE NAMES… Now compare with this: get hrs, mins, secs if hrs < 24 && mins < 60 && secs < 60 return true; else return false; The latter enhances readability and understandability. However, the former can be made better by including comments indicating/conveying the variables’ representation.
  • 21. -THE RULES… •CONSISTENCY IN THE USE OF VARIABLE NAMES Consistency in the use of variable name implies sticking to the use of a set of variable names throughout your program, regardless of the case- sensitivity or otherwise of the language.
  • 22. -THE RULES… • CONSISTENCY IN THE USE OF VARIABLE NAMES… e.g. int sum; float avg; SUM = (num1 + num2) **2 avg = Sum/2 average = average + 1
  • 23. -THE RULES… • NON-USAGE OF KEYWORD/RESERVED WORD For a good programming style, a programmer should as much as possible avoid the use of words that are close to or that are reserved words or keywords. The best way of not entering into this trap or error is by being acquainted with the language’s keywords or reserved words. e.g. int get; /*where get is a reserved word in C*/
  • 24. -THE STRUCTURE OF C; ITS DATA TYPES AND COMMON I/O STATEMENTS •THE STRUCTURE OF C •C language comprises majorly of three (3) structures/components. These are: - Program header - Declaration section - Program Statement (Simple/Compound, enclosed in brace(s))
  • 25. -THE STRUCTURE OF C; ITS DATA TYPES AND COMMON I/O STATEMENTS • THE STRUCTURE OF C… • Program header #include<stdio.h> #include<stdlib.h> { ……..code goes here! }
  • 26. -THE STRUCTURE OF C; ITS DATA TYPES AND COMMON I/O STATEMENTS •THE STRUCTURE OF C… •Declaration Section /* declaration section */ int x; float y;
  • 27. -THE STRUCTURE OF C; ITS DATA TYPES AND COMMON I/O STATEMENTS • THE STRUCTURE OF C… • Declaration Section….fuller version #include<stdio.h> #include<stdlib.h> { int x; float y; …real coding goes here! …on and on, as much as your finger can type! }
  • 28. -THE STRUCTURE OF C; ITS DATA TYPES AND COMMON I/O STATEMENTS • THE STRUCTURE OF C… • Program Statement This could be as simple as simple statement: • Sum = x + y OR …as compound as the compound statement { Sum = x + y Avg = Sum/2 }
  • 29. -THE STRUCTURE OF C; ITS DATA TYPES AND COMMON I/O STATEMENTS • THE STRUCTURE OF C… • Program Statement….Expression EXPRESSION Expression forms statements. The following expressions are used in C Language:
  • 30. -THE STRUCTURE OF C; ITS DATA TYPES AND COMMON I/O STATEMENTS • THE STRUCTURE OF C… • Program Statement….Expression Arithmetic expression +, -, *, /, ^, ** Relational expression <, >, <=, >=, <>, != Logical expression OR, AND, = =, !!, && Assignment Expression = Incremental/Decremental Value ++ (INCREMENTAL – increment a value by 1); --(DECREMENTAL – decrement a value by 1)
  • 31. -THE STRUCTURE OF C; ITS DATA TYPES AND COMMON I/O STATEMENTS • THE STRUCTURE OF C… • DATA TYPES We have: i. int /* meaning integer value - i */ ii. float /* meaning float/real data type - f */ iii. double /* meaning float/real data type - d */ iv. string/char /* meaning alphanumeric data type - c/s */
  • 32. -THE STRUCTURE OF C; ITS DATA TYPES AND COMMON I/O STATEMENTS • THE STRUCTURE OF C… • COMMON I/O STATEMENTS INPUT STATEMENT • Scanf: This is an input statement that is used to supply value from the computer screen unto computer memory. This is equivalent of the Input Statement in Basic program. Scanf (“%datatype”, &variable name); e.g. Scanf (“%f”, &area);
  • 33. -THE STRUCTURE OF C; ITS DATA TYPES AND COMMON I/O STATEMENTS • THE STRUCTURE OF C… • COMMON I/O STATEMENTS OUTPUT STATEMENT • Printf: This is an output statement that retrieves processed data from the computer memory and output to the computer screen. Printf (“%f”, area); /*for values of variable*/ Printf (“Enter value for length: ”); /*for literals*/ Printf (“Enter value for breadth: ”); /*ditto*/
  • 34. -THE STRUCTURE OF C; ITS DATA TYPES AND COMMON I/O STATEMENTS • THE STRUCTURE OF C… • COMMON I/O STATEMENTS Class Exercises 1. Write a C program that captures the values of three (3) variables: m, n, q; computes and output the sum of their squares. 2. Write a C program that accepts the value of a variable, x, detects its even and prime status.