際際滷

際際滷Share a Scribd company logo
PRINCIPLE & TECHNIQUES OF
PROGRAMMING LANGUAGES
With
Basic_Python
AJAYI O. O., PhD
CHAPTER TWO: THE PRINCIPLE OF
GOOD PROGRAMMING STYLE
PROGRAMMING STYLE
GENERAL GUIDELINES / RULES GOVERNING
GOOD PROGRAMMING STYLE
THE STRUCTURE OF QBASIC AND ITS COMMON
I/O STATEMENTS
2.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 CONTD
Programming styles are usually designed for a
specific programming language / family language.
i. C & C++: Same Style
ii. Basic (QBasic, GW-Basic) & VB: Same Style
iii. Style in C != Style in QBasic
-PROGRAMMING STYLE CONTD
BUT:
We have general principles/rules which
every programming language must
conform with.
2.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 CONTD.INSTANCES
 Look at PASCAL:
PROGRAM. AJAYI-PROGRAM (INPUT, OUTPUT)
{* Description : This program calculates CGPA of students*}
-PROGRAM HEADER CONTD.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 CONTD.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 CONTD.INSTANCES
 And C++, we have it as:
#include<iostream>
using namespace
//You can insert comments here or anywhere
Main()
{
}
-PROGRAM HEADER CONTD.INSTANCES
-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 languages
keywords or reserved words.
e.g.
int get; /*where get is a reserved word in C*/
2.3 THE STRUCTURE OF QBASIC AND
ITS COMMON I/O STATEMENTS
 THE STRUCTURE OF QBASIC
QBasic is a procedural language. Unlike object-
oriented language, it has no standard structure
according to programming style rule. Howbeit, it
does have structure for programmers to follow.
2.3 THE STRUCTURE OF QBASIC AND
ITS COMMON I/O STATEMENTS
GUIDE TO QBASIC STRUCTURE
i. Line Number: Programs in QBasic are easily written
with line numbers for readability purpose.
ii. CLS: This means Clear Screen
iii. REM: Implies REMark  Comment.
iv. END: To signify the end of a program
2.3 THE STRUCTURE OF QBASIC AND
ITS COMMON I/O STATEMENTS
 GUIDE TO QBASIC STRUCTURE- ILLUSTRATION
 For example, the program below does nothing but shows the guide
to QBasic Structure:
5 CLS
10 REM
15 END
OR
2 CLS
4 REM
6 END
2.3 THE STRUCTURE OF QBASIC AND
ITS COMMON I/O STATEMENTS
 GARBAGE IN & OUT IN QBASIC
 INPUT STATEMENT
 To feed/supply data unto the computer system using QBasic,
we make use of any of the following two commands:
INPUT statement
READ&DATA statement
2.3 THE STRUCTURE OF QBASIC AND
ITS COMMON I/O STATEMENTS
 GARBAGE IN & OUT IN QBASIC
 OUTPUT STATEMENTS
 These are statements that are used for fetch/retrieve/show
to screen, inputted or stored data from the computer
system.
 The major/basic output statement used in QBasic is called
PRINT.
ILLUSTRATIONS
 Coding Examples
 Open your System and See the Examples to be done on
the board NOW!
EXAMPLE 1
Code in QBasic to output the literals:
BIO-DATA Quiz
HE was born and brought up in Lagos.
He hails from Kwara.
He settles down in Ondo.
Who is He?
SOLUTION
5 CLS
10 REM
15 Print BIO-DATA Quiz
20 Print _____________
25 Print He was born and brought up in Lagos.
30 Print He hails from Kwara.
35 Print He settles down in Ondo.
40 Print
45 Print Who is He?
50 END
EXAMPLE 2
Given two variables: birthyear and
currentyear, input values for the two
variables and compute your AGE by
finding the difference of the two
variables.
SOLUTION
5 CLS
10 REM
15 INPUT birthyear
20 INPUT currentyear
25 yourage = currentyear  birthyear
30 PRINT currentyear-birthyear
35 END
EXAMPLE 3
Given:
y = 18, u = 21, r = 11
Code in QBasic to compute:
V = y + (u  r)
SOLUTION
5 CLS
10 REM
15 READ y, u, r
20 DATA 15, 210, 11
30 Let V = (y + (u-r))
35 PRINT The answer is: , V
40 END
TAKE HOME
Check your manual, solve and print the
output of the questions in Lab Exercise 1, 2
and 3 (Pages 45 & 46)

