Current Assignments Project 3 has been posted, due next Tuesday. Write a contact manager. Homework 6 will be posted this afternoon and will be due Friday.

Slides:



Advertisements
Similar presentations
Brown Bag #2 Advanced C++. Topics  Templates  Standard Template Library (STL)  Pointers and Smart Pointers  Exceptions  Lambda Expressions  Tips.
Advertisements

Data Structures (Second Part) Lecture 2 : Pointers Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
Introduction to Programming Lecture 39. Copy Constructor.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
This Time Pointers (declaration and operations) Passing Pointers to Functions Const Pointers Bubble Sort Using Pass-by-Reference Pointer Arithmetic Arrays.
Dale/Weems/Headington
C++ Data Type String A string is a sequence of characters enclosed in double quotes. Examples of strings: “Hello” “CIS 260” “Students” The empty string.
1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
#include using namespace std; void main() { int a[3]={10,11,23}; for(int i=0;i
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Pointers. Topics Pointers Pointer Arithmetic Pointers and Arrays.
Pointers. COMP104 Pointers / Slide 2 Pointers * A pointer is a variable used for storing the address of a memory cell. * We can use the pointer to reference.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays –Structures of related data items –Static entity (same size throughout program) A few types –Pointer-based.
Pointers: Part I. Why pointers? - low-level, but efficient manipulation of memory - dynamic objects  Objects whose memory is allocated during program.
Multiple-Subscripted Array
Review on pointers and dynamic objects. Memory Management  Static Memory Allocation  Memory is allocated at compiling time  Dynamic Memory  Memory.
Computer Science 1620 Arrays. Problem: Given a list of 5 student grades, adjust the grades so that the average is 70%. Program design: 1. read in the.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Templates Overload function: define more than one function With same function name Different parameter type Different type Different number of parameter.
CSE 332: C++ functions Review: What = and & Mean In C++ the = symbol means either initialization or assignment –If it’s used with a type declaration, it.
Recursion Chapter Nature of Recursion t Problems that lend themselves to a recursive solution have the following characteristics: –One or more.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12: Recursion Problem Solving, Abstraction, and Design using C++
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
February 11, 2005 More Pointers Dynamic Memory Allocation.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
C++ Tutorial Hany Samuel and Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2006 by Douglas.
Current Assignments Homework 3 is due tonight. Iteration and basic functions. Exam 1 on Monday.
ITEC 320 C++ Examples.
Dynamic memory allocation and Pointers Lecture 4.
Current Assignments Start Reading Chapter 6 Project 3 – Due Thursday, July 24 Contact List Program Homework 6 – Due Sunday, July 20 First part easy true/false.
Exam Format  90 Total Points  60 Points Writing Programs  25 Points Tracing Code/Algorithms and determining results  5 Points Short Answer  Similar.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
Tracing through E01, question 9 – step 1 // p02.cc P. Conrad, for CISC181 07S // Exam question for E01 #include using namespace std; void mysteryFunction(int.
Chapter 7 Pointers: Java does not have pointers. Used for dynamic memory allocation.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Lecture 6 C++ Programming Arne Kutzner Hanyang University / Seoul Korea.
Data Types Declarations Expressions Data storage C++ Basics.
C++ / G4MICE Course Session 2 Basic C++ types. Control and Looping Functions in C Function/method signatures and scope.
C++ Programming Lecture 13 Functions – Part V The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
System Programming Practical Session 7 C++ Memory Handling.
1 What is a Named Constant? A named constant is a location in memory that we can refer to by an identifier, and in which a data value that cannot be changed.
Strings Jarret Raim C Strings Same as arrays of characters. Use pointers. Require static declarations (compile time). No bounds checking. No easy.
1 Object-Oriented Programming Using C++ A tutorial for pointers.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Pointers A pointer type variable holds the address of a data object or a function. A pointer can refer to an object of any one data type; it cannot refer.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
Lecture 17: 4/4/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
1 Lecture 4: Part1 Arrays Introduction Arrays  Structures of related data items  Static entity (same size throughout program)
Lecture 9 – Array (Part 2) FTMK, UTeM – Sem /2014.
Array. Array is a group of data of the same type. Array elements have a common name –The array as a whole is referenced through the common name Individual.
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Pointers A variable that holds an address value is called a pointer variable, or simply a pointer.  What is the data type of pointer variables? It’s not.
Pointers What is the data type of pointer variables?
Command Line Arguments
C++ in 90 minutes.
CS 2308 Exam I Review.
Pointers, Dynamic Data, and Reference Types
Screen output // Definition and use of variables
Pointers & Functions.
Cs212: DataStructures Computer Science Department Lab 3 : Recursion.
Dynamic Memory A whole heap of fun….
Dynamic Memory A whole heap of fun….
C++ Pointers and Strings
Arrays Arrays A few types Structures of related data items
Pointers and dynamic objects
Pointers & Functions.
The Stack.
C++ Pointers and Strings
Presentation transcript:

Current Assignments Project 3 has been posted, due next Tuesday. Write a contact manager. Homework 6 will be posted this afternoon and will be due Friday. More pointers and arrays.

