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.

Slides:



Advertisements
Similar presentations
P5, M1, D1.
Advertisements

Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Chapter 1 Program Design
Computer Science 101 Introduction to Programming.
Computer Science 101 Introduction to Programming.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
30/10/ Iteration Loops Do While (condition is true) … Loop.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
The Software Development Process
Intermediate 2 Computing Unit 2 - Software Development.
Testing.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
The purpose of a CPU is to process data Custom written software is created for a user to meet exact purpose Off the shelf software is developed by a software.
7 - Programming 7J, K, L, M, N, O – Handling Data.
DATA TYPES.
Unit 2 Technology Systems
Component 1.6.
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
Component 1.6.
Chapter 2: Input, Processing, and Output
Programming Mehdi Bukhari.
IF statements.
Programming Problem steps must be able to be fully & unambiguously described Problem types; Can be clearly described Cannot be clearly described (e.g.
REPETITION STATEMENTS
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.
Standard Algorithms Higher Computing.
Programming Constructs Notes
Little work is accurate
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
File Handling Programming Guides.
Introduction to C++ Programming
Variables ICS2O.
An Introduction to Structured Program Design in COBOL
Coding Concepts (Sub- Programs)
Chapter 2 Variables.
Do While (condition is true) … Loop
Coding Concepts (Standards and Testing)
Java Programming Control Structures Part 1
Computer Science Testing.
Programming Errors Key Revision Points.
Data Types and Data Structures
Learning Intention I will learn about evaluating a program.
Java Review Most of these slides are based on
Software Development Process
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Spreadsheets, Modelling & Databases
Topics Designing a Program Input, Processing, and Output
Tonga Institute of Higher Education IT 141: Information Systems
Programming Logic and Design Fifth Edition, Comprehensive
Topics Designing a Program Input, Processing, and Output
Tonga Institute of Higher Education IT 141: Information Systems
Chapter 2: Input, Processing, and Output
Learning Intention I will learn about the different types of programming errors.
Chapter 2 Variables.
Variables in C Topics Naming Variables Declaring Variables
Arrays.
Review of Previous Lesson
Arrays & Loops.
WJEC GCSE Computer Science
Arrays & Loops.
Software Development Techniques
The IF Revisited A few more things Copyright © Curt Hill.
CHAPTER 6 Testing and Debugging.
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

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 the keyboard or can be the result of a calculation. A variable like name would hold data that is text. We sometimes call this a string. A variable like high score or exam mark would hold data that is a number. Different data types are therefore needed to store different types of data.

Data Types Integer This data type is used for storing a positive or negative whole number Example : 12, 563, 0, -83 This data type is used to store e.g. an age, the number of tickets you want to buy or the number of people at a sports event. Real This data type is used for storing a positive or negative number which contains a decimal or fractional part. Example : -13.67, 139.99, 1.64 This data type could be used to store a person’s height or time in a race.

Data Types String (Text) This data type is used for storing a data item of text. Example : “Yes”, “G62 7HS”, “Glasgow” This data type would be used to store e.g. a person’ s name, address or postcode. Boolean This data type is a two state variable and it can only store True or False. Example : True or False A Boolean variable could be used to say whether an item of data has been found in a list.

Data Structures An array is an example of a data structure. It is used to store a list of items that are of the same data type. For example a list of names, a list of teams or a list of employees. Now read pages 10 and 11 in your book and answer Question 3 on page 34 and 35.

Errors in Programs Most programs contain errors while they are in development. The programmer must ensure the code is tested as much as time allows. Testing should be competed in logical planned manner. Test data should be thought out and expected results should be compared against actual results. There are 3 types of errors in programs. These are called syntax, execution and logic errors.

Syntax Errors INPUT name$ PRINT “Hello; name$ END Syntax errors occur when the programming language rules have not been followed. Often this is caused by a typing error. For example a misspelt keyword or missing bracket or missing keyword. These errors are highlighted when the program is translated by the interpreter or compiler. True Basic Example : Syntax Error PRNT “Please enter your name” INPUT name$ PRINT “Hello; name$ END

Execution Errors PRINT “Please enter a number“ INPUT number If the program compiles and there are no syntax errors the program can still produce errors when it is run. Examples of execution errors are dividing by 0, indexing an array by a index outside of the array size. True Basic Example : Execution Error PRINT “Please enter a number“ INPUT number LET fraction = number / 0 PRINT “Your number divided by 10 is”;fraction END

Logic Errors A program can have no syntax errors and no execution errors. It can run to completion without crashing but it does not produce the expected result. This is known as a logic error. It may be that the code multiplies 2 numbers instead of adding them. It may be that in a calculation BODMAS has not been applied to the formula and it produces the wrong answer. True Basic Example : Logic Error PRINT “Please enter the length of the rectangle” INPUT length PRINT “Please enter the breadth of the rectangle” INPUT breadth LET area = length + breadth PRINT “The area is “; area END

Now read pages 22 and 23 in your book and answer Question 1 on page 38.

Readable Code It is good programming practice to make your code readable. This makes it very easy for another programmer to maintain the code. Programs are made readable by using a variety of techniques. Internal commentary – comments the computer ignores but helps us to understand what the code does. Meaningful variable names – giving a variable a name that is appropriate to what data is stored in that variable. Indentation and blank lines – help to give a program a structure so that it is easier to read. The code on the next slide demonstrates these 3 techniques:

Readable Code ! For loops ! This program asks the user for their name and a sentence ! It then asks for the number of times they want to display ! the sentence and it then displays the sentence that number of times. PRINT "Please enter your name" INPUT name$ PRINT "please enter your sentence" INPUT sentence$ PRINT "Please enter the number of times you wish to print your sentence" INPUT number PRINT "Here are your sentences "; name$ FOR counter = 1 to number PRINT counter;sentence$ NEXT counter END Internal commentary – lets us know what the program does. Meaningful variable names – easy to see what is stored in each variable Indentation and white space – format the program so it is easier to read

Now read pages 23 in your book and answer Question 4 on page 39.

Testing Testing your program makes sure that it performs in the way that you expect it to. It is a very important part of the development of software. It should be planned in a logical manner. This means that test data should cover normal, extreme (boundary) and exceptional cases.   When showing that you have tested a program you should indicate what conditions you tested, what results you expected and the actual results that were achieved when you ran the program with those conditions. This is usually displayed in a test table.

Testing Normal This type of test ensures that the program does what it should do when used with normal or expected input.   Extreme (sometimes referred to as limit or boundary) This type of test ensures the program does what is expected with extreme input. Exceptional This type of test ensures that the program can handle data that is exceptional. 

Testing ! This program asks the user for a mark Example: This program asks the user for a mark given for exam. The mark must be between 0 and 100. ! This program asks the user for a mark ! and validates that mark (0 and 100) DO PRINT "Please enter the mark“ INPUT mark IF mark <0 or mark >100 THEN PRINT “You have entered an invalid mark.” PRINT “Please try again“ END IF LOOP UNTIL mark>=0 and mark<=100 END Normal Test Data 9, 23, 45, 83 Extreme Test Data 0, 100 Exceptional Test Data -5, 128, a

Testing Test Data Type Expected Output Actual Output 9 Normal Test tables are usually written to indicate what data has been tested. Test table should be laid out in the following way. Test Data Type Expected Output Actual Output 9 Normal Accepted and stored 45 Extreme 100 -5 Exceptional Error Message a 128 What do you expect your program to do when it is run with this data. What actually happens when your program is run with this data. The data that you use when you run the program. The type of test data : should be Normal, Extreme or Exceptional.

Testing You would hope that the Expected Output column and the Actual Output column match.

Now read pages 24 and 25 in your book and answer Question 2 and 3 on page 38.

Want to know why code has to be both readable and well tested? Imagine the astronauts whose lives depended on her code being properly tested... Imagine the NASA software developers that came after her... ... trying to read thru 16 books of hand written code?