More Related Content

What's hot (9)

Code Generation in Perl
Code Generation in PerlCode Generation in Perl
Code Generation in Perl
Ian Kluft
PL Lecture 02 - Binding and Scope
PL Lecture 02 - Binding and ScopePL Lecture 02 - Binding and Scope
PL Lecture 02 - Binding and Scope
Schwannden Kuo
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
patricia Hidalgo
Programming language
Programming languageProgramming language
Programming language
Dhani Ahmad
javabasics_ programming development chapter01
javabasics_ programming development chapter01javabasics_ programming development chapter01
javabasics_ programming development chapter01
Udeshg90
PL Lecture 01 - preliminaries
PL Lecture 01 - preliminariesPL Lecture 01 - preliminaries
PL Lecture 01 - preliminaries
Schwannden Kuo
Programming paradigms
Programming paradigmsProgramming paradigms
Programming paradigms
AVC College of Engineering
Code: from Procedural to Object Oriented
Code: from Procedural to Object OrientedCode: from Procedural to Object Oriented
Code: from Procedural to Object Oriented
kleinron
Language Workbenches
Language WorkbenchesLanguage Workbenches
Language Workbenches
Mikhail Barash
Code Generation in Perl
Code Generation in PerlCode Generation in Perl
Code Generation in Perl
Ian Kluft
PL Lecture 02 - Binding and Scope
PL Lecture 02 - Binding and ScopePL Lecture 02 - Binding and Scope
PL Lecture 02 - Binding and Scope
Schwannden Kuo
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
patricia Hidalgo
Programming language
Programming languageProgramming language
Programming language
Dhani Ahmad
javabasics_ programming development chapter01
javabasics_ programming development chapter01javabasics_ programming development chapter01
javabasics_ programming development chapter01
Udeshg90
PL Lecture 01 - preliminaries
PL Lecture 01 - preliminariesPL Lecture 01 - preliminaries
PL Lecture 01 - preliminaries
Schwannden Kuo
Code: from Procedural to Object Oriented
Code: from Procedural to Object OrientedCode: from Procedural to Object Oriented
Code: from Procedural to Object Oriented
kleinron
Language Workbenches
Language WorkbenchesLanguage Workbenches
Language Workbenches
Mikhail Barash

Similar to DMA Chap2 (20)

STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2
Bro Shola Ajayi
Computer programming
Computer programmingComputer programming
Computer programming
Vincent Valenzuela
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
softwaree construction and development scd
softwaree construction and development scdsoftwaree construction and development scd
softwaree construction and development scd
Sami Mughal
Coding
CodingCoding
Coding
Anand Mutyala
C_Programming_Notes_ICE
C_Programming_Notes_ICEC_Programming_Notes_ICE
C_Programming_Notes_ICE
Gilbert NZABONITEGEKA
Basics of C Prog Lang.pdf
Basics of C Prog Lang.pdfBasics of C Prog Lang.pdf
Basics of C Prog Lang.pdf
KalighatOkira
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelines
Ankur Goyal
c#.pptx
c#.pptxc#.pptx
c#.pptx
JoselitoJMebolos
Qbasic program
Qbasic programQbasic program
Qbasic program
Fercie Caseria
Qbasic
QbasicQbasic
Qbasic
Fercie Caseria
Presentation c++
Presentation c++Presentation c++
Presentation c++
JosephAlex21
Embedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals masterEmbedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals master
Hossam Hassan
psp-all-unit-lecture-content- all syllabus
psp-all-unit-lecture-content- all syllabuspsp-all-unit-lecture-content- all syllabus
psp-all-unit-lecture-content- all syllabus
Priyadarshini803769
Intro in understanding to C programming .pptx
Intro in understanding to C   programming .pptxIntro in understanding to C   programming .pptx
Intro in understanding to C programming .pptx
abadinasargie
Intro in understanding to C programming .pptx
Intro in understanding to C   programming .pptxIntro in understanding to C   programming .pptx
Intro in understanding to C programming .pptx
abadinasargie
Introduction To Programming subject1.ppt
Introduction To Programming subject1.pptIntroduction To Programming subject1.ppt
Introduction To Programming subject1.ppt
uf88605
Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02
riddhi viradiya
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
ManiMala75
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
ManiMala75
STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2
Bro Shola Ajayi
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
softwaree construction and development scd
softwaree construction and development scdsoftwaree construction and development scd
softwaree construction and development scd
Sami Mughal
Basics of C Prog Lang.pdf
Basics of C Prog Lang.pdfBasics of C Prog Lang.pdf
Basics of C Prog Lang.pdf
KalighatOkira
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelines
Ankur Goyal
Presentation c++
Presentation c++Presentation c++
Presentation c++
JosephAlex21
Embedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals masterEmbedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals master
Hossam Hassan
psp-all-unit-lecture-content- all syllabus
psp-all-unit-lecture-content- all syllabuspsp-all-unit-lecture-content- all syllabus
psp-all-unit-lecture-content- all syllabus
Priyadarshini803769
Intro in understanding to C programming .pptx
Intro in understanding to C   programming .pptxIntro in understanding to C   programming .pptx
Intro in understanding to C programming .pptx
abadinasargie
Intro in understanding to C programming .pptx
Intro in understanding to C   programming .pptxIntro in understanding to C   programming .pptx
Intro in understanding to C programming .pptx
abadinasargie
Introduction To Programming subject1.ppt
Introduction To Programming subject1.pptIntroduction To Programming subject1.ppt
Introduction To Programming subject1.ppt
uf88605
Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02
riddhi viradiya
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
ManiMala75
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
ManiMala75

More from Bro Shola Ajayi (13)

DMA113 Chap1
DMA113 Chap1DMA113 Chap1
DMA113 Chap1
Bro Shola Ajayi
CSC431_Chap1
CSC431_Chap1CSC431_Chap1
CSC431_Chap1
Bro Shola Ajayi
Csc413 chap1
Csc413 chap1Csc413 chap1
Csc413 chap1
Bro Shola Ajayi
Csc303 part1 chap1
Csc303 part1 chap1Csc303 part1 chap1
Csc303 part1 chap1
Bro Shola Ajayi
INTRO TO SQL
INTRO TO SQLINTRO TO SQL
INTRO TO SQL
Bro Shola Ajayi
Intro to Web Prog
Intro to Web ProgIntro to Web Prog
Intro to Web Prog
Bro Shola Ajayi
Database: An Intro
Database: An IntroDatabase: An Intro
Database: An Intro
Bro Shola Ajayi
Database: An Introduction
Database: An IntroductionDatabase: An Introduction
Database: An Introduction
Bro Shola Ajayi
Seminar on cgpa calculation
Seminar on cgpa calculationSeminar on cgpa calculation
Seminar on cgpa calculation
Bro Shola Ajayi
CSC426 - SDLC Models
CSC426 - SDLC ModelsCSC426 - SDLC Models
CSC426 - SDLC Models
Bro Shola Ajayi
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
Bro Shola Ajayi
CSC426 - Software Engineering Lecture Note
CSC426   - Software Engineering Lecture NoteCSC426   - Software Engineering Lecture Note
CSC426 - Software Engineering Lecture Note
Bro Shola Ajayi
Requirement analysis
Requirement analysisRequirement analysis
Requirement analysis
Bro Shola Ajayi
Database: An Introduction
Database: An IntroductionDatabase: An Introduction
Database: An Introduction
Bro Shola Ajayi
Seminar on cgpa calculation
Seminar on cgpa calculationSeminar on cgpa calculation
Seminar on cgpa calculation
Bro Shola Ajayi
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
Bro Shola Ajayi
CSC426 - Software Engineering Lecture Note
CSC426   - Software Engineering Lecture NoteCSC426   - Software Engineering Lecture Note
CSC426 - Software Engineering Lecture Note
Bro Shola Ajayi

