Glossary Of Common Programming Terms Conditional Expression (or Relational Expresion) An expression that evaluates to either true or false, created using the relational operators. Commonly used in if statements, while loops, and for loops Examples: ( 34 < 23 ) ( n > 2) (avg = = 100) Conditional Statement A statement that uses a conditional expression with if or if-else to execute one or another statement. Examples: if (n = = 100) cout<<”congratulations”<<endl; else cout<<”not a perfect score”<<endl; Boolean operator ( !, &&, || ) Used to modify or combine conditional expressions, ! takes the reverse, && makes logical and, || makes logical or Example: (a < 100 || n = = 0 ) ( ! (p = = 0) ) same as ( p != 0) Relational Operators ( > , < , >=, <=, !=, ==) Used in relational expressions to compare two values and give a true or false result: DeMorgan’s Theorem (not required) A method of simplifying complex Boolean expressions, ( 6 < 9) (a > b) Example Change your oil every 3000 miles or 3 months if (miles >= 3000) || months >= 3 ) cout <<” change the oil “<<endl; Sometimes in loops we need to express the opposite sense of a complex Boolean. (loop repeats until it’s time to change the oil) For example: Set miles to 0 and months to 0 while ( ! (miles >= 3000 || months >= 3)) // this is the opposite of the if statement condition { Input mileage Add one to months } cout<<”it’s time to change the oil” DeMorgan says you can negate a complex boolean simply by changing >= to < and change || to && while ( miles < 3000 && months < 3 ) { Input mileage Add one to months } cout<<”it’s time to change the oil” // this is the same as the previous while loop Function A small program that accomplishes a specific task, and may return a value. Analogy: when doing your taxes, you use a little worksheet to do a side calculation, and bring the result back into your main tax sheet. Functions have precise interfaces (the head of the function) to make sure the programmer passes the correct number and type of arguments into the function during the function call. Definition: float pay( float hours, float rate) { return hours*rate; } // this line is the function head // this is the function body Placement of functions: Function definitions must be placed before the int main ( ) line in a program, OR Function prototypes must be placed before the int main ( ) line in a program and the definitions placed after main Function prototype The first line of a function definition, followed by a semicolon, when placed above main, allows the definition to be moved after the main function definition. Function call A statement inside a block of code (could be main or any other function ) that invokes or utilizes a function that is defined outside of main. cout<<”enter an average, -1 to quit”<<endl; cin >> avg; while ( avg >0) { cout<<”grade is “<<grade(avg)<<endl; cout<<”enter an average, -1 to quit”<<endl; cin >> avg; } // the function call is crawling at you Argument The variable or number or data that is given to a function call. (avg in the preceeding example) Parameter The variable in the function definition that receives the value of the argument. In the following definition, the parameter is x char grade(float x) { if (x >= 90) return ‘A’; etc, etc. } Syntax error A mistake in the grammar of a programming language Forgetting a ; misspelling a variable name, forgetting to declare a variable, etc. Loops A structure that lets you repeat a block of code, either a fixed number of times, or a user-controlled (based on input data) number of times. Using the following statements: while, for, or do-while Data type (int, float, char, double, string) The specifier in a variable declaration that determines how the data is represented. When a variable is declared, its data type must be specified. int x; // x is created only to hold whole numbers float g; // g is created only to hold numbers with decimal values Main The place in a program where execution starts. Only one main function may be active in a program at any time.