Lecture22 - Engineering 101 Engineering 101 Lecture 22...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Engineering 101 Engineering 101 Lecture 22 Lecture 22 Generic Types and Vectors Generic Types and Vectors Prof. Michael Falk University of Michigan, College of Engineering Announcements Announcements Project 5 due Weds at 9pm Exam 2 is being graded. Will be returned Thursday/Friday. A new grade book will be posted shortly. I will also be shuffling seats again soon. If you are concerned about your grade please email me to make an appointment to meet sometime after your last lab this week and before Nov. 9 (Nov. 10 is the drop deadline). Announcements Announcements For Project 5 , make sure you have the most up-to- date versions of tester.o and blackbox.m Robot competition rules have been posted. Use headtohead.o and blackbox2.m to run contests. Contest: 25x25 field 0.5 density with 500 battery. If two robots collide only one gets to move, but both pay their battery cost for the move. Top robot in each section: 10 extra credit points Top robot in class $50 gift certificate to Borders If the top robot beats the GSI robot: 5 points for everyone in the class. Strings and C-strings Strings and C-strings It is important to note that the string class is a more modern version of a more basic type called the C-string . The literals we have used (e.g. hello) are really C-strings . Sometimes functions expect C-strings s.c_str( ) will return the C-string equivalent of the string s Strings and C-strings Strings and C-strings One place this is required is when specifying file names for opening fstreams string filename; cout << Enter Filename:<< endl; getline(cin, filename); ifstream in(filename.c_str( ) ); Passing Strings to Functions and Passing Strings to Functions and Procedures Procedures Generally we pass by value if we dont want to change the variable and by reference if we do int function( int x, int y); void procedure ( int & x, int & y); pass-by-value a copy is made for use in the function pass-by-reference access is given to the original data Passing Strings to Functions and Passing Strings to Functions and Procedures Procedures With strings we sometimes want to avoid recopying the string. It takes memory and time. int function( int x, int y); void procedure ( int & x, int & y); pass-by-value a copy is made for use in the function pass-by-reference access is given to the original data Passing Strings to Functions and Passing Strings to Functions and Procedures Procedures To overcome this we can pass as a constant reference rather than by value int function(const string & x, const string &y); void procedure ( string & x, string & y); pass-by-reference full access is given to the original data constant pass-by-reference read-only access is given to the original data Generic Types Generic Types Sometimes we may want to write a function but make it useful for multiple data types....
View Full Document

This note was uploaded on 04/02/2008 for the course ENGR 101 taught by Professor Ringenberg during the Fall '07 term at University of Michigan.

Page1 / 54

Lecture22 - Engineering 101 Engineering 101 Lecture 22...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online