-------------------------------------------------------------------------- Object-oriented Systems Fall 1995 COM 3360/NTU SE737 --------------------------------------------------------------------------- Assignment 1 Due date: Monday, Oct. 2 NTU: one week later --------------------------------------------------------------------------- This assignment is stored in file $OO/hw/1 in file assign.txt THEME: Learn to know Adaptive Software ========= On CCS Northeastern machines, OO=/course/com3360 On the WWW, OO = http://www.ccs.neu.edu/research/demeter/course ========= Use the following header for your electronic homework submissions and put it at the top of the message: Course number: COM 3360 / NTU SE737 (whichever applies) Name: Account name: Assignment number: Date: The teaching assistant for this course is Katherine Klimukhina (login name: kate). Whenever you have questions about course material, please send e-mail to: mail lieberherr@ccs.neu.edu ccs.courses.com3360@ccs.neu.edu Get the class packet from Gnomon Copy, 325 Huntington Avenue and get the text book from the bookstore. (NTU students get all those by FED EX.) Get an account on Northeastern machines if you don't have one already. Set it up to use C++ compilers and the Demeter Tools/C++. To get access to the latest version of the C++ compilers and the Demeter Tools/C++, copy file $OO/.software into your file ~/.software and type command resoft PART A: ================================================================== Do assignment 1 described in chapter 17, page 545. Note that you no longer have to do the account set-up (Background Task 1). A part of assignment 1 is duplicated here for your convenience to save you typing. Part 1: C++ program completion: class definitions ------------------------------------------------- What to turn in: The C++ program fragment which you wrote and its output. This assignment recalls some of your knowledge of C++. You are asked to write class definitions for the following program so that it produces the output given at the end on lines starting with //. Put your entire program into one file called tree.C and compile with CC tree.C or gcc tree.C -lg++ (choose one of those compilers). It is suggested that you do the set-up which is at the beginning of this homework to initialize your computing environment, i.e., copy .software and use resoft.) Complete the following program: #include // write here the class definitions for DemNumber and Tree DemNumber::DemNumber() {}; Tree::Tree(DemNumber* node_in, Tree* left_in, Tree* right_in) { node = node_in; left = left_in; right = right_in; } int max(int a, int b){ return (a>b ? a : b);} int Tree::depth(){ return (max (left ? left->depth() : 0, right ? right->depth() : 0) + 1); } int Tree::size(){ return (left ? left->size() : 0) + (right ? right->size() : 0) + 1; } main (){ cout << "\nFirst Tree" << "\n"; DemNumber *n1 = new DemNumber(); Tree *t1 = new Tree(n1, 0, 0); cout<<"\ndepth of tree 1 ="; cout<depth(); cout<<"\nsize of tree 1 ="; cout<size(); cout << "\nSecond Tree" << "\n"; Tree *t2 = new Tree(n1, t1, t1); cout<<"\ndepth of tree 2 ="; cout<depth(); cout<<"\nsize of tree 3 ="; cout<size(); cout << "\nThird Tree" << "\n"; Tree *t3 = new Tree(n1, t2, t1); cout<<"\ndepth of tree 3 ="; cout<depth(); cout<<"\nsize of tree 5 ="; cout<size(); } // output to be produced //First Tree // //depth of tree 1 =1 //size of tree 1 =1 //Second Tree // //depth of tree 2 =2 //size of tree 3 =3 //Third Tree // //depth of tree 3 =3 //size of tree 5 =5 You should hand in all source code and a trace file showing all the output from running your program. Trace files can be created by using the script command BEFORE you start your work. Type exit after you are done to close the output file (default file is called typescript). For example, script # do all your work exit # exit will close the file typescript PART B: Exercise 1.1 on page 16 of the textbook. Turn in your reflections about your earlier work. At most 1/2 page. It is fine if you have not experienced those limitations before. ===================================================================== Corrections to the Laboratory Guide: From a happy user: Hi Crista: I just finished working through the Demeter Lab Guide and already feel a lot more comfortable with Demeter. The Lab Guide is concise, clear and written with a great deal of empathy for the user. Congratulations for doing such an excellent job with the Lab Guide! Here are some minor nits: 1. On page 36 "./run library-init" should be "./run library-input". 2. On page 37 D = "d-object" . . It should be D = "d-object" . 3. There are a number of places where memory allocation is done but there is no corresponding free. Since this is just a demo it is obviously not important. Most of these can be fixed easily. E-mail submission ================= Please follow the following rules: WHERE Send your solution to the teaching assistant. He/she stores the solutions and I can inspect them electronically. ONE ASCII FILE Send only ONE ascii file containing your hw solution. COMPLETE SOLUTION Send the complete text of your homework solution. Don't just send a message "my solution is in directory ...". This keeps your solution protected from access by others and allows for faster grading. COMPUTER USAGE: For doing the assignments you will need to use the Demeter Tools/C++. You can do that by 1. rlogin/telnet to computers at CCS (College of Computer Science, NU) 2. ftp Demeter to your machine, if it is available on it. See URL: ftp://ftp.ccs.neu.edu/pub/people/lieber/DemeterTools.txt regarding availability (currently it is SUN, RS6000 and Linux) 3. If you are close to Boston, dial in to the CCS computers. Regarding 1 and 3, see URL: http://www.ccs.neu.edu/labs/index.html Options 1 and 3 requires no installation on your part but access will be a bit slow depending on your location. Option 2 will be faster but you need to install Demeter. You do not however need root access for that .. Just plenty of disk space.. :)