3 Representation in C++.

Size: px
Start display at page:

Download "3 Representation in C++."

Transcription

1 3 Representation in C++. The computer language C++ is well suited for implementing a grid generator. C++ is a superset of C. The discussion below assumes knowledge of the language C. One major difference between C++ and C is that C++ has a data type called a class. A class is a generalization of the struct in C, or the record in Pascal. In a class we can gather together a number of variables. We have also the possibility to let functions be a part of a class. Furthermore we can chose to make certain variables and functions inaccessible for all code outside the class itself. The main idea, is that a class should be something encapsulated well isolated from the rest of the code. The class can only be used through well defined interfaces. It is often difficult to design good classes, however for boundary curves it is fairly easy to get a clean representation with classes. 3.1 A first example of a class Below we show an example of a class which implements the boundary curve where x is used as curve parameter. class bcurve double a, b; double a0, a1; int dir; bcurve( double a in, double b in ) a0 = ; a1 = 0.67; a = a in; b = b in; dir = 0; double x( double p ) double y( double p ) return a0*sqrt(p) + a1*p; void reverse() dir =!dir; ; A class declaration has the structure class name // declarations ; y = a 0 x + a1 x, a x b (3.14) 32

2 The word class is a reserved word, the name of the class is an identifier chosen by the programmer. The class bcurve contains now the variables a,b, the end points of the curve parameter, a0, a1 describing the parameter functions, and dir which is the direction of the curve. The value 0 of dir means that p goes from a to b, avalueof1meansfromb to a. bcurve also contains the functions bcurve, x, y, and reverse. The reserved word private means that these variables can only be accessed from functions inside the class. Under public we declare the variables and functions which any user of the class will be able to access directly. This constitutes the interface to the class. A class should be designed such that specific details that we may want to change later is kept under private. Changes become in that case local only to the class, and the rest of the code using the class can remain unchanged. Another reason to use private, is to prevent users of the class to change variables by mistake. For example, the variable dir can not be accessed directly, but can only be changed in a very controlled way through the function reverse. The first function under public is a function with the same name as the class, and with no return type. This is an initialization function, called a constructor, which is called automatically each time a variable of the class type is created. The intended use of the constructor is to give values to all variables in the class, so that we do not risk, by mistake, to use uninitialized variables. The other two public functions are the parameterization (x(p),y(p)). In a main program, the class is used as in the example below, where 10 points on the curve are generated. // The class declaration here. int main() bcurve bc(0,1.0); double x[10], y[10]; for( int i=0; i<10; i++ ) x[i] = bc.x( i/9.0 ); y[i] = bc.y( i/9.0 );... ; A variable of class type, such as bc in the example above, is called an object. When the program is executed, the first declaration bcurve bc(0,1.0); will immediately cause the constructor of the bcurve class to be called with the parameter values a in=0, b in=1.0. Note the dot notation bc.x(0.0) to access a member function of a class. Variables are accessed in the same way, e.g., bc.a denotes the left endpoint of the curve. However, in this example, trying to access a in the main program will lead to a compilation error, because a is declared as private. Normally functions are not defined inside the class definition as in the example above. C++ allows us to define the functions outside the class, and only declare them inside the class. The same example can in that case be written class bcurve double a, b; double a0, a1; 33

3 int dir; bcurve( double a in, double b in ); double x(double p ); double y(double p ); void reverse(); ; bcurve::bcurve( double a in, double b in ) a0 = ; a1 = 0.67; a = a in; b = b in; dir = 0; double bcurve::x( double p ) double bcurve::y( double p ) return a0*sqrt(p) + a1*p; void bcurve::reverse() dir =!dir; When the function definitions are lifted out of the class, they must be preceded by classname::, so that the compiler knows where the functions belong. It is possible that two different classes contain functions with the same name. The function definitions can now be put anywhere in the program. Often they are written on a separate file. Every part of the code which will use the class bcurve must include the class declaration at the top of its file. Therefore one usually puts the class declaration in a special file called in this case bcurve.h which we give below. class bcurve double a, b; double a0, a1; int dir; bcurve( double a in, double b in ); double x(double p ); double y(double p ); void reverse(); ; The file bcurve.h The function definitions are put on a separate file, bcurve.c, which is compiled separately once and for all. We give bcurve.c below. #include "bcurve.h" bcurve::bcurve( double a in, double b in ) a0 = ; a1 = 0.67; a = a in; b = b in; dir = 0; 34

4 double bcurve::x( double p ) double bcurve::y( double p ) return a0*sqrt(p) + a1*p; void bcurve::reverse() dir =!dir; The file bcurve.c In the main program where we use the class bcurve, we include bcurve.h as shown below #include "bcurve.h" int main() bcurve lower boundary(0,0.5);... The advantage with this, is that the functions inside the class bcurve are compiled once. We can compile the main program without recompiling the functions in bcurve. Had they been written inside the class, as in the first example in this chapter, the function definitions would have been present in the include-file, and therefore recompiled every time the main program was recompiled. When several files include each other in a non-trivial way, it can easily happen that a file like bcurve.h becomes included more than once. To avoid this, it is common practise to put extra preprocessor directives in bcurve.h, as follows #ifndef #define BCURVE BCURVE class bcurve double a, b; double a0, a1; int dir; bcurve( double a in, double b in ); double x(double p ); double y(double p ); void reverse(); ; #endif The file bcurve.h, with preprocessor directives This will ensure that bcurve.h is included only once. One way to improve execution speeds is to inline small functions which are called often. Inlining means that the compiler does not generate calls to the function, but instead it inserts the entire source code of the function at each place where it is called. In C++, we tell the compiler to inline a function, by using the keyword inline in front of the function. inline double x( double p ) 35

