CS 215-401 Midterm Study Guide Fall 2014. General topics Definitions and rules Technical names of things Syntax of C++ constructs Meaning of C++ constructs.

Slides:



Advertisements
Similar presentations
Lectures 10 & 11.
Advertisements

Programming Languages and Paradigms The C Programming Language.
 2003 Prentice Hall, Inc. All rights reserved Fundamentals of Characters and Strings Character constant –Integer value represented as character.
Strings.
CMSC 2021 C++ I/O and Other Topics. CMSC 2022 Using C++ Stream I/O Default input stream is called cin Default output stream is called cout Use the extraction.
Engineering Problem Solving With C++ An Object Based Approach Chapter 9 Pointers and Creating Data Structures.
Chapter 10.
Wednesday, 12/11/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/11/02  QUESTIONS??  Today: CLOSING CEREMONIES!  HW #5 – Back Monday (12/16)
Chapter 5: Loops and Files.
C-Strings A C-string (also called a character string) is a sequence of contiguous characters in memory terminated by the NUL character '\0'. C-strings.
Arrays Hanly - Chapter 7 Friedman-Koffman - Chapter 9.
1 Chapter 8 Scope, Lifetime, and More on Functions Dale/Weems/Headington.
1 Lecture 20:Arrays and Strings Introduction to Computer Science Spring 2006.
Chapter 9: Arrays and Strings
Chapter 9: Arrays and Strings
Chapter 9: Arrays and Strings
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
Chapter 8 Arrays and Strings
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
CS 117 Spring 2002 Review for Exam 3 arrays strings files classes.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 10. Pointers & Dynamic Data Structures.
1 Chapter 9 Scope, Lifetime, and More on Functions.
In Addition... To the string class from the standard library accessed by #include C++ also has another library of string functions for C strings that can.
CSIS 123A Lecture 6 Strings & Dynamic Memory. Introduction To The string Class Must include –Part of the std library You can declare an instance like.
1 Data Structures A Data Structure is an arrangement of data in memory. A Data Structure is an arrangement of data in memory.  The purpose is to map real.
Chapter 8 Arrays and Strings
1 Chapter 8 Scope, Lifetime, and More on Functions Dale/Weems/Headington.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
Functions Why we use functions C library functions Creating our own functions.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
Pointers OVERVIEW.
Character Arrays Based on the original work by Dr. Roger deBry Version 1.0.
File Input and Output in C++. Keyboard and Screen I/O #include cin (of type istream) cout (of type ostream) Keyboard Screen executing program input data.
Introduction to C++ Version 1.1. Topics C++ Structure Primitive Data Types I/O Casting Strings Control Flow.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 3 Formatting Output.
Define our own data types We can define a new data type by defining a new class: class Student {...}; Class is a structured data type. Can we define our.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Copyright © 2002, Department of Systems and Computer Engineering, Carleton University CONTROL STRUCTURES Simple If: if (boolean exp) { statements.
12/15/2015Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter Chapter 6 One-Dimensional Arrays.
1 Character Strings (Cstrings) Reference: CS215 textbook pages
12/23/2015Engineering Problem Solving with C++, second edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 9 An Introduction.
Loops and Files. 5.1 The Increment and Decrement Operators.
Chapter 11 Standard C++ Strings and File I/O Dept of Computer Engineering Khon Kaen University.
Review Pointer Pointer Variables Dynamic Memory Allocation Functions.
Data Types Storage Size Domain of all possible values Operations 1.
1 Chapter 9 Scope, Lifetime, and More on Functions.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 9. Streams & Files.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
CSE 332: C++ pointers, arrays, and references Overview of Pointers and References Often need to refer to another object –Without making a copy of the object.
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
1 Recall that... char str [ 8 ]; str is the base address of the array. We say str is a pointer because its value is an address. It is a pointer constant.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 7 Pointers and C-Strings.
1 Chapter 7 Pointers and C-Strings. 2 Objectives  To describe what a pointer is (§7.1).  To learn how to declare a pointer and assign a value to it.
Topic 2 Input/Output.
Chapter 7 Pointers and C-Strings
CS 215 Final Review Ismail abumuhfouz Fall 2014.
CS Computer Science IA: Procedural Programming
Chapter 9 Scope, Lifetime, and More on Functions
Chapter 15 Pointers, Dynamic Data, and Reference Types
2.1 Parts of a C++ Program.
More About Data Types & Functions
Chapter 3: Input/Output
Chapter 3 Input output.
Engineering Problem Solving with C++, Etter
Chapter 2: Introduction to C++.
Scope of Identifier The Scope of an identifier (or named constant) means the region of program where it is legal to use that.
Presentation transcript:

CS Midterm Study Guide Fall 2014

General topics Definitions and rules Technical names of things Syntax of C++ constructs Meaning of C++ constructs (reading code) System classes, functions, and header files. Common errors. Algorithms.

Topics Variables and types (chapter 2) Conditionals and Booleans (chapter 3) Loops (chapter 4) Functions (chapter 5) Arrays and vectors (chapter 6) Pointers and dynamic allocation (chapter 7) Streams and les (chapter 8) Classes and object-oriented design (chapter 9).

Chapter 2 Variables, Types & Operations Types: –int, double, char, bool, string. –Literals of each type. –When to use each type. –Differences between integers and floating point. Variables: –Identifier, type, scope, address, value. –Declaration and definition. (declare and initialize them before using them) –Scope of the Variable (Local vs. global variables). –Arithmetic operations Operations: –+ - * / % …. –Functions sqrt pow exp … –Operator precedence. –Integer division - when does it happen?

Chapter 3 & 4 Conditions & Loops Conditionals: –If, if-else, nested if… –Boolean expressions: && || ! –Common errors: extra semicolon. –Errors: tests that are always false or always true. Loops: –For, while, and do-while loops. –Differences between types of loops. –Equivalence of for and while loops. –Scope of loop variables. –For loop bounds: how many iterations?

Chapter 5Functions Syntax for functions definition (declaration and implementation). Syntax for prototypes. Parameters and arguments (what's the difference?) Return values and types (including void). The return statement. Deciding what parameters and return type a function needs. Call-by-value: copies the argument. Call-by-reference: use the argument itself (why and how?) const references.

Chapter 6 (Arrays) Syntax for arrays: e.g. int mylist[12]; Accessing: mylist[i].. Valid indexes i range from 0 to length - 1. Looping over array: for (int i = 0; i < length; i++) Limitations: capacity must be known in advance. Partially-filled arrays –Companion variable for the (current) size. –Capacity (maximum size) is still fixed. –Inserting and removing: shift the following elements. Arrays as function arguments. –Always call-by-reference. –Need a companion variable for array size. –Actually a pointer! –Cannot return an array, only a pointer. Two-dimensional arrays: e.g. int twod[rows][columns];

Chapter 7 Pointers Declaring a pointer: int *p; Operators –Address-of (&): int *p = &n; –Dereference (*): int n = *p; Pointer assignment: int *q; q = p; –Now they point to the same thing: changing *p also changes *q. NULL, uninitialized pointers. The name of an array is a pointer to its first element. Pointer arithmetic: + 1 goes to next element in an array. Array-pointer duality: a[i] = *(a + i). Int *p = &n; what is p, *p, and &p (and their types)?

Chapter 7 (Dynamic memory) Allocated from the heap. Use the New operator: int *p = new int; –Free with delete p; Or allocate a whole array: int *p = new int[n]; –Free with delete[] p; Common errors –Memory leaks (didn't free something). –Dangling pointer (using already-deleted memory). –Bounds error (going past the allocated array). –Wrong deletion operator

Chapter 7: C strings Char array: char [] vs. Pointer to an array of characters: char * End is marked by a null terminator (the character '\0') String literals are C strings. Iterating: –for (int i = 0; str[i] != ‘\0'; i++) – for (const char *p = str; *p != ‘\0’ ; p++) Length: number of characters not counting the null terminator. –Array size must be 1 more. –The null terminator is at index length Algorithms for length, copying, etc. Converting string objects to C strings: strobj.cstr()

Chapter 7: C strings Algorithms for length, copying, etc. Converting string objects to C strings: strobj.cstr() C string functions: strlen,, strcpy, strcmp,.... –In the cstring header. Algorithm for searching for special character in C string –Checking for digits (isdigit), letters (isalpha) …. – #include string objects / C++ strings string myString= “CS215”; Converting C strings to string objects

Chapter 8 : Streams Header files: iostream, iomanip, ifstream Insertion operator << –I/O manipulators: setw, scientific, endl Extraction operator >> –Skips initial whitespace. –Reads one item. –The rest is buffered, including the newline. –Sets a fail state on error. getline function: getline(cin, stringvar) get method: cin.get(ch) reads a single character. The fail state: cannot use the stream until it is fixed. –Detecting: fail method. –Clearing errors: clear and ignore Reading in a loop istringstream / ostringstream

Chapter 8 File Stream Types: ifstream, ofstream. Opening and closing. –ifstream infile; infile.open("outfile.txt"); –infile.close(); Reading from or writing to a file stream. Exactly the same as using cin or cout Just use the name of the stream variable: infile >> age What happens if a file e is missing? –ifstream : A fail state (check with.fail() ) –ofstream : No problem, the file is created. Stream parameters: must be call-by-reference. Sequential versus random access. Text versus binary files

Now lets answer some Problems and Questions