[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci & Eng Dept] / [R J Botting] / [CSci201] / 20
[Text Version] [Syllabus] [Schedule] [Glossary] [Labs] [Projects] [Resources] [Grading] [Contact] [Search ]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] <20>
Podcasts: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12]
Labs: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10]
Sat Mar 15 09:48:02 PDT 2008

Contents


    Pages 1-282 Review

      Reading

      Go back over everything we have studied and work out the one question you positively must have answered before the final! This is your last chance.

      Review all the past quizzes.

      Questions

        Can you post all quizzes

        No. Please refer to the marked up and graded ones I have handed back.

        What is the most important thing to remember in the final

        Be prepared
        1. A 8><11 sheet of paper with notes on things you don't want to forget
        2. Two sharp pencils
        3. A working eraser
        4. DON'T PANIC

        Will there be questions on previous projects

        No. Just th last one -- draw a UML: diagram of the class in your last project.

        Can we do an exercise that sumarizes everything

        NO TIMe... and we did somethin like this in class 19.

        Did anyone get the tic-tac-toe lab project running

        Yes. See [ lab10/ttt.cpp ] from Justin for the first working version to be sent to me by Email.

        Is there any way to magnify the output of the tic-tac-toe board.

        I can think of two techniques.

        You can use a graphic library and build a GUI. This quarter we didn't do any of this seeing it is not standard and is not in the book.

        Or you can write a whole library of functions to write out the symbols in large format:

         	X     X
         	 X   X
         	  X X
         	   X
         	  X X
         	 X   X
         	X     X
        I figure you would need about 11 functions or a single function with an argument and a rather large selection of 11 different forms.

        Give an example of a working function

        In class we did one to switch the first and last names of a person. See next question.

        Please go over strings

        In class we did a series of examples based on slicing up a string containing a first name, and initial, and a surname. We turned this into a string with the surname, a comma, and the firstname.

        We used

        1. string s = "...."
        2. s[i]
        3. s.substr(first)
        4. s.substr(first, length)
        5. s.find(character)
        6. s.rfind(character)

        Her is the function after testing with added comments:
         	string example(string name)
         	{  // assume name = "First Initial Last"
         	   // return "Last, First"
         	   int sp1 = name.find(' ');
         	   int sp2 = name.rfind(' ');
         	   return name.substr(sp2+1)+ ", "+ name.substr(0,sp1);
         	}
        [ texample.cpp ]

        More on strings see: [ 09.html ]

        Please go over Classes

        [ 15.html ] [ 16.html ]

        Do classes seem easy to me

        As long as they only have simple member functions they are simple.

        Thinking about classes is more abstract than trying to avoid them.

        Practice makes it easier.

        How do member functions effect classes and the rest of the program

        A member function is always applied to an object:
         		object.function(data)
        Objects contain data members, The function accesses these data variables, for the object and can change them.

        The class doesn't change -- the objects change.

        Member functions can reutrn values that are used in the rest of the program.

        Member functions can also refer to global variables like cout and cin and som make the program do things. The wise programmer avoids this if at all possible.

        Is there a way to avoid overloading constructors

        Mostly you want to!

        Be careful with the definitions and default parameters. There is also an advanced declaration that stops the compiler providing the default constructor when you declare a variable.... CSci202 or 330.

        Please go over Arrays

        An array is a collection of elements -- all the same size, and numbered from 0 upward. It has a fixed number elements. The size of the array is fixed when we declare it and can not be changed.

        Think of arrays as a series of boxes. One box per item. No space between them. Labeled with numbers: 0,1,2,3,....

        See [ 07.html#More%20About%20Arrays ] for a simple example of declaring and using an array.

        The following link [ lookup.php?search=array&from=cs201.20 ] will take you to a list of places in this course where we have talked about arrays.

        Please go over vectors

        [ vectors.html ] [ ../examples/vectors.cpp ]

        Go over pointers

        A pointer is a special type of data. It holds an address. It is used to remember where the "real" data is kept. Think of it a variable that has a cell phone number in it. You can dial the number and contat the phone by putting the de-reference "*" operator in front of the variable. In reverse the "&" is the address of operator and returns a value you can store in a pointer:
        1. Type * pointer;
        2. pointer = & variable;
        3. pointer = pointer_of_same_type;
        4. pointer = array_name;
        5. pointer = new data_type(data);

        6. * pointer
        7. point [ index ]

        8. delete pointer;

        See [ 12.html ] and [ lab07/ ] for more.

        How to recognize pointers

        To be sure you work backwards to the declaration and look for an "*" asterisk in it.

        Wise programmers often add a "p" to the ends of pointer variable names.

        Go over new and delete

        New T gives you a piece of storage the right size for an object of type T. It returns the address of the block of storages and so you should use it like this
         	T *tp = new T;
        From then on '*tp' is the new object.

        You should return the storage when your prgram has finished with it like this

         	delete tp;
        Noticw the abscence of an asterisk. The machine needs to be given the address of the object to be returned.

        You can also use new to get an array of objects...

      . . . . . . . . . ( end of section Questions) <<Contents | End>>

      Next Final Examination and Project 9

    Abreviations

  1. Gnu::="Gnu's Not Unix", a long running open source project that supplies a very popular C++ compiler.
  2. KDE::="Kommon Desktop Environment".
  3. OOP::="Object-Oriented Programming", Current paradigm for programming.
  4. SP::="Structured Programming", Previous paradigm for programming.
  5. TBA::="To Be Announced", something I should do.
  6. TBD::="To Be Done", something you have to do.
  7. UML::="Unified Modeling Language", [ 15.html ] (class notes on the UML and OOP).

End