Programming – syllabus knowledge

Slides:



Advertisements
Similar presentations
Chapter 2: Modularization
Advertisements

Programming Types of Testing.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Program Design and Development
Introduction to a Programming Environment
Modules, Hierarchy Charts, and Documentation
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Chapter 1 Program Design
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
CIS Computer Programming Logic
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Computer Science 101 Introduction to Programming.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
CPS120: Introduction to Computer Science
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
I Power Higher Computing Software Development High Level Language Constructs.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CPS120: Introduction to Computer Science Variables and Constants.
The Hashemite University Computer Engineering Department
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Controlling Program Flow with Decision Structures.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
Chapter 1: Introduction to Computers and Programming
Bill Tucker Austin Community College COSC 1315
Chapter # 2 Part 2 Programs And data
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Chapter 10 Programming Fundamentals with JavaScript
Topics Designing a Program Input, Processing, and Output
Topics Introduction to Functions Defining and Calling a Void Function
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Chapter 2: Input, Processing, and Output
GC211Data Structure Lecture2 Sara Alhajjam.
Ch. 8 File Structures Sequential files. Text files. Indexed files.
Objectives Identify the built-in data types in C++
Revision Lecture
The Selection Structure
Variables, Expressions, and IO
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Chapter 1: Introduction to Computers and Programming
Computer Programming.
Designing and Debugging Batch and Interactive COBOL Programs
IDENTIFIERS CSC 111.
Chapter 10 Programming Fundamentals with JavaScript
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Variables ICS2O.
Data Types and Data Structures
Chapter # 2 Part 2 Programs And data
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Topics Introduction to Functions Defining and Calling a Function
Introduction to Data Structure
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Chapter 2: Input, Processing, and Output
Basic Concepts of Algorithm
Chapter 4: Writing and Designing a Complete Program
CHAPTER 6 Testing and Debugging.
Programming Logic and Design Eighth Edition
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

Programming – syllabus knowledge This covers the knowledge dot points. skillsprogramming still needs to occur for full understanding

Characteristics of simple data types: Integer: often referred to as whole numbers. In pseudocode ‘int’ Real (floating point number): can contain decimal or precise numbers. In pseudocode ‘real’ or sometimes ‘float’. Boolean: data type having only two values. Usually True or False. In pseudocode it is often used in Selection or loop type structures. Character: used to store alphanumeric text such as letters, numbers, spaces, symbols and punctuation. Careful with use of symbols and punctuation as they are often reserved characters within the language that have a meaning of their own.

Constants and variables

Complex Data structures

Characteristics of complex data STructures String: (pseudocode:str) Strings can be any length. They can contain a variety of characters or can even be empty. In pseudocode and many languages, length can be calculated using the function len() strings can be reversed: reverse() strings can be concatenated: “This is a string variable called”+ “string1” + “and it stores a string”. other functions include: upcase, downcase, capitalize Where appropriate, strings can be converted to integers s_to_i to peform mathematical calculations integers can also be converted to strings to perform string manipulation.

Data structures

Why use them

Complex data types continued Arrays: one dimensional arrays store values of the same format. They are useful for storing things like, examination scores, temperatures, rainfall, names etc. An array uses a counter and a for or while loop, along the lines of for names < 20 input array[names] end This allows you to input 21 names into the array called array (generally the index starts at 0, this is the accepted standard for many languages and pseudocode, but always check the context carefully) The array is a useful storage structure that is accessible by the index and it decreased the number of variables you would need to use (name1, name2 etc) As a variable, an array can do all the things a variable can do. If the array contains integers, then averages, totals etc can be calculated.

Arrays continued Declaring as variable: Variable int: MarksList[marks]; //array of integers If you know how many elements: Markslist[14]; integer //array of integers with 15 elements Initialising Reading Calculations