5 Furthermore, all functions which are defined inside the class declarations becomes inline by default. Inlined functions are similar to macros, but gives less risk for unwanted side effects. Inlined functions must be defined in the same file as it is being called. Separate compiling of inline functions is not allowed in C++. Inline functions are therefore usually defined in the include file, such as shown in the class declaration bcurve.h below. #ifndef BCURVE #define BCURVE class bcurve double a, b; double a0, a1; int dir; bcurve( double a in, double b in ); inline double x(double p ) inline double y(double p ) return a0*sqrt(p) + a1*p; void reverse(); ; #endif We next improve the class above. Assume that we want to reparameterize, using the arc length normalized to [0, 1]. We would then define the class as class bcurve double a, b; double a0, a1; int dir; double length; double xo( double p ); double yo( double p ); bcurve( double a in, double b in ); double x( double s ); double y( double s ); ; The private functions xo,yo describes the curve in original parameterization, these are private because the user of the class should not have to worry about the exact description of the parameterization. Instead the curve should be accessed from the outside through the public functions x,y, in which the arc length is used as parameter. In this way, the curve can be implemented with any equivalent parameterization in xo,yo, the user will not note the difference in the functions x,y. Assume that we put the class declaration above on the file bcurve.h. The member functions can then be defined as below. #include "bcurve.h" double bcurve::xo( double p ) double bcurve::yo( double p ) return a0*sqrt(p) + a1*p; bcurve::bcurve( double a in, double b in ) 36

6 a0 = ; a1 = 0.67; a = a in; b = b in; dir = 0; b length = // numerical approximation of xo (p) 2 + yo (p) 2 dp a double bcurve::x( double s ) p // solve s =1/(length) xo (t) 2 + yo (t) 2 dt for p a return xo(p); double bcurve::y( double s ) p // solve s =1/(length) xo (t) 2 + yo (t) 2 dt for p a return yo(p); The main program given previously can still be used unchanged with this modified class. Assume that we want to use the parameter t instead of x, where the curve now is defined by x = t 2 y = a 0 t + a 1 t 2 This curve has the same graph as the curve (3.14), but a different parameterization (and different parameter values at the end points). We could then make this change in the functions xo,yo, but the main program (or any other function using the class) can remain unchanged. Remark: An efficient algorithm to solve the arc length equation s = 1 p x L (p) 2 + y (p) 2 dp a is Newton s method, p 0 =guess p k+1 = p k pk a x (p) 2 +y (p) 2 dp sl x (p k ) 2 +y (p k ) 2 k =0, 1, 2,... Where the iteration proceeds until the difference p k+1 p k is less than some given tolerance. The integral is evaluated by, e.g., Simpsons method, where the interval [a, p k ] is divided into a sufficiently large number of subintervals. It is possible to implement the integral evaluation such that only the update p k+1 p k.. dp needs to be computed in each iteration. However, I have not investigated whether this is advantageous or not. 3.2 Dynamic allocation of objects The declaration bcurve bc(0,1.0); allocates the object bc in static memory. It is common to use dynamic allocation of objects instead. In order to do that, we first declare a pointer to the object 37

7 bcurve *bc; The memory allocation is done by the statement bc = new bcurve(0,1.0); The parameters (0,1.0) are passed to the constructor, which is called automatically when the object is allocated. To access a member function of the object, we can use the expression x[i] = (*bc).x(i/9.0); The parenthesis are necessary, because the member selection operator,., has higher priority than the dereference operator, *. There is an alternative way to write the same expression, namely x[i] = bc->x(i/9.0); When an object is no longer needed, it can be deallocated by the delete operator, delete bc; Unused objects should be deallocated, since C++ does not have automatic garbage collection. Programs that break during execution due to memory leaks, are not uncommon with C and C Base classes and virtual functions Consider the domain in Fig. 2.1 below. It consists of four sides, one is a circular arc, two sides are straight lines, and one side is defined by spline points Fig. 2.1 Example of boundary curves. We could think of introducing three C++ classes to describe the boundary. The classes circle do describe the arc, line to describe the straight line sides, and spline curve to describe the outer boundary. We could then write the class domain to describe the entire domain. It contains the four boundaries as members, and the class could have the capability to generate a grid on the domain. class domain circle *side1; spline curve *side2; line *side3, *side4; double *x, *y;... 38