Recently uploaded (20)

RRB ALP CBT 2 Heat Engine Question Paper MCQ (Railway Assistant Loco Pilot)
RRB ALP CBT 2 Heat Engine Question Paper MCQ (Railway Assistant Loco Pilot)RRB ALP CBT 2 Heat Engine Question Paper MCQ (Railway Assistant Loco Pilot)
RRB ALP CBT 2 Heat Engine Question Paper MCQ (Railway Assistant Loco Pilot)
SONU HEETSON
MAT221: CALCULUS II | Transcendental Functions -Exponential and Logarithmic F...
MAT221: CALCULUS II | Transcendental Functions -Exponential and Logarithmic F...MAT221: CALCULUS II | Transcendental Functions -Exponential and Logarithmic F...
MAT221: CALCULUS II | Transcendental Functions -Exponential and Logarithmic F...
Josophat Makawa
THE REVOLT OF THE MASSES BABASAHIN HINGIL
THE REVOLT OF THE MASSES BABASAHIN HINGILTHE REVOLT OF THE MASSES BABASAHIN HINGIL
THE REVOLT OF THE MASSES BABASAHIN HINGIL
rytzzgrieta
teacher activies un classroom and students
teacher activies un classroom and studentsteacher activies un classroom and students
teacher activies un classroom and students
prabowoedy1
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
Meeting the needs of modern students?, Selina McCoy
Meeting the needs of modern students?, Selina McCoyMeeting the needs of modern students?, Selina McCoy
Meeting the needs of modern students?, Selina McCoy
Economic and Social Research Institute
Unit 1 Computer Hardware for Educational Computing.pptx
Unit 1 Computer Hardware for Educational Computing.pptxUnit 1 Computer Hardware for Educational Computing.pptx
Unit 1 Computer Hardware for Educational Computing.pptx
RomaSmart1
2024 Summer Nutrition North Carolina Profile
2024 Summer Nutrition North Carolina Profile2024 Summer Nutrition North Carolina Profile
2024 Summer Nutrition North Carolina Profile
Mebane Rash
One Click RFQ Cancellation in Odoo 18 - Odoo 際際滷s
One Click RFQ Cancellation in Odoo 18 - Odoo 際際滷sOne Click RFQ Cancellation in Odoo 18 - Odoo 際際滷s
One Click RFQ Cancellation in Odoo 18 - Odoo 際際滷s
Celine George
Electronics Mechanic Question Paper MCQ Book PDF Free Download
Electronics Mechanic Question Paper MCQ Book PDF Free DownloadElectronics Mechanic Question Paper MCQ Book PDF Free Download
Electronics Mechanic Question Paper MCQ Book PDF Free Download
SONU HEETSON
2025 MSKMUN NEWS-1-The MSKMUN 2025 is coming
2025 MSKMUN NEWS-1-The MSKMUN 2025 is coming2025 MSKMUN NEWS-1-The MSKMUN 2025 is coming
2025 MSKMUN NEWS-1-The MSKMUN 2025 is coming
1mksmunathens
ASP.NET Interview Questions PDF By ScholarHat
ASP.NET  Interview Questions PDF By ScholarHatASP.NET  Interview Questions PDF By ScholarHat
ASP.NET Interview Questions PDF By ScholarHat
Scholarhat
Full-Stack .NET Developer Interview Questions PDF By ScholarHat
Full-Stack .NET Developer Interview Questions PDF By ScholarHatFull-Stack .NET Developer Interview Questions PDF By ScholarHat
Full-Stack .NET Developer Interview Questions PDF By ScholarHat
Scholarhat
Entity Framework Interview Questions PDF By ScholarHat
Entity Framework Interview Questions PDF By ScholarHatEntity Framework Interview Questions PDF By ScholarHat
Entity Framework Interview Questions PDF By ScholarHat
Scholarhat
Azure Data Engineer Interview Questions By ScholarHat
Azure Data Engineer Interview Questions By ScholarHatAzure Data Engineer Interview Questions By ScholarHat
Azure Data Engineer Interview Questions By ScholarHat
Scholarhat
Chapter 2. Strategic Management: Corporate Governance.pdf
Chapter 2. Strategic Management: Corporate Governance.pdfChapter 2. Strategic Management: Corporate Governance.pdf
Chapter 2. Strategic Management: Corporate Governance.pdf
Rommel Regala
AI and Academic Writing, Short Term Course in Academic Writing and Publicatio...
AI and Academic Writing, Short Term Course in Academic Writing and Publicatio...AI and Academic Writing, Short Term Course in Academic Writing and Publicatio...
AI and Academic Writing, Short Term Course in Academic Writing and Publicatio...
Prof. (Dr.) Vinod Kumar Kanvaria
lklklklklklklklklklklklklklklklklklklklklklklklklklklklk
lklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklk
lklklklklklklklklklklklklklklklklklklklklklklklklklklklk
preetheshparmar
1111.pptx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1111.pptx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1111.pptx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1111.pptx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Praksha3
Mastering Soft Tissue Therapy & Sports Taping
Mastering Soft Tissue Therapy & Sports TapingMastering Soft Tissue Therapy & Sports Taping
Mastering Soft Tissue Therapy & Sports Taping
Kusal Goonewardena
RRB ALP CBT 2 Heat Engine Question Paper MCQ (Railway Assistant Loco Pilot)
RRB ALP CBT 2 Heat Engine Question Paper MCQ (Railway Assistant Loco Pilot)RRB ALP CBT 2 Heat Engine Question Paper MCQ (Railway Assistant Loco Pilot)
RRB ALP CBT 2 Heat Engine Question Paper MCQ (Railway Assistant Loco Pilot)
SONU HEETSON
MAT221: CALCULUS II | Transcendental Functions -Exponential and Logarithmic F...
MAT221: CALCULUS II | Transcendental Functions -Exponential and Logarithmic F...MAT221: CALCULUS II | Transcendental Functions -Exponential and Logarithmic F...
MAT221: CALCULUS II | Transcendental Functions -Exponential and Logarithmic F...
Josophat Makawa
THE REVOLT OF THE MASSES BABASAHIN HINGIL
THE REVOLT OF THE MASSES BABASAHIN HINGILTHE REVOLT OF THE MASSES BABASAHIN HINGIL
THE REVOLT OF THE MASSES BABASAHIN HINGIL
rytzzgrieta
teacher activies un classroom and students
teacher activies un classroom and studentsteacher activies un classroom and students
teacher activies un classroom and students
prabowoedy1
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
Unit 1 Computer Hardware for Educational Computing.pptx
Unit 1 Computer Hardware for Educational Computing.pptxUnit 1 Computer Hardware for Educational Computing.pptx
Unit 1 Computer Hardware for Educational Computing.pptx
RomaSmart1
2024 Summer Nutrition North Carolina Profile
2024 Summer Nutrition North Carolina Profile2024 Summer Nutrition North Carolina Profile
2024 Summer Nutrition North Carolina Profile
Mebane Rash
One Click RFQ Cancellation in Odoo 18 - Odoo 際際滷s
One Click RFQ Cancellation in Odoo 18 - Odoo 際際滷sOne Click RFQ Cancellation in Odoo 18 - Odoo 際際滷s
One Click RFQ Cancellation in Odoo 18 - Odoo 際際滷s
Celine George
Electronics Mechanic Question Paper MCQ Book PDF Free Download
Electronics Mechanic Question Paper MCQ Book PDF Free DownloadElectronics Mechanic Question Paper MCQ Book PDF Free Download
Electronics Mechanic Question Paper MCQ Book PDF Free Download
SONU HEETSON
2025 MSKMUN NEWS-1-The MSKMUN 2025 is coming
2025 MSKMUN NEWS-1-The MSKMUN 2025 is coming2025 MSKMUN NEWS-1-The MSKMUN 2025 is coming
2025 MSKMUN NEWS-1-The MSKMUN 2025 is coming
1mksmunathens
ASP.NET Interview Questions PDF By ScholarHat
ASP.NET  Interview Questions PDF By ScholarHatASP.NET  Interview Questions PDF By ScholarHat
ASP.NET Interview Questions PDF By ScholarHat
Scholarhat
Full-Stack .NET Developer Interview Questions PDF By ScholarHat
Full-Stack .NET Developer Interview Questions PDF By ScholarHatFull-Stack .NET Developer Interview Questions PDF By ScholarHat
Full-Stack .NET Developer Interview Questions PDF By ScholarHat
Scholarhat
Entity Framework Interview Questions PDF By ScholarHat
Entity Framework Interview Questions PDF By ScholarHatEntity Framework Interview Questions PDF By ScholarHat
Entity Framework Interview Questions PDF By ScholarHat
Scholarhat
Azure Data Engineer Interview Questions By ScholarHat
Azure Data Engineer Interview Questions By ScholarHatAzure Data Engineer Interview Questions By ScholarHat
Azure Data Engineer Interview Questions By ScholarHat
Scholarhat
Chapter 2. Strategic Management: Corporate Governance.pdf
Chapter 2. Strategic Management: Corporate Governance.pdfChapter 2. Strategic Management: Corporate Governance.pdf
Chapter 2. Strategic Management: Corporate Governance.pdf
Rommel Regala
AI and Academic Writing, Short Term Course in Academic Writing and Publicatio...
AI and Academic Writing, Short Term Course in Academic Writing and Publicatio...AI and Academic Writing, Short Term Course in Academic Writing and Publicatio...
AI and Academic Writing, Short Term Course in Academic Writing and Publicatio...
Prof. (Dr.) Vinod Kumar Kanvaria
lklklklklklklklklklklklklklklklklklklklklklklklklklklklk
lklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklklk
lklklklklklklklklklklklklklklklklklklklklklklklklklklklk
preetheshparmar
1111.pptx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1111.pptx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1111.pptx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1111.pptx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Praksha3
Mastering Soft Tissue Therapy & Sports Taping
Mastering Soft Tissue Therapy & Sports TapingMastering Soft Tissue Therapy & Sports Taping
Mastering Soft Tissue Therapy & Sports Taping
Kusal Goonewardena