Declaring an array Format for declaring an array: data_type array_name[number of values to hold]; For numerical arrays – if all of the spaces are not initialized, the remaining ones are set to 0 int IntAr[10] = {2, 4, 6, 8}; The number of elements in the array is not always used or known when declaring an array int IntAr[] = {3, 5, 7};

Last one in array SET Max to array[0] FOR i = 1 to array length - 1 // -1 used to designate last item in array IF array[i] > Max THEN SET Max to array[i] ENDIF ENDFOR PRINT Max

Setting up array

Adding element

average

Len average – good if you don’t know number of elements in array

Array search

Binary search

exercises 1. Declare an array with elements 44, 23, 42, 33, 16, 54, 34, 18, and print them out as follows: [44, 23, 42, 33, 16, 54, 34, 18] 2. Declare an array with elements 44, 23, 42, 33, 16, 54, 34, 18, and print them out as follows: 44 23 42 33 16 54 34 18 3. Declare an array with elements 44, 23, 42, 33, 16, 54, 34, 18, and check if the length of the array is even or odd. 4. Declare an array with elements 44, 23, 42, 33, 16, 54, 34, 18, and check if the first element of the array is the same value as the last one. 5. Declare an array with elements 44, 23, 42, 33, 16, 54, 34, 18, and print them out in reverse order as follows: 18

variable Local – local in scope Global – global in scope Parameters – can be passed into module and used (value) and then another passed back as a result (reference) to be used elsewhere

Naming conventions for variables Begin with lowercase letter Contains no spaces Additional words begin with capital Unique names within code Consistent use of names Underscores are also good Careful with reserved characters ie !, @, #, %, &

Control structures Sequence: line by line: Keep statements in sequence and starting at the same point down the lines. Selection: If/Then/Else: Statements should be indented inside the selection structure but not the selection keywords Begion Input (name) X = name Print (x) Print (“Are you enjoying control structures?”) end Loop: Indent all the statements that fall inside the loop but again, not the keywords that trigger the loop if this then that else this end if Do while heather != Name writeln (“your name is not heather? T/F” ) input (name) End while DoUntil… Do For….

STatements Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is a "text-based" detail (algorithmic) design tool. The rules of Pseudocode are reasonably straightforward. All statements showing "dependency" are to be indented. These include while, do, for, if,

Modularisation Modularisation is the process of dividing a problem into separate tasks, each with a single purpose. Top-down design methodology allows the programmer to concentrate on the overall design of the algorithm without getting too involved with the details of the lower- level modules. Benefits of modular design The major benefits of using a modular design are: Ease of understanding - each module should perform just one function. Reusable code - modules used in one algorithm can also be used in other algorithms. Elimination of redundancy - using modules can help to avoid the repetition of writing out the same segment of code more than once. Efficiency of maintenance - each module should be self-contained and have little or no effect on other modules within the algorithm. http://www.damiantgordon.com/Videos/ProgrammingAndAlgorithms/Week6.html

The Mainline Since each module performs a single specific task, a mainline module should provide the master control that ties all of the modules together and coordinates their activity. This program mainline should show the main processing functions, and the order in which they are to be performed. It should show the flow of data and the major control structures. The mainline should be easy to read, be of manageable length and show sound logic structure. Generally, you should be able to read a mainline and see exactly what is being done in the program. Modular Algorithm Example Design a program that will prompt for the user for three numbers, accept those numbers, sort them into ascending order and output them to the screen. The program should continue to read numbers until ‘000’ is entered. Applying the top-down design methodology, the major tasks required to complete solve this problem are: Read 3 numbers While numbers NOT '000' Sort 3 numbers Print 3 numbers Read 3 numbers

Modularising fibonacci PROGRAM FibonacciNumbers: Fibonacci Calc Module def CalcFib(): a = int(input("Please input value: ")) //converting str to int FirstNum = 1 SecondNum = 1 print("Running total: ", SecondNum, " ( 0 + 1 )") while a != 1: # DO total = SecondNum + FirstNum print("Running total: ", total, " (",FirstNum,"+",SecondNum,")") FirstNum = SecondNum SecondNum = total //what is the scope of ‘total’ a = a - 1 ENDWHILE; # END. Main Program print("Calculating Fibonacci Numbers...") CalcFib()