8 ... void generate grid( int n, int m );... ; The members x, y are matrices which will contain the grid. The problem with this approach is that it lacks generality. Tomorrow, we might want to generate a grid in a different domain. We would then have to rewrite the domain class, in order to fit in other types of boundary curves. We would like to have a way to write a general domain class in which we can declare the boundary curves as bcurve *sides[4]; and where the domain class does not need to care about which type of curve each side is. This can be accomplished by using inheritance, which we now describe by a simple example. Consider the class below, describing a polygon. #include <iostream.h> #include <math.h> struct point double x; double y; ; class polygon int npts; point *vertices; double distance( point, point ); polygon( int n, point *vert ); void translate( double dx, double dy ); void draw( Widget w, GC& gc ); void rotate( double alpha ); double perimeter(); ; We have introduced a data type point, describing a point in the plane. In C++ a struct is the same thing as class, except for the difference that all variables are public by default in a struct. In a class the default is to make a member private. For example, some of the member functions are defined as polygon::polygon( int n, point *vert ) npts = n; vertices = new point[npts]; for( int i=0 ; i<npts ; i++ ) vertices[i] = vert[i]; double polygon::perimeter( ) double p=0; for( int i=0 ; i<npts-1 ; i++ ) p += distance( vertices[i], vertices[i+1] ); p += distance( vertices[npts-1], vertices[0] ); The function distance gives the distance between two points in the plane. 39

9 Assume that we use this class to represent a square. The square has additional properties that makes it a very special type of polygon. For example, the perimeter of a square can be computed more efficiently than in the general case above, by just taking 4 times the side. We want to exploit the special properties of the square. We do that by introducing the class square as a derived class from the class polygon. The declaration of square is given below. class square : public polygon double side; square( point vert[4] ); double perimeter(); ; square::square( point vert[4] ) : polygon( 4, vert ) side = distance( vert[0], vert[1] ); double square::perimeter() return side*4; The first line class square : public polygon means that the square class contains the entire polygon class. We say that square inherits polygon. The public means that all the public members in polygon are also public in square. The constructor of square takes the four corner points as a parameter. Before the body of square::square is executed, the constructor of the base class polygon is called. This is the meaning of the notation : polygon(4,vert). Note how we have defined a new version of the function perimeter in square. In order for everything to work as intended we have to make a few small changes in the base class. We change the base class to class polygon protected: int npts; point *vertices; double distance( point, point ); polygon( int n, point *vert ); void translate( double dx, double dy ); void draw( Widget w, GC& gc ); void rotate( double alpha ); virtual double perimeter(); ; We have changed private to protected. The derived class, square, can not access the private variables in the base class. Protected is used to allow derived classes to access the variables. In other respects the variables under protected are inaccessible from the outside. The second change is that we have added the reserved word virtual to the function perimeter. The meaning of virtual is to tell the compiler that this is a function which can be redefined by a derived class. In the main program we can now use the classes as usual, point verts[5], sqverts[4];... polygon *p = new polygon( 5, verts ); 40

10 square *s = new square( sqverts ); What is more important is that we can assign squares to polygons, point verts[5], sqverts[4];... polygon *p = new polygon( 5, verts ); polygon *s = new square( sqverts ); // call to polygon::perimeter cout << "perimeter of polygon is " << p->perimeter() << endl; // call to square::perimeter cout << "perimeter of square is " << s->perimeter() << endl; If we had not declared perimeter to be a virtual function, the call s->perimeter above would have been a call to polygon::perimeter(). Although *s is of type polygon, it can be assigned a square. This is called polymorphism, and is a powerful technique, which is often used to avoid alternative statements like switch( type ) case s : per = perimeter square(); break; case r : per = perimeter rectangle();break; case c : per = perimeter circle();break; default: per = perimeter general(); Codes which rely on a special type variable to choose between cases, like in the example above, are difficult to maintain and modify. With a good hierarchy of inheriting classes such switch statements can be replaced by a single call to a virtual function. The assignment square s; polygon p; p = s; is thus allowed, but the opposite assignment s=p is forbidden. This is not strange, since it is unlikely that a polygon is a square. However, a square is always a polygon. 3.4 Abstract base classes In the previous example the function polygon::perimeter() was replaced by a function withthesamenameinthederivedclasssquare. It is often advantageous to instead define a base class with unspecified virtual functions, a so called abstract base class. Consider the example class shape points* vertices; int npts;... shape( ); virtual void rotate( double alpha ) = 0; virtual void translate( double dx, double dy ) = 0; virtual double perimeter() = 0;... ; By using the notation =0 after the function, we have here declared the functions rotate, translate, andperimeter to be purely virtual functions. This means that the the 41

11 functions are not defined in shape, but that they will be specified in classes which are derived from shape. No objects of the abstract base class can be created. The declaration of an object shape sh; is wrong, since the purely virtual functions are not defined in shape. An abstract class can be used only as a base for another class. An abstract class can be used to create an interface to the class without giving any information about implementation. 3.5 Programming exercise: A base class for boundary curves We would now like to use the techniques described above to redesign the bcurve and domain classes described in Section 3.3. First we define an abstract base class for boundary curves. It should contain at least the following information class curvebase protected: double pmin, pmax; // Max and minimum values of curve parameter int rev; // pmin to pmax or vice versa virtual double xp( double p ) = 0; // x(p) virtual double yp( double p ) = 0; // y(p) virtual double dxp( double p ) = 0; // x (p) virtual double dyp( double p ) = 0; // y (p) double integrate( double a, double b ); // arc length integral... curvebase() ; // constructor double x( double s ); // arc length parameterization double y( double s ); // arc length parameterization... ; Exercise 1: Complete the class by writing the non-virtual functions. Add more variables or functions to the class, if you find it necessary. Exercise 2: You will generate a grid on the domain in Fig. 2.2 below Fig. 2.2 Computational domain. The corners are located at (-3,1), (3,0), (3,3), and (-3,3). The lower boundary is given by the function y =1/(e 5x + 1). (The lower corners do not match perfectly, but for all practical purposes we can assume that 1/(e 15 +1)= 0and1/(e 15 +1) = 1.) Derive classes that are needed to represent the boundary curves of the domain in Fig. 2.2 from the base class. Test the class by using it in a simple main program. 42

