.Open CSci202 Computer Science II, Session 02, Review . Previous .See http://www/dick/cs202/01.html . Preparation Study the page below and chapters 1,2,3, 4,5,6 and write down the questions, doubts, and surprises that you have on a piece of paper. .Open Reading 1 Introduction to Computers, the Internet and theWorldWideWeb 2 Introduction to C++ Programming 3 Introduction to Classes and Objects 4 Control Statements: Part 1 5 Control Statements: Part 2 6 Functions and an Introduction to Recursion .List 6.19 Recursion 294 Example .See ./02rec.cpp .See ./20rec.cpp 6.20 Example Using Recursion: Fibonacci Series 298 6.21 Recursion vs. Iteration 301 .Close . Assigned Work Due Submit one question before 10am by using the web form provided above to earn credit. This will tell me what topics to cover in the class. . Exercise As a member of the CSci Honors committee I have to calculate a special GPA of all people who apply for honors each qusrter. This is a GPA of just the computer science classes -- and the main computer on campus runs the Student Information System (SIS+) and doesn't do this for me. So I need to store upto 30 floating point numbers, add them up, find the maximum and minimum, and print out these three statistics. Write the Simplest Possible Program that could do this... . Chapter 3 pages 86 -- Void Functions I understand that void functions do not return any data, but why is it that some void functions have return (identifier) in them? The "return" statement has to purposes. (1) it gets you out of the function. (2) it can also give the caller a piece of data. A "void function" may not give the caller any data. I think it will be thrown away. Some void functions have no "return" because there is an implicit, invisible, "return" placed at the end of the function. . Chapter 3 pages 88-90 -- CSCI 202 What are arguments and parameters? They are the same things. Mathematicians talk about parameters and C program talked about arguments. BUT they both ment the data that is give to a function to calculate with. For example .As_is double sin( double x) (in ) is a function with a single double parameter called `x`. It is called like this .As_is whatever = a * sin (omega) + b*sin(gamma); and in each call it is given the `actual` value that to initialize `x`. . Chapter 3 pages 88-90 -- Functions How do you define a function's peramiters? (1) Good spelling is important for wizards. (2) In the header of the function: .As_is ReturnedType name( parameters ).... . Chapter 3 pages 89-93 -- Classes Can you give a better explanation on how classes work and what they're used for? Classes pay off when organizing a complex project -- it splits a thousand chaotic lines of code into half-a-dozen well organized files with 100 lines of code in each... A class describes a rules for a collection of similar objects. An object contains data value -- named data values, called attributes. These are declared in a class. So, if we needed to talk about Points in a Cartesian grid we would expect two coordinates called `x` and `y`. A class that looks like this: .As_is class Point { .As_is double x; .As_is double y; .As_is ... .As_is }; Describes objects with 2 attributes called x and y. A class describes data in an object and the functions that can apply to these objects. A class also defines rules for constructing new objects. These are special functions that have the same name as the class itself: .As_is class Point { .As_is double x; .As_is double y; .As_is public: .As_is Point(){ x=y=0; } .As_is Point(double x0, double y0){ x=x0; y=y0; } .As_is ... .As_is }; You can add functions that do things to Points.... for example to move one. And you can add functions to calculate properties of a Point: .As_is public: .As_is Point(){ x=y=0; } .As_is Point(double x0, double y0){ x=x0; y=y0; } .As_is void move(double dx, double dy){ x+= dx; y+=dy; } .As_is double length(){ return x*x + y*y; } .As_is ... .As_is }; Object-oriented design is the diffcult task of discovering the best set of classes to fit the user's needs. Here are my .See ./objects.html rough notes on classes. . Chapter 3 pages 91 - 95 -- Class member functions How do you know when you should and shouldn't use the get and set functions? Are these functions necessary in a Class when you can directly just call the function. (i.e, data()). Access to the private data in an object must me on a `need to know` basis. Only add a "get" function when another type of object needs the value. Only add a "set" function to a class when a different class needs to change the value. In a complex program it heps to draw interaction diagrams -- pages 386 thru to 391 before you write the code. The arrows tell you the minimum set of funtions in each class needed to meet the user's needs. Beware the temptation to add "get" and "set" for every variable "Just In Case" -- You Ain't Gonna Need It. . Chapter 3 pages 99-101 -- classes/constructors what is the difference between a constructor and a Default Constructor? The Default constructor needs to data and provides suitable default values for the private data in the newly constructed object. It is the constructor used for declarations like this .As_is Whatever foo; However, non-default constructors have arguments and are used for declarations like this: .As_is Whatever foo(bar, mumble, 42, 3.14159, "ying tong iddle I po"); . Chapter 4 pages 139 -- BOOL or bool What is BOOL and when exactly is it used? The correct spell is .As_is bool and it is the name of the "Boolean data type" invented by George Boole to model "The Laws of Thought". Boolean data have no more than 2 values .As_is false .As_is true They have a dozen operators: .As_is and && .As_is or || .As_is not ! But, the "English" form means the same thing as the older "C" symbolic form. All tests and conditions become a Boolean value before the if/while/for... gets to them. You will use them -- perhaps without knowing it in all interesting programs. You can also declare `bool` variables: .As_is bool tooBig; and store values in them for later use: .As_is tooBig = (x >1000000 or y >100000); . Chapter 4 pages 173 -- boolean what is boolean attribute? A boolean attribute is a property of an object that have two values: true and false. . Chapter 5 pages 194 -- Essentials of Counter-Controlled Fepetition which counter-controlled is more usefull when writting a complex code, the FOR repetition statement or the WHILE statement? and what are the benefits of using that statement? Use counter controled loops for counting and scanning across data strutcures! Use the `while` for simple loops. . Chapter 5 pages 197 -- For Loop What exactly is a "for loop" and how do you implement them? It is short hand for a very comoon kind of loop. .As_is for( Student s = class.first(); not s.end(); s.next) .... The syntax is .As_is for (A; B; C ) D where A is statement, B is a condition, C an statement and D any statement. The compiler converts it into this code .As_is { .As_is A; .As_is while(B) .As_is { .As_is D; .As_is C; .As_is } .As_is } Using "for" in this saves a lot of typing... The vast majority of for-loops look like .As_is for( int i =1; i<=n; i++) .... or .As_is for( int i =0; i .See ./iomanip.html . Chapter 8 pages 414 -- Passing Arguments to functions by reference with pointers In the book it claims that there are three ways in c++ to pass arguments to a function 1. pass by reference with reference arguments, pass by reference with pointer arguments, as well as pass by value...is their any other more complicated way to pass an argument to a function? . Lab Review: .See http://www/dick/cs202/lab01.html . Next -- Arrays + Vectors + Project Topics: .See http://www/dick/cs202/03.html The first project .See ./p1.html is due in the fourth class. It is on Arrays (Chapter 7). Select one and start it as soon as you can. Hand in what ever you've got, however bad, at the start of the 4th class. .Close CSci202 Computer Science II, Session 02, Review FAQ::="Frequently Asked Questions", see .See http://www.faqs.org/faqs/ for more FAQ.