Modularising prime checking Prime Checking Module def IsItPrime(): a = int(input("Please input value: ")) b = a - 1 IsPrime = True while b != 1: DO if a % b = = 0: THEN IsPrime = False ENDIF; b = b - 1 ENDWHILE; return IsPrime END IsItPrime. Main Program PROGRAM CheckPrime: if IsItPrime() == True: THEN print("Prime number") else: print("Not a prime number") END.

bubblesort You need to watch this>>>>https://www.youtube.com/watch?v=lyZQPjUT5B4 AND THIS https://www.youtube.com/watch?v=csjGw7O3z4U PROGRAM BetterBubblesort: Age = [44, 23, 42, 33, 18, 54, 34, 16] reducingindex = len(Age)-1 for outerindex in range(0,len(Age)): DO for index in range(0,reducingindex): if Age[index+1] < Age[index]: THEN TempValue = Age[index+1] Age[index+1] = Age[index] A ge[index] = TempValue ENDIF; ENDFOR; reducingindex = reducingindex - 1 print(Age) END.

Stubs A stub is a small program routine that substitutes for a longer program, possibly to be loaded later or that is located remotely. For example, a program that uses Remote Procedure Calls ( RPC ) is compiled with stubs that substitute for the program that provides a requested procedure. The stub accepts the request and then forwards it (through another program) to the remote procedure. When that procedure has completed its service, it returns the results or other status to the stub which passes it back to the program that made the request. A stub returns a value that is sufficient for testing. The stub does not need to perform the real calculation.

Bubble sort/Min/Max PROGRAM MinVal: Age = [44, 23, 42, 33, 18, 54, 34, 16] MinVal = Age[0] for index in range(0,len(Age)): DO if MinVal > Age[index]: THEN MinVal = Age[index] ENDIF; ENDFOR; print(MinVal) # END. PROGRAM MaxVal: MaxVal = Age[0] if MaxVal < Age[index]: MaxVal = Age[index] print(MaxVal)

Inter module communication There are two methods for inter-module communication 1. Variables: Global and local 2. Parameters: actual v formal, value v reference

structure

Module definition Formal parameters Pass by Reference Parameter Actual parameters Value Parameters

functions

Why use Functions Can be re-used over and over again To make code easier to read To allow for easier update and maintenance They are efficient It is usually preferable for efficiency of coding to use a function to return a value. If possible, a parameter should be altered within the code and passed back as a value (via a function) rather than an altered parameter.

Last word – it is in the UK/WA/HSC syllabus A function returns a value and a procedure just executes commands. The name function comes from math. It is used to calculate a value based on input. A procedure is a set of command which can be executed in order. In most programming languages, even functions can have a set of commands. Hence the difference is only in the returning a value part. But if you like to keep a function clean, (just look at functional languages), you need to make sure a function does not have a side effect. It comes down to fully fledged/qualified/experienced programmers preference! This depends on the context. In Pascal-like languages, functions and procedures are distinct entities, differing in whether they do or don't return a value. They behave differently wrt. the language syntax (eg. procedure calls form statements; you cannot use a procedure call inside an expression vs. function calls don't form statements, you must use them in other statements). Therefore, Pascal-bred programmers differentiate between those. In C-like languages, and many other contemporary languages, this distinction is gone; in statically typed languages, procedures are just functions with a funny return type. This is probably why they are used interchangeably. In functional languages, there is typically no such thing as a procedure - everything is a function.

Records – but it looks like a database?

Why use database oops….record? Using variables to store data is not always convenient E.g. PersonAge, PersonHeight, PersonMarried, PersonSurname It’s more convenient in this case to use a structure to hold multiple pieces of related data The structure is a container - think of a suitcase –carry its contents in one hand instead of holding many separate items. Data records are saved to a special file format, called the random file They are not plain text like serial files are, not human readable Since every record is exactly the same length, when records are written end-to- end it’s easy to calculate where any particular record begins.