DMA Chap2

  • 1. PRINCIPLE & TECHNIQUES OF PROGRAMMING LANGUAGES With Basic_Python AJAYI O. O., PhD
  • 2. CHAPTER TWO: THE PRINCIPLE OF GOOD PROGRAMMING STYLE PROGRAMMING STYLE GENERAL GUIDELINES / RULES GOVERNING GOOD PROGRAMMING STYLE THE STRUCTURE OF QBASIC AND ITS COMMON I/O STATEMENTS
  • 3. 2.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 CONTD Programming styles are usually designed for a specific programming language / family language. i. C & C++: Same Style ii. Basic (QBasic, GW-Basic) & VB: Same Style iii. Style in C != Style in QBasic
  • 5. -PROGRAMMING STYLE CONTD BUT: We have general principles/rules which every programming language must conform with.
  • 6. 2.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
  • 7. -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).
  • 8. 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 CONTD.INSTANCES
  • 9. Look at PASCAL: PROGRAM. AJAYI-PROGRAM (INPUT, OUTPUT) {* Description : This program calculates CGPA of students*} -PROGRAM HEADER CONTD.INSTANCES
  • 10. 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 CONTD.INSTANCES
  • 11. 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 CONTD.INSTANCES
  • 12. And C++, we have it as: #include<iostream> using namespace //You can insert comments here or anywhere Main() { } -PROGRAM HEADER CONTD.INSTANCES
  • 13. -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!
  • 14. -THE RULES INDENTATION & BRACING STYLE If (condition) { // code block - Your program goes here } The above is called IMMEDIATE Bracing Style
  • 15. -THE RULES INDENTATION & BRACING STYLE If (condition) { // code block - Your program goes here } The above is called DIRECT Bracing Style
  • 16. -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.
  • 17. -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;
  • 18. -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.
  • 19. -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.
  • 20. -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
  • 21. -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 languages keywords or reserved words. e.g. int get; /*where get is a reserved word in C*/
  • 22. 2.3 THE STRUCTURE OF QBASIC AND ITS COMMON I/O STATEMENTS THE STRUCTURE OF QBASIC QBasic is a procedural language. Unlike object- oriented language, it has no standard structure according to programming style rule. Howbeit, it does have structure for programmers to follow.
  • 23. 2.3 THE STRUCTURE OF QBASIC AND ITS COMMON I/O STATEMENTS GUIDE TO QBASIC STRUCTURE i. Line Number: Programs in QBasic are easily written with line numbers for readability purpose. ii. CLS: This means Clear Screen iii. REM: Implies REMark Comment. iv. END: To signify the end of a program
  • 24. 2.3 THE STRUCTURE OF QBASIC AND ITS COMMON I/O STATEMENTS GUIDE TO QBASIC STRUCTURE- ILLUSTRATION For example, the program below does nothing but shows the guide to QBasic Structure: 5 CLS 10 REM 15 END OR 2 CLS 4 REM 6 END
  • 25. 2.3 THE STRUCTURE OF QBASIC AND ITS COMMON I/O STATEMENTS GARBAGE IN & OUT IN QBASIC INPUT STATEMENT To feed/supply data unto the computer system using QBasic, we make use of any of the following two commands: INPUT statement READ&DATA statement
  • 26. 2.3 THE STRUCTURE OF QBASIC AND ITS COMMON I/O STATEMENTS GARBAGE IN & OUT IN QBASIC OUTPUT STATEMENTS These are statements that are used for fetch/retrieve/show to screen, inputted or stored data from the computer system. The major/basic output statement used in QBasic is called PRINT.
  • 27. ILLUSTRATIONS Coding Examples Open your System and See the Examples to be done on the board NOW!
  • 28. EXAMPLE 1 Code in QBasic to output the literals: BIO-DATA Quiz HE was born and brought up in Lagos. He hails from Kwara. He settles down in Ondo. Who is He?
  • 29. SOLUTION 5 CLS 10 REM 15 Print BIO-DATA Quiz 20 Print _____________ 25 Print He was born and brought up in Lagos. 30 Print He hails from Kwara. 35 Print He settles down in Ondo. 40 Print 45 Print Who is He? 50 END
  • 30. EXAMPLE 2 Given two variables: birthyear and currentyear, input values for the two variables and compute your AGE by finding the difference of the two variables.
  • 31. SOLUTION 5 CLS 10 REM 15 INPUT birthyear 20 INPUT currentyear 25 yourage = currentyear birthyear 30 PRINT currentyear-birthyear 35 END
  • 32. EXAMPLE 3 Given: y = 18, u = 21, r = 11 Code in QBasic to compute: V = y + (u r)
  • 33. SOLUTION 5 CLS 10 REM 15 READ y, u, r 20 DATA 15, 210, 11 30 Let V = (y + (u-r)) 35 PRINT The answer is: , V 40 END
  • 34. TAKE HOME Check your manual, solve and print the output of the questions in Lab Exercise 1, 2 and 3 (Pages 45 & 46)