210 likes | 364 Views
Identifiers. Programmer defined names or words. Naming Rules for identifiers: alphanumerical underscore no leading digit(s) no space. Identifiers - Examples. Correct: RowCount Return2Copies columncount ColumnCount columnCount Incorrect Names: 2Copies row Count 3rdRow.
E N D
Identifiers • Programmer defined names or words. • Naming Rules for identifiers: • alphanumerical • underscore • no leading digit(s) • no space e-business and Information Systems
Identifiers - Examples • Correct: • RowCount • Return2Copies • columncount • ColumnCount • columnCount • Incorrect Names: • 2Copies • row Count • 3rdRow e-business and Information Systems
Basic Concept of Programming • Basic Computer Operations: • Data Inputs • Data Manipulations • Data Outputs e-business and Information Systems
Data Manipulation • Manipulating Data with: • Unknown values • user inputs • depend on the results of other manipulations • Known values – predetermined • Constant values – values will not change thru the execution e-business and Information Systems
RAM Identifiers bFlag bDone iCount Data Storage • Run time storage for unknown value: • Variable – Identifier - Data Storage Reference • names (identifier) • data types (size of the data storage) • scopes (duration or lifetime) e-business and Information Systems
Variable Name • Naming Rules for Variables: • alphanumerical • no leading digit • no space • underscore • Naming Conventions: • lowercase for first character • Uppercase for the character of a word e-business and Information Systems
Variable Name - Examples • Correct Names: • RowCount • Return2Copies • columncount • Preferred: • rowCount • return2Copies • columnCount • Incorrect Names: • 2Copies • row Count • 3rdRow e-business and Information Systems
Data Types • Primitive Data Types: • int • char • float e-business and Information Systems
Define a Variable • Syntax: • Data_Type Variable_name; • Data_Type Variable_name = Value; • Examples: • int iCount; • char iFirstCharacter; • char iC = ‘A’; • int iNumber = 0; • float fFlat = 17.5; e-business and Information Systems
Scope of a Variable • Scopes: • block scope • instance scope – will talk more about this later • class scope – will talk more about this later e-business and Information Systems
Scope - block • Scope: • between the most inner block of {…} • starts right after the definition of the variable e-business and Information Systems
Block Scope - Example { int iTotal; int iSteps; { int iBegin = 0; int iEnd = 10; //data manipulations }//end of scopes of iBegin and iEnd //data manipulations }//end of scopes of iSteps and iTotal e-business and Information Systems
{ int iTotal; int iSteps; //data manipulations }//end of scopes of iSteps and iTotal { int iBegin = 0; int iEnd = 10; //data manipulations }//end of scopes of iBegin and iEnd Block Scope Example – cont. e-business and Information Systems
Scope - instance • Instance scope variables: • properties • non-static e-business and Information Systems
Scope - class • Class scope variables • unique for all instances of the same class • static variables e-business and Information Systems
More on Data Manipulations • Basic operations: • value assignment operator = • addition operator + • subtraction operator - • multiplication operator * • division operator / e-business and Information Systems
Simple statements int iBegin = 0; int iEnd = 10; int iSteps; int iTotal; iSteps = iEnd – iBegin; iTotal = 5 * iSteps; //note a complete statement ends with ; e-business and Information Systems
Basic Structures • Structured Programming in C/C++ • sequence • decision/selection/testing • iteration/repetition/looping e-business and Information Systems
Sequence //Do this instruction int iCount = 0; int iRow = 0; int iColumn = 0; e-business and Information Systems
False True Condition if(condition) { //Do Task 2 } else{ //Do Task 1 } Do Task 2 Do Task 1 Decision/Selection/Testing e-business and Information Systems
while (condition) { //Do Tasks } Do Tasks True Condition False Iteration/Repetition/Looping e-business and Information Systems