An array (single dimension) of records BEGIN LoadArrayof Records // from HSBC – NSW syllabus Open ProductFile for input Set i to 1 Read ProdArrayofRecords (i) from ProductFile ‘note the use of the priming read in case the file is empty WHILE not EOF i = i + 1 END WHILE Close ProductFile Display “There are “ i “product records read in from the file” END LoadArrayofRecords To write updated data from the array of records to a sequential file, the following pseudocode is used: BEGIN WriteArrayof Records Open ProductFile for output Write ProductFile from ProdArrayofRecords (i) WHILE i <= NumRecords Display i “product records have been written to the file” END WriteArrayof Records

Or the pascal way – much easier Procedure call Why no counter increment?

Open file – close the file A file contains data which is saved in the hard disk. You can only view a file from the hard disk by using an operating system. A can contain text data which is used by word processors. Many text files are saved in the hard disk with the extensions: *.txt and *.doc. The file with extension of *.txt, means that it is created by the Microsoft Notepad. Whenever you use the Microsoft Notepad and save a text file, this saved file is created and written on to the hard disk. However, some programs have various formats on how to maintain the text - such as justification, font, font colour. So many files contain more data other than text data! The program itself uses various techniques to create a file in such a way that, when it is being read again it can read (using programming skills, etc..) if it is justified, its font style etc.. Remember to open the file and close the file. Exam markers usually look out for this bit Program Lesson8_Program1; Var UserFile : Text; FileName, TFile : String; Begin Writeln('Enter the file name (with its full path) of the text file:'); Readln(FileName); {A .txt file will be assigned to a text variable} Assign(UserFile, FileName + '.txt'); Reset(UserFile); {'Reset(x)' - means open the file x} //or Open(UserFile); Repeat Readln(UserFile,TFile); Writeln(TFile); Until Eof(UserFile); Close(UserFile); Readln; End.

Code Types – 2015 Paper

Compiler v interpreter Complier: converts the whole code into machine code before running it. Interpreter: converts the code one instructions at a time, running each instruction before translating the next

Errors Syntax: is an error in the grammar of the language you are using. Usually your IDE will offer an interpreter that will allow you to debug where syntax issues are as it goes through the code line by line. Line numbers with errors are provided (frequently the line number provided by the interpreter means there is a problem on the line after. Logic: Harder to pick up. Errors in logic will mean that you do not get the result you were expecting. Best picked up by Desk Checks and trace’s. Eg/ 20/0 will produce a logic error as you cannot divide 20 by 0 Run-time: Frequently a result of not enough memory to run the program. Check memory allocated to the program (in preferences). Check how much RAM your machine has. Also check for OS updates and IDE updates.

Trace tables

Documentation Examples of External documentation – to help users of system Data Dictionary’s, Variable lists, How to manuals, FAQ’s, Quick reference guides, IPO charts, User Guide, Where is the Requirements Specification? Where is the Impact Analysis Document? Where is the Design Document? Have you documented all the assumptions, limitations properly? Have you done review of all the documents? Did you get sign off on all the documents from all the stakeholders? Examples of Internal Documentation – to help developers/designers of the system Comments, indentation or anything adds to the ability to understand the code and its purpose.

Data validation Range checking : setting a range of acceptable values. Type checking : Declaring variable types: ie str, int, real, float, char, bool

SDC stages of the software development cycle (SDC) analyse detailed requirements design data and algorithms code data structures and instructions debug syntax and logic errors test to meet specifications document internally and externally implement and test with live data evaluate performance of the program

Some good references Damian Gordon - https://www.youtube.com/channel/UCEb0O4R9xhuZ8bNhpsu-5ZQ http://www.bbc.co.uk/education/subjects/z34k7ty - UK Computer Science subject (very similar to WA)