Unformatted text preview:

OutlineRemarks on Laboratory WorkReview and ReadingsA Survival Guide for PS1More on C++ I/OOutline Lab Work Review PS1 Survival C++ I/OCPSC 427a: Object-Oriented ProgrammingMichael J. FischerLecture 4September 13, 2011CPSC 427a 1/26Outline Lab Work Review PS1 Survival C++ I/ORemarks on Laboratory WorkReview and ReadingsA Survival Guide for PS1More on C++ I/OCPSC 427a 2/26Outline Lab Work Review PS1 Survival C++ I/ORemarks on Laboratory WorkCPSC 427a 3/26Outline Lab Work Review PS1 Survival C++ I/OToolset to use for course workThis course uses a collection of software tools running under Linux,including g++, valgrind, eclipse, make, a command shell suchas bash or tcsh, and Linux libraries and header files.These and other tools you will need are installed and maintainedon the Zoo machines.You are all entitled to Zoo accounts for use in this course, and youwill all be granted 24-hour access to the Zoo (in Arthur K. WatsonHall). I expect you to use the Zoo for all course work.CPSC 427a 4/26Outline Lab Work Review PS1 Survival C++ I/OWorking remotelyFor those of you who find it difficult to get to the Zoo and want towork remotely, I offer three suggestions, all of which have somedrawbacks.CPSC 427a 5/26Outline Lab Work Review PS1 Survival C++ I/O1. Replicate the Zoo environment on your own machineThis means installing Linux, either in place of your nativeoperating system, beside it in a dual-boot arrangement, or on topof it using virtualization software.Drawbacks: It takes time and expertise to install and configure allof the software you will need, and there is still the danger ofincompatibilities with the Zoo if you don’t end up with exactly thesame versions of everything.CPSC 427a 6/26Outline Lab Work Review PS1 Survival C++ I/O2. Remote login to the ZooLog into the Zoo remotely via ssh (which you must install on yourmachine), and use command-line tools such as emacs and make todevelop your code.Drawbacks: People used to program using command-line tools, butit is cumbersome compared with using a modern graphicalwindowing system and an IDE such as eclipse.CPSC 427a 7/26Outline Lab Work Review PS1 Survival C++ I/O3. Set up a virtual Zoo desktop on your machineTo use VNC (Virtual Network Computing), you must:1. install SSH and VNC clients on your machine;2. log onto a Zoo machine using ssh;3. start a VNC server on the Zoo;4. connect to the VNC server using your VNC client.See handout 3 (pdf) for detailed instructions.VNC gives you a virtual Zoo desktop that, in principle,will lookand feel just as if you were sitting at a Zoo console.Drawbacks: It won’t really feel the same. You will notice delayedresponse to your mouse actions. It’s a bit of a nuisance getting theconnection set up each time you want to work. Moving files backand forth between your local machine and the Zoo requires othertools such as rsync or scp.CPSC 427a 8/26Outline Lab Work Review PS1 Survival C++ I/OHomework submissionCompleted homework is to be submitted on the Zoo using thecommand /c/cs427/bin/submit.In order to submit, you must have a course account.Put the files you want to submit into a subdirectory, go to thatdirectory, and run submit.The first argument to submit is the problem set number.The remaining arguments are the files to be submitted.Example: submit 1 * submits everything in the current directoryfor problem set #1.CPSC 427a 9/26Outline Lab Work Review PS1 Survival C++ I/OReview and ReadingsCPSC 427a 10/26Outline Lab Work Review PS1 Survival C++ I/OA brief course review to dateLecture 1 describes the course goals of how to constructsoftware that is efficient, robust, scalable,maintainable, reusable, and understandable, as wellas giving correct outputs on correct inputs.Lecture 2 looks at how object-oriented design principles can beapplied even to C programs, pointing out alsoinherent limitations of C that motivated thedevelopment of C++.Lecture 3 gives a whirlwind tour of an object-oriented C++program for insertion sort, looking in particular athow the various pieces of code are split into interfaceor header files (.hpp) and implementation or codefiles (.cpp).CPSC 427a 11/26Outline Lab Work Review PS1 Survival C++ I/OHow to use the textbookThe lectures do not exactly follow the textbook, but they areroughly parallel.For example, lectures 1–3 generally correspond to chapters 1 and2, although several concepts from chapters 3 and 4 were alsocovered briefly.You should read the corresponding chapters carefully, becausethere is information in the book that will not be covered explicitlyin class but that you should nevertheless know.CPSC 427a 12/26Outline Lab Work Review PS1 Survival C++ I/OA Survival Guide for PS1CPSC 427a 13/26Outline Lab Work Review PS1 Survival C++ I/OOperator extensionsFor PS1, you need to extend three operators <=, <<, and >> towork with type Player.The corresponding function names are:Operator Function name<= operator<=<< operator<<>> operator>>Operators extensions are simply new methods for thecorresponding functions.CPSC 427a 14/26Outline Lab Work Review PS1 Survival C++ I/OAdding new methodsEvery function in C++ may have many methods.Which method is selected in a function call depends on thenumber and types of its arguments, which we call its signature.Every method must have a distinct signature.For PS1, the signatures of the methods to be defined are given inPlayer.hpp.bool operator<=(const Player& p2) const;istream& read(istream& in);ostream& print(ostream& out) const;CPSC 427a 15/26Outline Lab Work Review PS1 Survival C++ I/OTwo kinds of functionsTop-level functions: These are ordinary C-style functions.Member functions: These are functions that belong to a class.When run, the special variable this is an implicitparameter which points to an instance of the class.Corresponding to the two kinds of functions are two differentcalling syntaxes:Top-level call: Like C, e.g., f(x, a).Member call: Uses the field selector “dot” notation, e.g., x.g(a).Here, x is an object (instance of a class) containinga member function g().x becomes the implicit parameter of g(); a theexplicit parameter.CPSC 427a 16/26Outline Lab Work Review PS1 Survival C++ I/OAn ambiguity with operator extensionsAn operator like + invokes its associated function operator+().But which kind of call does a+b correspond to?1. operator+(a, b)?2. a.operator+(b)?The answer is “both”, with preference given to (2) if thecorresponding method is defined.CPSC 427a 17/26Outline Lab Work Review PS1 Survival C++


View Full Document

Yale CPSC 427 - Lecture 4

Download Lecture 4
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 4 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 4 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?