Exam 2 Functions (templates overloading etc.) Recursion Static Arrays Pointers (including function pointers) No Sorting

Sample Problem Find the syntax errors: Int foo( int int ); Int main() { foo( 3, 4 ) return 0; } Int foo( x, y ) { return x + y; }

Sample Problem Find the syntax errors: float foo( int 4, int 5 ); int main() { foo( 3.0, 4 ); return 0; } int foo( float x, float y ) { return x + y; }

Sample Problem Find the syntax errors: float foo( int x = 5.0, int y = 5.0 ); int main() { foo( 3.0 ); return 0; } float foo( float x, float y ) { return x + y; }

Sample Problem Find the syntax errors: float foo( &int x = 5, &int y = 5 ); int main() { foo( 3 ); return 0; } float foo( &int x, &int y ) { return x + y; }

Sample Problem Find the syntax errors: float foo( int& x = 5, int& y = 5 ); int main() { foo( 3 ); return 0; } float foo( int& x, int& y ) { return x + y; }

Sample Problem Find the syntax errors: template T foo( T x, T y ) int main() { foo( 3.0 ); return 0; } T foo( T x, T y ) { return x + y; }

Sample Problem Find the syntax errors: #include using namespace std; int main() { int y = 5; int* x = NULL; x = y&; cout << (*x) << “==“ << y << endl; return 0; }

Sample Problem Find the syntax errors: #include using namespace std; int main() { int y = 5; int x = NULL; x = &y; cout << x << “==“ << &y << endl; return 0; }

Sample Problem Find the syntax errors: #include using namespace std; int main() { int[10] y = {5}; cout << y[-1] << “==“ << y[10] << endl; return 0; }

Sample Problem Find the syntax errors: #include using namespace std; int main() { int array[11.5]; return 0; }

Sample Problem Find the syntax errors: #include using namespace std; int main() { constant int x; int array[x]; return 0; }

Sample Problem Find the syntax errors: #include using namespace std; int main() { int z; int* x; int y[10][2]; x = y[1][2]; // can't assign int to int* x = &(y[5][0]); // x = &(y[5]) only works on some compilers z = y[4]; // can’t assign an int* to an int return 0; }

Sample Problem Find the logic error: #include using namespace std; int main() { int array[100]; for( int i = 1; i <= 100; i++ ) { array[i] = 2*i; }

Sample Problem Find the logic error: #include using namespace std; void foo( int* x ); int main() { int* x = NULL; foo(x); cout << (*x) << endl; } void foo( int* x ) { int y = 6; x = &y; // Returning the address of a local variable }

Sample Problem Find the logic error: #include using namespace std; int* foo(); int main() { cout << foo() << endl; } int* foo() { int a[10] = {0}; return a; // a is the address of array a, its really a pointer }

Sample Problem What does this code snippet print: int array[4][3]; for( int i = 0; i < 3; i++ ) { for( int j = 0; j < 4; j++ ) { array[j][i] = i*j; } cout << array[i][i]; } 014

Sample Problem What does this code snippet print: char array[] = “this is\0a test”; for( int i = 0; array[i] != ‘\0’; i++ ) { cout << array[i]; } This is

Sample Problem What does this code snippet print: char* foo( char* a1 ); char* bar( char* a1 ); int main() { char test[] = "test1"; cout << test << “ “ << foo( test ) << “ “ << bar( test ) << endl; return 0; } char* foo( char* a1 ) { a1[4] = '2';return a1; } char* bar( char* a1 ) { a1[4] = '3';return a1; } test1 test2 test3\n

Sample Problem What does this code snippet print: void foo( int x ); void bar( int& x); int main() { int y = 5; cout << y << endl; foo(y); cout << y << endl; bar(y); cout << y << endl; return 0; } void foo( int y ) { y = y+1; } void bar( int& y ) { y = y+1; }

Sample Problem What does this code snippet print: int foo( int x ); int main() { foo(-2); return 0; } int foo( int y ) { if ( y < 4 ) { cout << y << “ “; y = foo( y + 1); } cout << y << “ “; return y; }

Sample Problem What does this code snippet print: char* foo( char* y, const int size ); int main() { const int size = 15; char* test = “This is a test”; cout << foo( test, size ); return 0; } char* foo( char* y, const int size ) { char x[ size ]; for ( int i = 0; i < size; i++ ) { x[i] = y[size-i-2]; } x[size - 1] = ‘\0’; // Add a NULL character to the end return x; } tset a si sihT

Sample Problem What does this code print? #include using namespace std; float foo( float x = 4, float y = 3); float bar( int x, float (*y) (float x = 4, float y = 3) ); int main() { cout << bar( 4, foo ) << endl; return 0; } float foo( float x, float y) { return (x/y); } float bar( int x, float (*y) (float x = 4, float y = 3) ) { return y( x ); }

Sample Problem Write the definition for a function that given an array of 20 integers computes the median value. Write a complete program that given an array returns a pointer to a copy of that array. Write a recursive function to subtract one positive number from another. Write an iterative function definition that concatenates two strings. Write a recursive function definition to concatenate two strings.