Computer Science 60-106 Final: Review Guide

11 Pages
Unlock Document

University of Windsor
Computer Science
Ritu Chaturvedi

60-106 FINAL EXAM REVIEW Lesson 1 (Basics)  How to compile and run 1. Go to the 60-106-F2013 file: cd 60-106-F2013 2. Make a file: pico (file name).c 3. Type: #include int main () { printf("Welcome to 60-106\n"); } 4. Ctrl + O to save 5. Hit Enter 6. Ctrl + X to exit 7. cc (file name).c 8. ./a.out to run the program 9. List the files in your folder by inputting ls No Editor Compiler Syntax Execute Logical/run- (pico) (cc) errors? (./a.out) time errors? No Yes Yes Finished! Lesson 2 (Basic Functions)  variables and constants are names for memory cells/storage locations to hold data values  constant cannot be changed while a variable may change when processing a problem  format for declaring a variable in C: datatype variablename[,variablenames];  format for declaring constants: const datatype variablename=value[,variablenames=values];  it’s better to use variable names close to its meaning (with less than 15 characters)  input data is what you type in to the algorithm/program; and output is the result  datatype must be assigned to each constant or variable at declaration  different kinds of datatypes: 1. Integer (int)  can store whole numbers (ex. -1, 194) 2. Real (float or double)  numeric with whole number and decimal places (ex. 129.39, 39000) 3. Character (char)  letters, numbers, and special symbols as single characters (ex. ‘E’, ‘0’, ‘+’) - SINGLE QUOTES 4. String  all letters, numbers, and special symbols as a group of characters (ex. “Charles”, “B+”) - DOUBLE QUOTES 5. Boolean/logical (implemented as int)  0 as false and 1 (or value not equal to 0) as true (ex. int flag=1; //declares flag as true)  Rules for datatypes: 1. Datatypes are usually not mixed. 2. value of a constant or variable will be defined as 1 or 4 datatypes: numerical (integer or real), character, string, or Boolean 3. using any data outside the datatype will result in error 4. only valid operations are allowed on a datatype (ex. numbers assigned as a string datatype can’t be used)  program (instruction) can be one of the following: 1. read (scanf) or print (printf)  reading what the user inputted and printing the results 2. assignment instruction (ex. sum = num1 + num2) 3. function call 4. decision instruction 5. repetitive instruction  format for scanf scanf(“format specifiers”, &variable1, &variable2, … , &variable);  format for printf printf(“format specifiers”, variable1, variable2, … , variable);  format specifiers: o int and long int  %d and %ld o float and double  %f o char  %c o string  %s Lesson 3 (Operators)  assignment instruction  to read a value in the memory cell (variable on the right side) and to assign a value to the memory cell (left side) o general format: variable = expression; o ex. write assignment instruction to copy the sum of assn1 and assn2 to assn3 Answer: assn3 = assn1 + assn2  expression  “a variable, a constant, or a literal of a combination of these connected by appropriate operators” o 3 types of expressions: arithmetic, relational and logical  operators  tell the computer how to process data o types of operators:  mathematical: addition(+), subtraction(-), multiplication(*), division(/), integer division(/), modulo division(%)  arithmetic operators o divisions can be using with real numbers (ex. 5.0/2.0=2.5), integers (5/2=2) and mixed numbers (ex. 5.0/2=2.5) o the % operator returns the remainder of the integer division (whereas the / operator returns the quotient)  relational operators o used to program decisions that need two data operands of the same type o < (less than), > (greater than), <= (less than or equal to), >= (greater than or equal to), == (equal to) and != (not equal to)  logical operators o used to connect relational operators (aka decision making expressions) o ex. if-else statements o not (!), (&&) - AND or (||) – OR  other C operators o ++ (adding 1 to a variable) o – (subtracting 1 from the variable) o sizeof (the number of bytes the variable type requires) o cast (accepts the expression as its operand then converts the operand type to the typed specified by the cast operator) o assign operations (short forms of assignment instructions)  general format: variable operator= value; Lesson 4 & 5 (Loops)  3 types of control structures o sequential  assignment, scanf, printf o selection  if-else statements o repetition  while, do-while, for loops  repetition structures allow a sequence of instructions to be executed in a loop continuously until the condition cannot be satisfied  different kinds of loops: o counter-controlled loop  repeats a specific number of times (ex. loop that prints 4 stars in one line so we know the repetition is done 4 times) o sentinel-controlled  repeats until a specified input called a sentinel value is entered to terminate it; number of times the loop repeats for is unknown  sentinel value  input value entered for processing  ex. terminate the loop when input is negative o general conditional  repeats until a general condition is met  used when counter-controlled or sentinel loops aren’t applicable  used when the number of loop repetitions cannot be determined prior to the execution  ex. loop repeats until the user input is invalid  3 types of loop structures: while, for and do-while  while loop  used to apply both counter-controlled and sentinel-controlled loops o important parts of the structure: initialization of variables, testing control variables (termination condition), updating the control variable (to move to the next item) While loop as counter-controlled loop  used when it is known how many repetitions are needed before the execution  constructing the loop: o step 1: initialize the loop control variable by assigning it a value (ex. count=0) o step 2: repeat instruction while testing condition is true (ex. count<5) o step 3: update the loop control variable (ex. count++;) While loop as sentinel-controlled loop  used when it is not known how many repetitions are needed before the execution  constructing the loop: o step 1: choose a sentinel value from domain (ex. sentinel=-1) o step 2: initialize the loop control variable by assigning it a value (ex. scanf (“%d”, &n); where n is the first of set of input values) o step 3: repeat instruction while input value is not equal to sentinel value (ex. while (sentinel !=-1)) o step 4: update the loop control variable by reading the next input value For Loop Syntax: for (initialization expression; loop repetition condition; update expression) statement; Do-While Loop Syntax (run the loop while the testing condition is true): statement; while (condition); For Loop While Loop for (initialization expression; loop repetition statement; condition; update expression) while (condition); statement; for (h = 1; h!=3; h++) { h=1; } while (h!=3) {
More Less

Related notes for 60-106

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.