12 Exercise 3: Design a class domain as outlined in Section 3.3. The class should contain four boundary curves of type curvebase, and have capability for generating a grid on the domain. Write a main program which generates the grid. Use the algebraic grid generation formula (2.2). Exercise 4: Add a function to the class domain to write the grid to a file. The simplest is to use cout to write an ascii file. A better way is to use the unix functions open, write, and close to output the grid in binary format. We give an example below of how they are used to write a vector x consisting of n m doubles. #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h>... int fd = open( "outfile.bin", O CREAT O RDWR O TRUNC, 0660 ); int nr = write( fd, x, n*m*sizeof(double) ); close(fd); Use the unix commands man open, andman -s 2 write to obtain more information about these functions. The grid can be viewed in Matlab. To read a binary file, use the Matlab functions fopen and fread. Exercise 5: This exercise is not compulsory, just do it if you have time, and would like to make a better program. The four boundary curves are somehow input to the class domain, e.g., through a constructor. You have probably up to now used some convention of type the first argument to the constructor should be the lower boundary etc. Add a function order boundaries to the class domain. This function should order a random set of four boundaries such that bcurve[0] and bcurve[1] are always facing each other, and have consistent coordinate directions, and the same for bcurve[2] and bcurve[3]. When this function is used, the boundary curves can be input to domain in any order, with any direction of the parameter. 43

Determine If An Equation Represents a Function

Determine If An Equation Represents a Function Question : What is a linear function? The term linear function consists of two parts: linear and function. To understand what these terms mean together, we must first understand what a function is. The

More information

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage

More information

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement? 1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members

More information

An Incomplete C++ Primer. University of Wyoming MA 5310

An Incomplete C++ Primer. University of Wyoming MA 5310 An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages

More information

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism Polymorphism Problems with switch statement Programmer may forget to test all possible cases in a switch. Tracking this down can be time consuming and error prone Solution - use virtual functions (polymorphism)

More information

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London

More information

C++FA 5.1 PRACTICE MID-TERM EXAM

C++FA 5.1 PRACTICE MID-TERM EXAM C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer

More information

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations

More information

EP241 Computer Programming

EP241 Computer Programming EP241 Computer Programming Topic 10 Basic Classes Department of Engineering Physics University of Gaziantep Course web page www.gantep.edu.tr/~bingul/ep241 Sep 2013 Sayfa 1 Introduction In this lecture

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

13 Classes & Objects with Constructors/Destructors

13 Classes & Objects with Constructors/Destructors 13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.

More information

Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1

Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1 Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1 Introduction to Classes Classes as user-defined types We have seen that C++ provides a fairly large set of built-in types. e.g

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

Continued Fractions and the Euclidean Algorithm

Continued Fractions and the Euclidean Algorithm Continued Fractions and the Euclidean Algorithm Lecture notes prepared for MATH 326, Spring 997 Department of Mathematics and Statistics University at Albany William F Hammond Table of Contents Introduction

More information

Figure 2.1: Center of mass of four points.

Figure 2.1: Center of mass of four points. Chapter 2 Bézier curves are named after their inventor, Dr. Pierre Bézier. Bézier was an engineer with the Renault car company and set out in the early 196 s to develop a curve formulation which would

More information

CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing

CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing CpSc212 Goddard Notes Chapter 6 Yet More on Classes We discuss the problems of comparing, copying, passing, outputting, and destructing objects. 6.1 Object Storage, Allocation and Destructors Some objects

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

Questions: Does it always take the same amount of force to lift a load? Where should you press to lift a load with the least amount of force?

Questions: Does it always take the same amount of force to lift a load? Where should you press to lift a load with the least amount of force? Lifting A Load 1 NAME LIFTING A LOAD Questions: Does it always take the same amount of force to lift a load? Where should you press to lift a load with the least amount of force? Background Information:

More information

Common Beginner C++ Programming Mistakes

Common Beginner C++ Programming Mistakes Common Beginner C++ Programming Mistakes This documents some common C++ mistakes that beginning programmers make. These errors are two types: Syntax errors these are detected at compile time and you won't

More information

Grade 7/8 Math Circles November 3/4, 2015. M.C. Escher and Tessellations

Grade 7/8 Math Circles November 3/4, 2015. M.C. Escher and Tessellations Faculty of Mathematics Waterloo, Ontario N2L 3G1 Centre for Education in Mathematics and Computing Tiling the Plane Grade 7/8 Math Circles November 3/4, 2015 M.C. Escher and Tessellations Do the following

