1 / 62

CLO 1, CLO 2 1.Explain various programming problem using design tools (C2)

2.0 INTRODUCTORY CONCEPT. CLO 1, CLO 2 1.Explain various programming problem using design tools (C2) 2. Apply knowledge of basic concepts of fundamental programming to solving a given problem(C3). 2.0 INTRODUCTORY CONCEPT. At the end of this chapter, student will be able to :

ady
Download Presentation

CLO 1, CLO 2 1.Explain various programming problem using design tools (C2)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2.0 INTRODUCTORY CONCEPT CLO 1, CLO 2 1.Explain various programming problem using design tools (C2) 2. Apply knowledge of basic concepts of fundamental programming to solving a given problem(C3)

  2. 2.0 INTRODUCTORY CONCEPT At the end of this chapter, student will be able to : • Define a variable and a constant • Identify the rules for naming variables and constant, • Declare constants and variables • Build constant and variables • Explain keywords and operators in programming • Use keywords and operators

  3. 2.0 INTRODUCTORY CONCEPT At the end of this chapter, student will be able to : 7. Convert formula into C expression

  4. 2.1 Constant And Variables(Identifier) 2.1.1 Variable And Constant Variable • Refer to the memory location where the data is stored • This value keeps changing during the program execution

  5. Figure 2.1(i) : Representation of Variable in Memory

  6. 2.1.1 Constant • a location in the memory that stores data that never changes during the execution of the program • constant can either be: • A numbers, like 15 or 10.5 • A single character, like 'x' or '#‘ • A group of characters (string), like “Beautiful Malaysia”

  7. 2.1.2 Rules For Naming Constants And Variables • Can be a combination of alphabets and numbers but must start with an alphabet • Comprise maximum of 40 characters • No commas or blank space is allowed • No special characters can be used except underscore (_)

  8. 2.1.3 Declare Constants And Variables • Constant and variable used in a program must be declared in the beginning • To specify the variable and constant data type to the compiler

  9. Declare Constant const data_type name=value ; e. g : const float pie=3.14 ; const intDays_of_Week=7; const char Colour=“RED”;

  10. Declare Variable data_type name ; e. g : float mark_1 ; int Quantity; char StudentID;

  11. 2.1.4 Scope of Constants And Variables DIY

  12. 2.0 INTRODUCTORY CONCEPT 2.1 Understand Constant And Variables(Identifier) 2.1.5 Build Constants and variables in Programmes Total Pie Payment

  13. 2.1.6 Identify and Explain Keywords in C Programmes Are reserved words for which the meaning is already defined to the compiler. an identifier cannot have the same spelling and case as a C keyword

  14. 2.1.7 Use Keywords In Programmes

  15. 2.1.7 Use Keywords In Programmes

  16. 2.1.7 Use Keywords In Programmes

  17. 2.0 INTRODUCTORY CONCEPT 2.2 Understand Data Types Data Types Data types are used to store various types of data that is processed by program. Data type attaches with variable to determine the number of bytes to be allocate to variable and valid operations which can be performed on that variable

  18. 2.2.1 Basic Data Types in C The C language provides a lot of basic types. Most of them are formed from one of the four basic arithmetic type identifiers in C (char, int, float and double), and optional specifiers (signed, unsigned, short, long). All available basic arithmetic types are listed below:

  19. Char signed long Short signed long int Short int long long Signed short long long int Signed short int signed long long Int signed long longint Signed int float Long double long int

  20. 2.2.2 Basic Data Types Numeric

  21. Numeric Keyword            Variable Type                Range char              Character (or string)        -128 to 127 int                integer                      -32,768 to 32,767 short              Short integer               -32,768 to 32,767 short intShort integer               -32,768 to 32,767 long               Long integer                 2,147,483,648 to 2,147,483,647 unsigned char     Unsigned character          0 to 255 unsigned intUnsigned integer             0 to 65,535 unsigned short    Unsigned short integer       0 to 65,535 unsigned long      Unsigned long integer        0 to 4,294,967,295 float              Single-precision             +/-3.4E10^38 to +/-3.4E10^38                   floating-point                   (accurate to 7 digits)      double             Double-precision             +/-1.7E10^308 to +/1.7E10^308                    floating-point                   (accurate to 15 digits)

  22. Characters C stores character type internally as an integer. Each character has 8 bits so we can have 256 different characters values (0- 255).Character set is used to map between an integer value and a character. The most common character set is ASCII. The char type store only one symbol of data (letter, digit, space, tab and so on).

  23. String The string type is able to keep virtually data of any length. Also string type is based on arrays and uses reference type working with memory.

  24. 2.2.3 Explain The Basic Data Types in C a. int int is used to define integer numbers. { int Count; Count = 5; }

  25. b. Char chardefinescharacters. { char Letter; Letter = 'x'; }

  26. c. float float is used to define floating point numbers. { float Miles; Miles = 5.6; }

  27. d. Double double is used to define BIG floating point numbers. It reserves twice the storage for the number. On PCs this is likely to be 8 bytes. { double Atoms; Atoms = 2500000; }

  28. 2.2.4 Use data types in C programmes

  29. 2.2.4 Use data types in C programmes

  30. 2.2.4 Use data types in C programmes

  31. 2.2.4 Use data types in C programmes

  32. 2.3 Understand Operators And Expression Operator • Operators are symbols which take one or more operands or expressions and perform arithmetic or logical computations.

  33. 2.3.1 Types Of Operator Types of operators available in C are as follows: Arithmetic Mathematical operators are used for performing simple mathematical calculations such as addition, subtraction, multiplication and division.

  34. Relational Relational operators are used to compare two operands.

  35. Logical • Logical operators are used to combine two simple statements into a compound statement. • Using logical operators, you can simulate Boolean algebra in C.

  36. Boolean Boolean operators define the relationships between words or groups of words. True=1 False=0

  37. 2.3.2 Operators used in programming 3 types : a. Mathematic operators b. Relational operators c. Logical operators

  38. 2.3.3 a.Arithmetic

  39. Operator precedence : i)bracket () ii) *,/,% (left to right) iii)+,- (left to right)

  40. Example 1

  41. Example 2

  42. b.Relational

  43. c. Logical

  44. The AND (&&) operator will evaluate to true only if all the conditions in the expression returns a true value. Example You will pass the exam only when you get more than 50 in subject 1, subject 2 and subject3.

  45. The OR (||) operator will evaluate to true even if one of the conditions is true. Example To get a medal, you should either be 1st or 2nd in the race.

  46. The NOT (!) operator will evaluate to true if the condition fails and vice versa. Example If your sex is not M, you are girl

  47. 2.3.4 Use Operators in Expression Statements

More Related