Presentation is loading. Please wait.

Presentation is loading. Please wait.

# include using namespace std; int Square ( int ); int Cube ( int ); int main () { cout<<“The square of 27 is “<< Square(27) << endl; cout<<“The cube of.

Similar presentations


Presentation on theme: "# include using namespace std; int Square ( int ); int Cube ( int ); int main () { cout<<“The square of 27 is “<< Square(27) << endl; cout<<“The cube of."— Presentation transcript:

1 # include using namespace std; int Square ( int ); int Cube ( int ); int main () { cout<<“The square of 27 is “<< Square(27) << endl; cout<<“The cube of 27 is “ << Cube(27) << endl; return 0; }

2 SYNTAX – defines exactly what combination of letters, numbers and symbols can be used SEMANTICS – a set of rules that determines the meaning of instructions METALANGUAGE – a language that is used to write the syntax rules for another language OLDEST METALANGUAGE – BNF (Backus-Naur Form) SYNTAX TEMPLATE – a generic example of the c++ construct

3 IDENTIFIERS Identifier – A name associated with a function or data object and used to refer to that function or data object Rules – a) must start with a letter or an underscore b) identifiers that begin with underscore have special meaning Invalid IdentifierExplanation 40HoursIdentifiers cannot begin with a digit Get DataBlanks are not allowed Box-22hyphen is a math symbol Cost_in_$($) special symbols are not allowed intreserved word

4 Valid IdentifierHow it is used MAX_HOURSMaximum normal work hours OVERTIMEOvertime pay rate factor payRateAn employee’s hourly pay rate hoursnumber of hours an employee worked wagesemployee’s weekly wages empNumAn employee’s identification number CalcPaya function for computing an employee’s wages

5 C++ IS CASE SENSATIVE EmpNum is not the same as empnum Emp Num is not the same as EmpNum empNum is not the same as EmpNum

6 DATA TYPES TWO CATEGORIES OF DATA TYPES 1)STANDARD OR BUILT IN – use often so C++ has them predefined intfloatchar 2)Programmer or user defined data types – see chapter 10.

7 HOW DATA IS STORED IN MEMORY 1)Memory is divided into CELLS 2)Each CELL has a unique address 3)This address is a binary number 4)We use identifiers to name cells 5)The compiler translates the identifier into the address in memory Cell 1101101101Cell 1101101111Cell 1101101000 EmpNumEmpPayEmpAddress

8 Char char – consists of one alphanumeric character – a letter, digit or special symbol char is enclosed is a singe quote ‘8’ ‘8’ ≠ 8 ‘8’ is an alphanumeric – cannot be used in mathematical equations 8 is a numeric – can be used in mathematical equations ‘ ‘ is a blank char it consists of a ‘ press the space bar ‘ ‘A’ < ‘B’ due to a predefined collating sequence but we cannot do math on chars

9 String String – a sequence of characters – word, name, sentence Strings are enclosed in double quotes. “I am happy” Strings must be typed on one line – don’t split. “I am Happy” will give you an error. “” is the empty string or null string – no space between double quotes

10 DATA OBJECTS CONSTANTS – a name of a memory location whose contents are not allowed to change VARIABLES – a name of a memory location whose contents can change A 1001 1002 const char EMPCODEint EmpNum

11 DECLARATION Declaration – a statement that associates an identifier with a data object, a function or a data type so that the programmer can refer to the item by name int EmpNum; int EmpPay; const char EMPCODE = ‘A’; int Square( int);

12 int EmpNumint EmpPaystring EmpAddress Variables – a location in memory, referenced by an identifier, that contains a data value that can be changed Declaring a variable – specify data type and name; int EmpNum; int EmpPay; string EmpAddress; OR int EmpNum, EmpPay; string EmpAddress;

13 ‘A’ const char EMPCODE Constants – a location in memory, referenced by an identifier, that contains a data value that CANNOT be changed Declaring a constant – specify constant, data type, name and data value const char EMPCODE = ‘A’;

14 LITERAL VS CONSTANT LITERAL – any constant value written in a program cout<<“I am a c++ programmer”; NAMED CONSTANT const char EMPCODE = LITERAL VALUE;


Download ppt "# include using namespace std; int Square ( int ); int Cube ( int ); int main () { cout<<“The square of 27 is “<< Square(27) << endl; cout<<“The cube of."

Similar presentations


Ads by Google