More information

Cabri Geometry Application User Guide

Cabri Geometry Application User Guide Cabri Geometry Application User Guide Preview of Geometry... 2 Learning the Basics... 3 Managing File Operations... 12 Setting Application Preferences... 14 Selecting and Moving Objects... 17 Deleting

More information

Euler s Method and Functions

Euler s Method and Functions Chapter 3 Euler s Method and Functions The simplest method for approximately solving a differential equation is Euler s method. One starts with a particular initial value problem of the form dx dt = f(t,

More information

1 bool operator==(complex a, Complex b) { 2 return a.real()==b.real() 3 && a.imag()==b.imag(); 4 } 1 bool Complex::operator==(Complex b) {

1 bool operator==(complex a, Complex b) { 2 return a.real()==b.real() 3 && a.imag()==b.imag(); 4 } 1 bool Complex::operator==(Complex b) { Operators C and C++ 6. Operators Inheritance Virtual Alastair R. Beresford University of Cambridge Lent Term 2008 C++ allows the programmer to overload the built-in operators For example, a new test for

More information

2.2 Derivative as a Function

2.2 Derivative as a Function 2.2 Derivative as a Function Recall that we defined the derivative as f (a) = lim h 0 f(a + h) f(a) h But since a is really just an arbitrary number that represents an x-value, why don t we just use x

More information

The Method of Least Squares. Lectures INF2320 p. 1/80

The Method of Least Squares. Lectures INF2320 p. 1/80 The Method of Least Squares Lectures INF2320 p. 1/80 Lectures INF2320 p. 2/80 The method of least squares We study the following problem: Given n points (t i,y i ) for i = 1,...,n in the (t,y)-plane. How

More information

Linear Programming Problems

Linear Programming Problems Linear Programming Problems Linear programming problems come up in many applications. In a linear programming problem, we have a function, called the objective function, which depends linearly on a number

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1 The Java Series Java Essentials I What is Java? Basic Language Constructs Slide 1 What is Java? A general purpose Object Oriented programming language. Created by Sun Microsystems. It s a general purpose

More information

DERIVATIVES AS MATRICES; CHAIN RULE

DERIVATIVES AS MATRICES; CHAIN RULE DERIVATIVES AS MATRICES; CHAIN RULE 1. Derivatives of Real-valued Functions Let s first consider functions f : R 2 R. Recall that if the partial derivatives of f exist at the point (x 0, y 0 ), then we

More information

What are the place values to the left of the decimal point and their associated powers of ten?

What are the place values to the left of the decimal point and their associated powers of ten? The verbal answers to all of the following questions should be memorized before completion of algebra. Answers that are not memorized will hinder your ability to succeed in geometry and algebra. (Everything

More information

Parametric Curves. (Com S 477/577 Notes) Yan-Bin Jia. Oct 8, 2015

Parametric Curves. (Com S 477/577 Notes) Yan-Bin Jia. Oct 8, 2015 Parametric Curves (Com S 477/577 Notes) Yan-Bin Jia Oct 8, 2015 1 Introduction A curve in R 2 (or R 3 ) is a differentiable function α : [a,b] R 2 (or R 3 ). The initial point is α[a] and the final point

More information

Absolute Value Equations and Inequalities

Absolute Value Equations and Inequalities . Absolute Value Equations and Inequalities. OBJECTIVES 1. Solve an absolute value equation in one variable. Solve an absolute value inequality in one variable NOTE Technically we mean the distance between

More information

= δx x + δy y. df ds = dx. ds y + xdy ds. Now multiply by ds to get the form of the equation in terms of differentials: df = y dx + x dy.

= δx x + δy y. df ds = dx. ds y + xdy ds. Now multiply by ds to get the form of the equation in terms of differentials: df = y dx + x dy. ERROR PROPAGATION For sums, differences, products, and quotients, propagation of errors is done as follows. (These formulas can easily be calculated using calculus, using the differential as the associated

More information

IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction

IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction IS0020 Program Design and Software Tools Midterm, Feb 24, 2004 Name: Instruction There are two parts in this test. The first part contains 50 questions worth 80 points. The second part constitutes 20 points

More information

Core Maths C1. Revision Notes

Core Maths C1. Revision Notes Core Maths C Revision Notes November 0 Core Maths C Algebra... Indices... Rules of indices... Surds... 4 Simplifying surds... 4 Rationalising the denominator... 4 Quadratic functions... 4 Completing the

More information

Solutions to Homework 10

Solutions to Homework 10 Solutions to Homework 1 Section 7., exercise # 1 (b,d): (b) Compute the value of R f dv, where f(x, y) = y/x and R = [1, 3] [, 4]. Solution: Since f is continuous over R, f is integrable over R. Let x

More information

7.6 Approximation Errors and Simpson's Rule

7.6 Approximation Errors and Simpson's Rule WileyPLUS: Home Help Contact us Logout Hughes-Hallett, Calculus: Single and Multivariable, 4/e Calculus I, II, and Vector Calculus Reading content Integration 7.1. Integration by Substitution 7.2. Integration

More information

www.sahajsolns.com Chapter 4 OOPS WITH C++ Sahaj Computer Solutions

www.sahajsolns.com Chapter 4 OOPS WITH C++ Sahaj Computer Solutions Chapter 4 OOPS WITH C++ Sahaj Computer Solutions 1 Session Objectives Classes and Objects Class Declaration Class Members Data Constructors Destructors Member Functions Class Member Visibility Private,

More information

Area and Arc Length in Polar Coordinates

Area and Arc Length in Polar Coordinates Area and Arc Length in Polar Coordinates The Cartesian Coordinate System (rectangular coordinates) is not always the most convenient way to describe points, or relations in the plane. There are certainly

More information

Definition: A vector is a directed line segment that has and. Each vector has an initial point and a terminal point.

Definition: A vector is a directed line segment that has and. Each vector has an initial point and a terminal point. 6.1 Vectors in the Plane PreCalculus 6.1 VECTORS IN THE PLANE Learning Targets: 1. Find the component form and the magnitude of a vector.. Perform addition and scalar multiplication of two vectors. 3.

More information

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship. CSCI 253 Object Oriented Design: Java Review OOP George Blankenship George Blankenship 1 Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation Abstract Data Type (ADT) Implementation

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

Chapter 10. Key Ideas Correlation, Correlation Coefficient (r),

Chapter 10. Key Ideas Correlation, Correlation Coefficient (r), Chapter 0 Key Ideas Correlation, Correlation Coefficient (r), Section 0-: Overview We have already explored the basics of describing single variable data sets. However, when two quantitative variables

More information

Nonlinear Algebraic Equations. Lectures INF2320 p. 1/88

Nonlinear Algebraic Equations. Lectures INF2320 p. 1/88 Nonlinear Algebraic Equations Lectures INF2320 p. 1/88 Lectures INF2320 p. 2/88 Nonlinear algebraic equations When solving the system u (t) = g(u), u(0) = u 0, (1) with an implicit Euler scheme we have

More information

Brent A. Perdue. July 15, 2009

Brent A. Perdue. July 15, 2009 Title Page Object-Oriented Programming, Writing Classes, and Creating Libraries and Applications Brent A. Perdue ROOT @ TUNL July 15, 2009 B. A. Perdue (TUNL) OOP, Classes, Libraries, Applications July

More information

Data Structures Using C++ 2E. Chapter 5 Linked Lists

Data Structures Using C++ 2E. Chapter 5 Linked Lists Data Structures Using C++ 2E Chapter 5 Linked Lists Test #1 Next Thursday During Class Cover through (near?) end of Chapter 5 Objectives Learn about linked lists Become aware of the basic properties of

More information

Glossary of Object Oriented Terms

Glossary of Object Oriented Terms Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction

More information

Chapter 7: Additional Topics

Chapter 7: Additional Topics Chapter 7: Additional Topics In this chapter we ll briefly cover selected advanced topics in fortran programming. All the topics come in handy to add extra functionality to programs, but the feature you

More information

1.7 Graphs of Functions

1.7 Graphs of Functions 64 Relations and Functions 1.7 Graphs of Functions In Section 1.4 we defined a function as a special type of relation; one in which each x-coordinate was matched with only one y-coordinate. We spent most

More information

Multi-variable Calculus and Optimization

Multi-variable Calculus and Optimization Multi-variable Calculus and Optimization Dudley Cooke Trinity College Dublin Dudley Cooke (Trinity College Dublin) Multi-variable Calculus and Optimization 1 / 51 EC2040 Topic 3 - Multi-variable Calculus

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

Chapter One Introduction to Programming

Chapter One Introduction to Programming Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

More information

Linear Algebra Notes for Marsden and Tromba Vector Calculus

Linear Algebra Notes for Marsden and Tromba Vector Calculus Linear Algebra Notes for Marsden and Tromba Vector Calculus n-dimensional Euclidean Space and Matrices Definition of n space As was learned in Math b, a point in Euclidean three space can be thought of

More information

Generating Serialisation Code with Clang

Generating Serialisation Code with Clang EURO-LLVM CONFERENCE 12 th April 2012 Wayne Palmer Generating Serialisation Code with Clang 1 INTRODUCTION TO THE QUANTITATIVE ANALYTICS LIBRARY A single C++ library of nearly 10 million lines of code.

More information

LINEAR INEQUALITIES. Mathematics is the art of saying many things in many different ways. MAXWELL

LINEAR INEQUALITIES. Mathematics is the art of saying many things in many different ways. MAXWELL Chapter 6 LINEAR INEQUALITIES 6.1 Introduction Mathematics is the art of saying many things in many different ways. MAXWELL In earlier classes, we have studied equations in one variable and two variables

More information

Common Data Structures

Common Data Structures Data Structures 1 Common Data Structures Arrays (single and multiple dimensional) Linked Lists Stacks Queues Trees Graphs You should already be familiar with arrays, so they will not be discussed. Trees

More information

Datum > Curve KIM,ME,NIU

Datum > Curve KIM,ME,NIU Datum > Curve Intersect First create at least one quilt on the surface of the model. Feature > Surface (> New) > Copy (do not use offset that creates a surface off the solid surface even with zero offset)

More information

Chapter 7 - Roots, Radicals, and Complex Numbers

Chapter 7 - Roots, Radicals, and Complex Numbers Math 233 - Spring 2009 Chapter 7 - Roots, Radicals, and Complex Numbers 7.1 Roots and Radicals 7.1.1 Notation and Terminology In the expression x the is called the radical sign. The expression under the

More information

Number Sense and Operations

Number Sense and Operations Number Sense and Operations representing as they: 6.N.1 6.N.2 6.N.3 6.N.4 6.N.5 6.N.6 6.N.7 6.N.8 6.N.9 6.N.10 6.N.11 6.N.12 6.N.13. 6.N.14 6.N.15 Demonstrate an understanding of positive integer exponents

More information

G. GRAPHING FUNCTIONS

G. GRAPHING FUNCTIONS G. GRAPHING FUNCTIONS To get a quick insight int o how the graph of a function looks, it is very helpful to know how certain simple operations on the graph are related to the way the function epression

More information

EQUATIONS and INEQUALITIES

EQUATIONS and INEQUALITIES EQUATIONS and INEQUALITIES Linear Equations and Slope 1. Slope a. Calculate the slope of a line given two points b. Calculate the slope of a line parallel to a given line. c. Calculate the slope of a line

More information

2) Write in detail the issues in the design of code generator.

2) Write in detail the issues in the design of code generator. COMPUTER SCIENCE AND ENGINEERING VI SEM CSE Principles of Compiler Design Unit-IV Question and answers UNIT IV CODE GENERATION 9 Issues in the design of code generator The target machine Runtime Storage

More information

3 Contour integrals and Cauchy s Theorem

3 Contour integrals and Cauchy s Theorem 3 ontour integrals and auchy s Theorem 3. Line integrals of complex functions Our goal here will be to discuss integration of complex functions = u + iv, with particular regard to analytic functions. Of

More information

The programming language C. sws1 1

The programming language C. sws1 1 The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan

More information

Trigonometric Functions and Triangles

Trigonometric Functions and Triangles Trigonometric Functions and Triangles Dr. Philippe B. Laval Kennesaw STate University August 27, 2010 Abstract This handout defines the trigonometric function of angles and discusses the relationship between

More information

Illustration 1: Diagram of program function and data flow

Illustration 1: Diagram of program function and data flow The contract called for creation of a random access database of plumbing shops within the near perimeter of FIU Engineering school. The database features a rating number from 1-10 to offer a guideline

More information

To give it a definition, an implicit function of x and y is simply any relationship that takes the form:

To give it a definition, an implicit function of x and y is simply any relationship that takes the form: 2 Implicit function theorems and applications 21 Implicit functions The implicit function theorem is one of the most useful single tools you ll meet this year After a while, it will be second nature to

More information

Circle Name: Radius: Diameter: Chord: Secant:

Circle Name: Radius: Diameter: Chord: Secant: 12.1: Tangent Lines Congruent Circles: circles that have the same radius length Diagram of Examples Center of Circle: Circle Name: Radius: Diameter: Chord: Secant: Tangent to A Circle: a line in the plane

More information

Java CPD (I) Frans Coenen Department of Computer Science

Java CPD (I) Frans Coenen Department of Computer Science Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials

More information

Symbol Tables. Introduction

Symbol Tables. Introduction Symbol Tables Introduction A compiler needs to collect and use information about the names appearing in the source program. This information is entered into a data structure called a symbol table. The

More information

17. Friendship and Inheritance

17. Friendship and Inheritance - 117 - Object Oriented Programming: 17. Friendship and Inheritance Friend functions In principle, private and protected members of a class cannot be accessed from outside the same class in which they

More information

Scalar Valued Functions of Several Variables; the Gradient Vector

Scalar Valued Functions of Several Variables; the Gradient Vector Scalar Valued Functions of Several Variables; the Gradient Vector Scalar Valued Functions vector valued function of n variables: Let us consider a scalar (i.e., numerical, rather than y = φ(x = φ(x 1,

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

1. Relational database accesses data in a sequential form. (Figures 7.1, 7.2)

1. Relational database accesses data in a sequential form. (Figures 7.1, 7.2) Chapter 7 Data Structures for Computer Graphics (This chapter was written for programmers - option in lecture course) Any computer model of an Object must comprise three different types of entities: 1.

More information

Geometric Transformations

Geometric Transformations Geometric Transformations Definitions Def: f is a mapping (function) of a set A into a set B if for every element a of A there exists a unique element b of B that is paired with a; this pairing is denoted

More information

10CS35: Data Structures Using C

10CS35: Data Structures Using C CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions - a conventional tool for handling a

More information

Understanding Basic Calculus

Understanding Basic Calculus Understanding Basic Calculus S.K. Chung Dedicated to all the people who have helped me in my life. i Preface This book is a revised and expanded version of the lecture notes for Basic Calculus and other

More information

Course Title: Software Development

Course Title: Software Development Course Title: Software Development Unit: Customer Service Content Standard(s) and Depth of 1. Analyze customer software needs and system requirements to design an information technology-based project plan.

More information

http://school-maths.com Gerrit Stols

http://school-maths.com Gerrit Stols For more info and downloads go to: http://school-maths.com Gerrit Stols Acknowledgements GeoGebra is dynamic mathematics open source (free) software for learning and teaching mathematics in schools. It

More information

GeoGebra. 10 lessons. Gerrit Stols

GeoGebra. 10 lessons. Gerrit Stols GeoGebra in 10 lessons Gerrit Stols Acknowledgements GeoGebra is dynamic mathematics open source (free) software for learning and teaching mathematics in schools. It was developed by Markus Hohenwarter

More information

Compiler Construction

Compiler Construction Compiler Construction Lecture 1 - An Overview 2003 Robert M. Siegfried All rights reserved A few basic definitions Translate - v, a.to turn into one s own language or another. b. to transform or turn from

More information

the points are called control points approximating curve

the points are called control points approximating curve Chapter 4 Spline Curves A spline curve is a mathematical representation for which it is easy to build an interface that will allow a user to design and control the shape of complex curves and surfaces.

More information

Beginner s Matlab Tutorial

Beginner s Matlab Tutorial Christopher Lum lum@u.washington.edu Introduction Beginner s Matlab Tutorial This document is designed to act as a tutorial for an individual who has had no prior experience with Matlab. For any questions

More information

Homework 2 Solutions

Homework 2 Solutions Homework Solutions 1. (a) Find the area of a regular heagon inscribed in a circle of radius 1. Then, find the area of a regular heagon circumscribed about a circle of radius 1. Use these calculations to

More information

C++ Programming Language

C++ Programming Language C++ Programming Language Lecturer: Yuri Nefedov 7th and 8th semesters Lectures: 34 hours (7th semester); 32 hours (8th semester). Seminars: 34 hours (7th semester); 32 hours (8th semester). Course abstract

More information

9.4. The Scalar Product. Introduction. Prerequisites. Learning Style. Learning Outcomes

9.4. The Scalar Product. Introduction. Prerequisites. Learning Style. Learning Outcomes The Scalar Product 9.4 Introduction There are two kinds of multiplication involving vectors. The first is known as the scalar product or dot product. This is so-called because when the scalar product of

More information

Vector storage and access; algorithms in GIS. This is lecture 6

Vector storage and access; algorithms in GIS. This is lecture 6 Vector storage and access; algorithms in GIS This is lecture 6 Vector data storage and access Vectors are built from points, line and areas. (x,y) Surface: (x,y,z) Vector data access Access to vector

More information

39 Symmetry of Plane Figures

39 Symmetry of Plane Figures 39 Symmetry of Plane Figures In this section, we are interested in the symmetric properties of plane figures. By a symmetry of a plane figure we mean a motion of the plane that moves the figure so that

More information

1 if 1 x 0 1 if 0 x 1

1 if 1 x 0 1 if 0 x 1 Chapter 3 Continuity In this chapter we begin by defining the fundamental notion of continuity for real valued functions of a single real variable. When trying to decide whether a given function is or

More information

Algebra I Notes Relations and Functions Unit 03a

Algebra I Notes Relations and Functions Unit 03a OBJECTIVES: F.IF.A.1 Understand the concept of a function and use function notation. Understand that a function from one set (called the domain) to another set (called the range) assigns to each element

More information

1 Abstract Data Types Information Hiding

1 Abstract Data Types Information Hiding 1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content

More information

2008 AP Calculus AB Multiple Choice Exam

2008 AP Calculus AB Multiple Choice Exam 008 AP Multiple Choice Eam Name 008 AP Calculus AB Multiple Choice Eam Section No Calculator Active AP Calculus 008 Multiple Choice 008 AP Calculus AB Multiple Choice Eam Section Calculator Active AP Calculus

More information

Chapter 5 Functions. Introducing Functions

Chapter 5 Functions. Introducing Functions Chapter 5 Functions 1 Introducing Functions A function is a collection of statements that are grouped together to perform an operation Define a function Invoke a funciton return value type method name

More information

Using Microsoft Word. Working With Objects

Using Microsoft Word. Working With Objects Using Microsoft Word Many Word documents will require elements that were created in programs other than Word, such as the picture to the right. Nontext elements in a document are referred to as Objects

More information

2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION

2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION 2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION A world-coordinate area selected for display is called a window. An area on a display device to which a window is mapped is called a viewport. The window

More information

Coding conventions and C++-style

Coding conventions and C++-style Chapter 1 Coding conventions and C++-style This document provides an overview of the general coding conventions that are used throughout oomph-lib. Knowledge of these conventions will greatly facilitate

More information

Note: Syntactically, a ; is needed at the end of a struct definition.

Note: Syntactically, a ; is needed at the end of a struct definition. Structs, Classes, and Arrays Structs A type representation containing a set of heterogeneous members with possibly varying types. struct Student { string name; int id; double tuition; ; Note: Syntactically,

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II C++ intro Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 26, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 26,

More information

What is a parabola? It is geometrically defined by a set of points or locus of points that are

What is a parabola? It is geometrically defined by a set of points or locus of points that are Section 6-1 A Parable about Parabolas Name: What is a parabola? It is geometrically defined by a set of points or locus of points that are equidistant from a point (the focus) and a line (the directrix).

More information