Chapter 2

Beginning Problem-Solving Concepts for the Computer

1

Contents • • • • • Constant and variables Data types Functions Operators Expressions and equations McManus COP1006 2 .

3 .3 Types of Problems that can be solved on computers : • Computational – problems involving some kind of mathematical processing • Logical – Problems involving relational or logical processing • Repetitive – Problems involving repeating a set of mathematical and/or logical instructions.

Fundamental Concepts • The building blocks of equations and expressions – Constants – Variables – Operators – Functions – Expressions – equations 4 .

constants can be named – Cannot be changed once given initial value • Example – SalesTaxRate = 6 5 .Constants • A value – a specific alphabetical and/or numeric value – Does not change during the processing of all the instructions in a solution • Can be of any data type • In some programming languages.

Variables • May change during processing • The variable name should be consistent with what the value of the variable represents • The name references the memory area where the value is stored. PayRate 6 .Age. • May be of any data type • Examples :. • The computer uses the name as a reference to help it find that value in its memory . Address. LastName.

7 .

it uses the value found at the memory location to do the processing. • The computer uses the variable name to find the location. . • The value is the contents of the location.Difference between name of a variable and value of a variable 8 • There will be no character.length limitations for variable . • The name of a variable is the label the computer uses to find the correct memory location.

McManus COP1006 9 .

The naming convention is uppercase for the first character in each of the words in the name. • • • • • • Do not use spaces Start a variable name with a letter. but one that clearly represents the variable. Be consistent when using upper-and lower case characters. Exact variable name must be used in all places where the data item is used . Do not use a dash ( or any other symbol that is used as mathematical operator). 10 . Use the naming convention specified by the company where you work. with no spaces between words in the name.Rules for Naming Variables • • Name variable according to what it represents Create as short a name as possible.

– Is printed in the form of reports. • Information – The output of processing of input .Data type • Data – unorganized facts. 11 . – They go into the computer as input .

McManus COP1006 12 .

Data Types • Data can come with different type :(Most common types) – Numeric – Character – Logical • Computer must be told the data type of each variable or constant . • Most languages include other data types – Date – User-defined 13 .