Wed Oct 30 00:00:04 2024
EVENTS
 FREE
SOFTWARE
INSTITUTE

POLITICS
JOBS
MEMBERS'
CORNER

MAILING
LIST

NYLXS Mailing Lists and Archives
NYLXS Members have a lot to say and share but we don't keep many secrets. Join the Hangout Mailing List and say your peice.

DATE 2008-07-01

HANGOUT

2024-10-30 | 2024-09-30 | 2024-08-30 | 2024-07-30 | 2024-06-30 | 2024-05-30 | 2024-04-30 | 2024-03-30 | 2024-02-29 | 2024-01-29 | 2023-12-29 | 2023-11-29 | 2023-10-29 | 2023-09-29 | 2023-08-29 | 2023-07-29 | 2023-06-29 | 2023-05-29 | 2023-04-29 | 2023-03-29 | 2023-02-28 | 2023-01-28 | 2022-12-28 | 2022-11-28 | 2022-10-28 | 2022-09-28 | 2022-08-28 | 2022-07-28 | 2022-06-28 | 2022-05-28 | 2022-04-28 | 2022-03-28 | 2022-02-28 | 2022-01-28 | 2021-12-28 | 2021-11-28 | 2021-10-28 | 2021-09-28 | 2021-08-28 | 2021-07-28 | 2021-06-28 | 2021-05-28 | 2021-04-28 | 2021-03-28 | 2021-02-28 | 2021-01-28 | 2020-12-28 | 2020-11-28 | 2020-10-28 | 2020-09-28 | 2020-08-28 | 2020-07-28 | 2020-06-28 | 2020-05-28 | 2020-04-28 | 2020-03-28 | 2020-02-28 | 2020-01-28 | 2019-12-28 | 2019-11-28 | 2019-10-28 | 2019-09-28 | 2019-08-28 | 2019-07-28 | 2019-06-28 | 2019-05-28 | 2019-04-28 | 2019-03-28 | 2019-02-28 | 2019-01-28 | 2018-12-28 | 2018-11-28 | 2018-10-28 | 2018-09-28 | 2018-08-28 | 2018-07-28 | 2018-06-28 | 2018-05-28 | 2018-04-28 | 2018-03-28 | 2018-02-28 | 2018-01-28 | 2017-12-28 | 2017-11-28 | 2017-10-28 | 2017-09-28 | 2017-08-28 | 2017-07-28 | 2017-06-28 | 2017-05-28 | 2017-04-28 | 2017-03-28 | 2017-02-28 | 2017-01-28 | 2016-12-28 | 2016-11-28 | 2016-10-28 | 2016-09-28 | 2016-08-28 | 2016-07-28 | 2016-06-28 | 2016-05-28 | 2016-04-28 | 2016-03-28 | 2016-02-28 | 2016-01-28 | 2015-12-28 | 2015-11-28 | 2015-10-28 | 2015-09-28 | 2015-08-28 | 2015-07-28 | 2015-06-28 | 2015-05-28 | 2015-04-28 | 2015-03-28 | 2015-02-28 | 2015-01-28 | 2014-12-28 | 2014-11-28 | 2014-10-28 | 2014-09-28 | 2014-08-28 | 2014-07-28 | 2014-06-28 | 2014-05-28 | 2014-04-28 | 2014-03-28 | 2014-02-28 | 2014-01-28 | 2013-12-28 | 2013-11-28 | 2013-10-28 | 2013-09-28 | 2013-08-28 | 2013-07-28 | 2013-06-28 | 2013-05-28 | 2013-04-28 | 2013-03-28 | 2013-02-28 | 2013-01-28 | 2012-12-28 | 2012-11-28 | 2012-10-28 | 2012-09-28 | 2012-08-28 | 2012-07-28 | 2012-06-28 | 2012-05-28 | 2012-04-28 | 2012-03-28 | 2012-02-28 | 2012-01-28 | 2011-12-28 | 2011-11-28 | 2011-10-28 | 2011-09-28 | 2011-08-28 | 2011-07-28 | 2011-06-28 | 2011-05-28 | 2011-04-28 | 2011-03-28 | 2011-02-28 | 2011-01-28 | 2010-12-28 | 2010-11-28 | 2010-10-28 | 2010-09-28 | 2010-08-28 | 2010-07-28 | 2010-06-28 | 2010-05-28 | 2010-04-28 | 2010-03-28 | 2010-02-28 | 2010-01-28 | 2009-12-28 | 2009-11-28 | 2009-10-28 | 2009-09-28 | 2009-08-28 | 2009-07-28 | 2009-06-28 | 2009-05-28 | 2009-04-28 | 2009-03-28 | 2009-02-28 | 2009-01-28 | 2008-12-28 | 2008-11-28 | 2008-10-28 | 2008-09-28 | 2008-08-28 | 2008-07-28 | 2008-06-28 | 2008-05-28 | 2008-04-28 | 2008-03-28 | 2008-02-28 | 2008-01-28 | 2007-12-28 | 2007-11-28 | 2007-10-28 | 2007-09-28 | 2007-08-28 | 2007-07-28 | 2007-06-28 | 2007-05-28 | 2007-04-28 | 2007-03-28 | 2007-02-28 | 2007-01-28 | 2006-12-28 | 2006-11-28 | 2006-10-28 | 2006-09-28 | 2006-08-28 | 2006-07-28 | 2006-06-28 | 2006-05-28 | 2006-04-28 | 2006-03-28 | 2006-02-28 | 2006-01-28 | 2005-12-28 | 2005-11-28 | 2005-10-28 | 2005-09-28 | 2005-08-28 | 2005-07-28 | 2005-06-28 | 2005-05-28 | 2005-04-28 | 2005-03-28 | 2005-02-28 | 2005-01-28 | 2004-12-28 | 2004-11-28 | 2004-10-28 | 2004-09-28 | 2004-08-28 | 2004-07-28 | 2004-06-28 | 2004-05-28 | 2004-04-28 | 2004-03-28 | 2004-02-28 | 2004-01-28 | 2003-12-28 | 2003-11-28 | 2003-10-28 | 2003-09-28 | 2003-08-28 | 2003-07-28 | 2003-06-28 | 2003-05-28 | 2003-04-28 | 2003-03-28 | 2003-02-28 | 2003-01-28 | 2002-12-28 | 2002-11-28 | 2002-10-28 | 2002-09-28 | 2002-08-28 | 2002-07-28 | 2002-06-28 | 2002-05-28 | 2002-04-28 | 2002-03-28 | 2002-02-28 | 2002-01-28 | 2001-12-28 | 2001-11-28 | 2001-10-28 | 2001-09-28 | 2001-08-28 | 2001-07-28 | 2001-06-28 | 2001-05-28 | 2001-04-28 | 2001-03-28 | 2001-02-28 | 2001-01-28 | 2000-12-28 | 2000-11-28 | 2000-10-28 | 2000-09-28 | 2000-08-28 | 2000-07-28 | 2000-06-28 | 2000-05-28 | 2000-04-28 | 2000-03-28 | 2000-02-28 | 2000-01-28 | 1999-12-28

Key: Value:

Key: Value:

MESSAGE
DATE 2008-07-22
FROM Ruben Safir
SUBJECT Subject: [NYLXS - HANGOUT] C++ Workshop 2.2.3
THis might repeat soewhat because I've been writing this in my work processor but.. here is the next entry including the code for the test environment for
C++. The code on the end compiles without complaints from g++ but
I don't vouch for it yet. Try it out and feel free to point out my mistakes

C++ Workshop II

The next chapter of the C++ book gives a whirlwind tour of the basics
of the C++ syntax that are necessary for object oriented programming.
This section is almost like jumping into the pool and hope you get
acclimated to the water. C++ is not a good language for a beginner,
and this section makes it clear why. To really get a handle on this
section without prior programing experience is a very tall order.

In parsing this chapter, keep a few things in mind. Much of the code
snippets given as an example in this section would be written outside of
your main program, as library files and header files. While we discussed
the preprocessor directive previously in both the C and C++ workshops,
we hadn't looked at them in detail. For those not familiar with these
construction, which are core to C programing, a few words are in order
about them.

There are two different external file types that your compiler uses to
build your program, aside from the file that your main program code is
stored in. They are called header files or libraries. Most normally,
there is a header file for each library. They also share part of their
name according to a naming convention. Standardized libraries, such
as iostream have header files. The libraries can be static or shared.
Either type is unlinked C bitcode, or objects files in C language
parlance. A group of object files archived together, usually with the
'ar' program, form these libraries. Thee files normally exist in
/usr/lib or /lib and might have a suffix of '.so'. It is sometimes
necessary to compile a program with the -I option to tell the compiler
to include a library, even though the preprocessor include line is
designating the header file. Usually if the header file is math.h then
the library is libmath.

Declaration of variable types, function names, and preprocessor constants
which apply to the library files are header files. These are what
is referred to within your program, such as or .
In C these are .h files such as /usr/include/strings.h. In C++ they
might not, as in /usr/include/g++/iostream. Take a peek and look at
some of your header files. Becoming familiar with their syntax will
greatly improve your hacking skills.


The reason to discuss this, and we should really talk even more about
this, is that the examples in the C++ text implicitly and explicitly
imply that the code being written is for library objects, and written in
external files. When we discuss making classes, the most logical place to
make a new class is in an external file, compiled to an C object for use
later by someone else's program. Calling class objects is not a problem.
A simple explanation of the “new” keyword and type defining the class
structures puts you on your way. But once we discuss Constructors,
Destructors, data hiding, public interface design, private data and
implementation design, operator overloading, and function overloading
and polymorphism, then we are talking writing modules for others to use,
or even for us to use concurrently to the main code we are writing.

Section 2.1 is a big section which walks through much of the C++ basic
design, and I will go over it piece by piece over the next couple of days.



In organizing the concepts of C++ which are being introduced we can view each of them separately, but studying them it is essential to keep in mind that they are designed to function together in the construction of programs which are easier to debug, which allow for cleaner overall syntax, and which encourage creation of reusable code.

We shall explore:

Data Types (build in and user created)

Pointers and References (and their subtle deference)

Manual Memory Allocation and the 'new' and delete keywords

Class Declaration

Class Definition

Private data

Public data

Object instantiation and access, Class typedef

Class Constructors

Class Destructor

Function or Method Overloading

Operator Overloading

External extension of definitions

Copy Constructors

at the end we'll try to actually make the example class, which is an extended array.


1) Data Types: DATA DATA DATA, everything is DATA

As we know, C and C++ have built in data type which each variable and object the language needs to be defined as. Both C and C++ are typed language.

We have char, int, double, float, pointer, and so on, a complete list of which is available around the net. A pointer stores an address of another C++ object. Different hardware and software platforms also have different sizes that it allocates for these data types, creating an inconsistency which, as an aside, the Free Software community has tried to address with the creation of the glib library, part of the GTK project.

What is less apparent is that with regard to a computer, everything is data. We have the data that we create and manipulated with instructions, but the instructions themselves are a form data which we can package up and save for later use, and feed to the CPU at will. When the CPU runs out instructions the resulting actions are further instructions that can be packaged and saved as data. In a word, everything is data, and how we package that data is what separates one programming language from the next.

This concept is covered extensively in NYLXS “Introduction Programming with Perl” class and since this is an advanced topic, we won't get much further into this. But we will review the basics of data types and then look at the new feature that C++ gives which C didn't have in such a generous way, the ability to easily create new data types easily and in a reusable fashion.

An integer in the C family on the 32 bit Intel clone architecture is defined as a marked space in memory of 32 bits in size to represent both positive and negitive numbers. On the new 64 bit architecture that many of you might have, I don't know if this still holds true since the word size of a those machines is 64 bits or 8 bytes.

when you use the declaration

int a = 3456;

The computer your program sets aside 32 bits, 4 bytes, of space in ram and puts the binary representation of that value in that space. The leftmost bit is usually the signed bit determining whether the number represented within is either positive or negative. A signed integer can therefor have a maximum value of 2,147,483,647 positive or negative. beyond that you must use a long int, which on 32 bit architecture actually won't help you, or to use external libraries with other data types defined.

By default, C allows certain syntax with a data type. It will automatically translate it, for example, into a char that will print its representation for functions such as printf or in C++ the cout object:

printf (“%d\n”, myint);
cout << myint;

It can be combined with operators
it can be used with the assignment operator to fill or initialize its space with data.

int myans,myx = 6,myy =12;

It can be combined with arithmetic operators and have results assigned accordingly.

myans = myy + myx;

Two of them can be compared.

while (myy < myx){
...
...
}

They can be auto incremented

myy++;
++myy;

and so on....

One data type is actually a serial arraignment of data, that is an array.

int myarray[100];

This defines an array of 100 elements indexed from zero to one hundred.

myy = myarray[4];

assigns the fifth element of our array to our integer variable myy. One thing you can not do with an array data type is use an assignment operator on the entire array object.

myarray[] = myarray2[]; //THIS IS AN ERROR

C++ allows up to define our own data types that have all the properties of the built in ones. It uses the class mechanize, operator overloading, and the “new” keyword to accomplish this.


2) Pointers and References – Where did I PUT THAT!

When we create data for our program, we ask the program to insert memory
into RAM and to retrieve or assign the data from that memory location
for use. Internally the program keeps track of the symbols and the
memory locations. In fact is you run the program “nm” on a C or C++
binary it will tell you all the symbols that it has in that binary.

ruben-at-www2:~/cplus> nm file3|less

0804a210 A __bss_start
08048a84 t call_gmon_start
0804a29c b completed.1
0804a0bc d __CTOR_END__
0804a0b4 d __CTOR_LIST__
U __cxa_atexit-at--at-GLIBC_2.1.3
0804a204 D __data_start
0804a204 W data_start
08048ed0 t __do_global_ctors_aux
08048ab0 t __do_global_dtors_aux
0804a208 D __dso_handle
......


But we can also create memory locations that are assignable, and store
a representation of that memory location directly into a variable that
only stores the memory location as data, not the data itself. In c
and C++ this is called pointers and we can use the following syntax to
create them.

int *pt = &myint;

This declares the pointer to an int variable called pt which stores the
address for myint. The syntax int * in a declaration (and ONLY in a
declaration) says make a pointer to an int. The & syntax in front of a
variable myint says don't return the value of the variable, but return
the address of the data stored in the variable itself.

There are functions that return only pointer data. Those functions make
it possible to access memory without the declaration of variables at all.
There are also declarations that can be made in C and C++ which can
create variables without variable names either.




int (*pt)[10];

This declares a pointer (pt) to an array of 10 integers.

char (*p)[10][100]

This is a pointer which addresses an array of 10 pointers (implied)
to arrays of 100 chars each. Commonly this is know as a point to an
array of 10 strings. The symbolic variable name for an array often
gets automatically cast as a point type.

Most string functions in C return a char pointer for example

char * strtok(char *s1, const char *s2);

This would return an address of a char, which in theory would represent
an array of chars. In use it would look like this


char * spt;
char wd1[100] = 'hello world', wd2[100] = ' ';

spt = strtok(wd1,wd2);
printf(“%s\n”, spt);





3) Manual Memory Allocation and the 'new' and delete keywords

C++ makes it very convent to create dynamically allocated memory which
is accessed by pointers. We might call these anonymous pointers because
they do not point to any variables, just defined memory. We do this
with the key word “new”.

int *pt = new int(124);

This creates a new int pointer called pt and assigns to the memory
pointed to by pt with the integer value 124.

delete pt;


deletes the anonymous pointer pt.

int *pt = new int[100];

This declaration creates a new int pointer to an array of 100 integers,
with no data assigned yet to that block of memory.

delete [] pt;

deletes the entire array pointed to by pt and then undefines pt.




4) Class Declaration – Type Type Type

When using C++ one of the key reasons for choosing this language involves
our ability to roll our own data types. While with C programming we
can use typedef with unions and structures, the class system with C++ is
much ore extensive and flexible, giving genuine data type ability to the
programmer, a flexibility previously reserved for the elite programmers
who could hack the core C programming interface, probably involving a
bit of assembly to boot.

The first thing you need to do when making a class is to declare it,
similarly to how one needs to declare a function. Declaring the class
alerts the compiler of the new symbols that will be used in further code.
The declaration does not include the definition. that can be done later.
All of this most commonly takes place in an external file so that it
can be reused, or even a .h header file.

class IntArray;
once we make this declaration, we can declare objects of this class as
we could with any other data type

IntArray array_object;

or even declare pointers to it such as:

IntArray *pt_array_obj = new IntArray;

After declaring the class itself, we need to now declare the internals
of our class, or its body.

class IntArray{
public:
bool operator==(const IntArray&) const; //This is a declaration
bool operator=!(const IntArray&) const; //This is a declaration

bool operator=(const IntArray&); //This is a declaration
int size() const; //This is a declaration
void sort(); //This is a declaration
int min() const; //these are all declarations
int max() const;
int find() const;

private:
//nothing yet
}

All this is so that later we can use the IntArray as a data type

IntArray myarray;

and we can then use the IntArray objects as any other variable

myarray[] = a[];

Then we can use the
Class Definition dot syntax to gain access to the public interface

myint = myarray.size();

or if we use a pointer as follows

IntArray * parray = new IntArray;

myint = parray->size();



5) Class Definition:

Once we declare the class type by also declaring the internals and externals of a class, and by using the keywords 'class', 'public:' and 'private:' we need to define the class its qelf, or essentially code the class. All the methods that we declared now need to be coded, either either as 'inline' methods or normal methods. For the purposes of object oriented languages like C++, methods are a subclass of functions, like functions in every way accept scoped to class objects. Inline functions are quick jobs that can be simply defined and which the compiler can replace at the call point, reducing the number of times the code has to be loaded, interpreted and run in our program, all of which is overhead of normal function or method calls. Functions that are used to access basic data which is otherwise private in a class are ideally suited for inline functions. Methods defined in classes are automatically attempted by the compiler to be compiled inline.

Lets look at the example that the text is using to give us a tour of C++. The text is trying to create an object which wraps the common C type integer array in order to give it more flexibility and features. A common beginners error in C programming is the attempt to assign one array to another array with code simlar to this

a[] = b[]; //ERROR

This is particulary common when working with strings, which are char arrays

char quote[255] = “A society which can not archive, can not share digital materials can not remain politically Free in the digital era”; //legal as an assignment;

char quote2[255];

quote2 = quote; //ERROR

If we wrap arrays in a new class, creating a new data type, we might first declare it as above, preferably in a header file:

class IntArray;

Now we declare the classes members, defining the internals of the class. Unlike functions (but like C structs) we need to end the body of a class definition with a semi-colon.

We define both public and private components of our class. the public section is the API that we are building. The private area is the internal machination of the class. The inner machinery that the programmer using our class doesn't need to become confused with.




#ifndef TOP
#include
#endif
#ifndef INTARRAY_H
#define INTARRAY_H
#endif

class IntArray{

public:
static
//constructors
explicit IntArray(int size = DefaultArraySize);
IntArray( int *array, int array_size);
IntArray(const IntArray &rhs);

//destructor

~IntArray(){ delete [] ia };

//operators
bool operator==(cont IntArray&);
bool operator!=(const IntArray&);

//assignment operator
IntArray operator=(const Intarray&);

int size() const;
void sort();
int min() const;
int max() const;
int find( int value) const;



private:
static const int DefaultArraySize = 255;
int _size;
int *ia;
}; //remember the colon


This defined Class has several declared methods, which can later be defined. The
purposes of these methods can be classified and we will be looking more closely at them in the coming sections.

6) Private Data

Much of the internal work your class does, and the data it keeps track of is the domain of the class objects, and which have what is commonly know as no consumer usable parts within. These internal segments of your object code are best hidden from the users space, and is safer for the user not to monkey with. This data is designated by the private tag, and this technique is called information hiding. In our example we have only two data items which are no accessible to the user directly, int _size and int * ia .

private:

int _size;
int *ia;

Our job is to do the accounting of out objects size and the int array which we are wrapping in our objects. So direct access doesn't make much sense. We access these data's in a variety of ways which we will build examples of, mostly through a well documented public interface.

7) Public data

The public interface is, at least in our example, more complicated. We will need accessory methods, methods to gain access to otherwise private data, and we will need constructors, destructors, operator overload methods, and copy method. We've declared a few of these already in our class definition, but we haven yet defined the methods themselves. Our public interface is the application interface we are building for our new data type. Special attention needs to be given to the planning of this interface if you expect wide adoption of the class.

At this point, a good example program is needed. While I'm not that masterful with language, and the texts are as clear as mud on many issues, the following has been put together in an effort to create a working sample C++ program for us to work with.

Our C++ program is in three files which are located on the NYLXS site and posted here for convince.


http://www.nylxs.com/docs/workshops/intarray.h.html

1 #ifndef INTARRAY_H
2 #define INTARRAY_H
3 #endif
4
5 using namespace std;
6
7 class IntArray;
8
9
10 class IntArray{
11
12 public:
13 //constructors
14 //explicit IntArray(int size = DefaultArraySize);
15 IntArray();
16 explicit IntArray(int);
17 IntArray( int *array, int array_size);
18 IntArray(const IntArray &rhs);
19
20 //destructor
21
22 ~IntArray(){ delete [] ia; };
23
24 //operators
25 bool operator==(const IntArray &);
26 bool operator!=(const IntArray &);
27 //assignment operator
28 IntArray& operator=(const IntArray &);
29 //index operator
30 int& operator[](int);
31
32 int size() const;
33 void sort();
34
35 int min() const;
36 int max() const;
37
38 int find( int value) const;
39
40
41
42 private:
43 static const int DefaultArraySize = 255;
44 int _size;
45 int *ia;
46 }; //remember the colon
47
48
This is the example header file

http://www.nylxs.com/docs/workshops/file4.C.html


1 #ifndef TOP_H
2 #define TOP_H
3 #include
4 #include
5 #endif
6 #ifndef INTARRAY_H
7 #include "intarray.h"
8 #define INTARRAY_H
9 #endif
10 using namespace std;
11 IntArray::
12 IntArray(){
13 _size = DefaultArraySize;
14 int * tmp;
15 ia = new int[_size];
16 for (tmp = ia; tmp < (ia + _size); tmp++)
17 *tmp = 0;
18 }
19
20 IntArray::
21 IntArray( int sz ){
22 int * tmp;
23 if(sz < 0){
24 cerr << "Size must be greater than 0 and an integer\n";
25 exit (-1);
26 }
27
28 _size = sz;
29
30 ia = new int[sz];
31 for(tmp = ia; tmp < (ia + sz); tmp++)
32 *tmp = 0;
33 }
34
35 IntArray::
36 IntArray( int *tmp, int sz){
37
38 if(sz < 0){
39 cerr << "Size must be greater than 0 and an integer\n";
40 exit(-1);
41 }
42 _size = sz;
43 int * tmp2;
44 ia = new int[sz];
45 for(tmp2 = ia; tmp2 < (ia + sz); tmp2++,tmp++){
46 *tmp2 = *tmp;//copy tmp to ia
47 }
48 }
49
50 IntArray::
51 IntArray(const IntArray &rhs){
52 _size = rhs.size();
53 ia = new int[_size];
54 for(int i = 0; i < _size; i++){
55 ia[i] = rhs.ia[i];
56 }
57 }
58
59
60 //operators
61 bool
62 IntArray::
63 operator==(const IntArray &rh){
64 bool test;
65 int sz = size(), i;
66 if (sz == rh.size())
67 test = true;
68 else
69 return false;
70
71 for(i = 0; i < 0; i++){
72 if (ia[i] == rh.ia[i])
73 test = true;
74 else
75 return false;
76 }
77 return test;
78 }
79
80
81 int&
82 IntArray::
83 operator[](int index){
84 if (index < 0 || index > _size)
85 exit (-1);
86 return ia[index];
87 }
88 bool
89 IntArray::
90 operator!=(const IntArray &rh){
91 bool test;
92 int sz = size(), i;
93 if (sz != rh.size())
94 return test = true;
95
96 for(i = 0; i < 0; i++){
97 if (ia[i] != rh.ia[i])
98 return true;
99 else
100 test = false;
101 }
102 return test;
103 }
104
105 //assignment operator
106 IntArray&
107 IntArray::
108 operator=(const IntArray& rh){
109 int sz = rh.size(), *tmp, *tmp2;
110 delete [] ia;
111 int * ia = new int[sz];
112 tmp = ia;
113 for (tmp2 = rh.ia; tmp < (tmp + sz); tmp++){
114 tmp2++;
115 *tmp = *tmp2;
116 }
117 return *this;
118 }
119
120 inline int
121 IntArray::
122 size() const{
123 return _size;
124 }
125
126 void
127 IntArray::
128 sort(){
129 //good ole bubble sort
130 int *sorted, last, *index;
131
132 for(index = ia; index < (ia + _size); index++){
133 for(sorted = index; sorted < (ia + _size); sorted++){
134 last = *(sorted + 1);
135 if (*sorted > last){
136 //switch - pushing higher to back
137 last = *sorted;
138 *sorted = *(sorted + 1);
139 *(sorted + 1) = last;
140 }
141 }
142 }
143 }
144
145 int
146 IntArray::
147 min() const{
148 int low, *tmp = ia;
149 for(low = *tmp;tmp < (ia + _size); tmp++){
150 if (*tmp < low)
151 low = *tmp;
152 }
153
154 return low;
155 }
156
157 int
158 IntArray::
159 max() const{
160 int high, *tmp = ia;
161 for(high = *tmp;tmp < (ia + _size); tmp++){
162 if (*tmp > high)
163 high = *tmp;
164 }
165
166 return high;
167 }
168
169 int
170 IntArray::
171 find( int value) const{
172 int * tmp = ia;
173 for(;tmp < (ia + _size); tmp++){
174 if(value == *tmp)
175 return value;
176 }
177 return (-1);
178 }
179
180
181
182
183
184

This is the example library file and this is the test program that uses our classes


http://www.nylxs.com/docs/workshops/file4_main.C.html

1 #ifndef TOP_H
2 #include
3 #define TOP_H
4 #endif
5
6 #ifndef INTARRAY_H
7 #include "intarray.h"
8 #define INTARRAY_H
9 #endif
10
11 int main(){
12 IntArray myarray1;
13 myarray1[2] = 400;
14 cout << myarray1[2] << _end;
15 return 1;
16 }
17
18


  1. 2008-07-01 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] C programming Workshop part II
  2. 2008-07-01 swd <sderrick-at-optonline.net> Re: [NYLXS - HANGOUT] Need to get rid of a whole bunch of programming
  3. 2008-07-01 email <ray-pub-at-rcn.com> Re: [NYLXS - HANGOUT] Need to get rid of a whole bunch of programming
  4. 2008-07-01 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Need to get rid of a whole bunch of programming books. TALK ABOUT FREE SOFTWARE!!!
  5. 2008-07-01 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Gates: Windows really sucks
  6. 2008-07-01 email <ray-pub-at-rcn.com> Re: [NYLXS - HANGOUT] Need to get rid of a whole bunch of programming
  7. 2008-07-02 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] [david-at-thekramers.net: Fedora 9 X dual screen problems]
  8. 2008-07-02 swd <sderrick-at-optonline.net> Re: [NYLXS - HANGOUT] Need to get rid of a whole bunch of programming
  9. 2008-07-02 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] C++ Workshop 2 (section 2.1)
  10. 2008-07-03 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] C++ Workshop 2.1
  11. 2008-07-03 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] July 4th
  12. 2008-07-03 Shoshana Rivka Safir <shani-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Post high school jobs or internships?
  13. 2008-07-03 meg7-at-nyu.edu Re: [NYLXS - HANGOUT] July 4th
  14. 2008-07-03 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] July 4th
  15. 2008-07-03 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] July 4th
  16. 2008-07-03 From: "Ronny Abraham" <ronny.coder-at-gmail.com> Re: [NYLXS - HANGOUT] Post high school jobs or internships?
  17. 2008-07-03 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] C++ Workshop 2.3
  18. 2008-07-03 From: "Michael L. Richardson" <mlr52-at-michaellrichardson.com> Re: [NYLXS - HANGOUT] Post high school jobs or internships?
  19. 2008-07-04 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] [alan-at-patriot.net: [Dclug] Our Fourth Amendment]
  20. 2008-07-04 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] 4th of July Plans
  21. 2008-07-04 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Workshops
  22. 2008-07-05 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Might be time for a visit to Congress again
  23. 2008-07-05 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  24. 2008-07-05 From: "Michael L. Richardson" <mlr52-at-mycouponmagic.com> Re: [NYLXS - HANGOUT] Workshops
  25. 2008-07-05 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Workshops
  26. 2008-07-06 From: "Ronny Abraham" <ronny.coder-at-gmail.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  27. 2008-07-07 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] [meissner-at-suse.de: [security-announce] SUSE Security Announcement: Linux kernel (SUSE-SA:2008:031)]
  28. 2008-07-07 Mark Simko <msimko-at-optonline.net> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  29. 2008-07-07 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] [meissner-at-suse.de: [security-announce] SUSE Security Announcement: Linux kernel (SUSE-SA:2008:032)]
  30. 2008-07-07 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  31. 2008-07-07 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  32. 2008-07-07 Mark Simko <msimko-at-optonline.net> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  33. 2008-07-07 Mark Simko <msimko-at-optonline.net> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  34. 2008-07-07 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  35. 2008-07-07 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  36. 2008-07-07 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  37. 2008-07-07 Mark Simko <msimko-at-optonline.net> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  38. 2008-07-07 Mark Simko <msimko-at-optonline.net> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  39. 2008-07-07 From: "Ronny Abraham" <ronny.coder-at-gmail.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  40. 2008-07-07 Ron Guerin <ron-at-vnetworx.net> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  41. 2008-07-07 From: "Ronny Abraham" <ronny.coder-at-gmail.com> Re: [NYLXS - HANGOUT] Post high school jobs or internships?
  42. 2008-07-07 From: "Ronny Abraham" <ronny.coder-at-gmail.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  43. 2008-07-07 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] [nyc-at-workatjelly.com: Jelly in Manhattan this Friday, 7/11]
  44. 2008-07-07 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  45. 2008-07-07 Ron Guerin <ron-at-vnetworx.net> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  46. 2008-07-07 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  47. 2008-07-07 From: "Ronny Abraham" <ronny.coder-at-gmail.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  48. 2008-07-08 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  49. 2008-07-08 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  50. 2008-07-08 Mark Simko <msimko-at-optonline.net> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  51. 2008-07-08 From: "Ronny Abraham" <ronny.coder-at-gmail.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  52. 2008-07-08 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  53. 2008-07-08 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  54. 2008-07-08 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  55. 2008-07-08 From: "Ronny Abraham" <ronny.coder-at-gmail.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  56. 2008-07-08 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Maybe its because lindows just sucked
  57. 2008-07-08 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] ASUS/GNU
  58. 2008-07-08 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] While we're on this topic
  59. 2008-07-08 From: "Tameek" <tameek-at-gmail.com> Re: [NYLXS - HANGOUT] [nyc-at-workatjelly.com: Jelly in Manhattan this Friday, 7/11]
  60. 2008-07-08 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] [nyc-at-workatjelly.com: Jelly in Manhattan this Friday, 7/11]
  61. 2008-07-09 email <ray-pub-at-rcn.com> Re: [NYLXS - HANGOUT] [nyc-at-workatjelly.com: Jelly in Manhattan this
  62. 2008-07-09 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Installfest this weekend?
  63. 2008-07-09 email <ray-pub-at-rcn.com> Re: [NYLXS - HANGOUT] Installfest this weekend?
  64. 2008-07-09 Mark Simko <msimko-at-optonline.net> Re: [NYLXS - HANGOUT] Post high school jobs or internships?
  65. 2008-07-12 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Installfest this weekend?
  66. 2008-07-12 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] GNU/Linux INSTALLFEST/HACKFEST NYC Local
  67. 2008-07-12 Contrarian <adrba-at-nyct.net> Subject: [NYLXS - HANGOUT] "Gates of Vienna" blog averts DMCA prosecution
  68. 2008-07-14 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Re: Linux on the desktop - it's come a long way, but is it there yet?
  69. 2008-07-15 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] so much for Apples Free Software pitch
  70. 2008-07-15 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] grep
  71. 2008-07-15 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] grep
  72. 2008-07-15 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] C++ Workshop 2.2
  73. 2008-07-18 Contrarian <adrba-at-nyct.net> Subject: [NYLXS - HANGOUT] [BrooklynFreeCycle] offer---- old library card catalog file cabinet
  74. 2008-07-18 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] HAckfest/Installfest
  75. 2008-07-18 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Re: [nylug-talk] HAckfest/Installfest
  76. 2008-07-18 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Hackfest/Installfest
  77. 2008-07-18 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Tax Exempy Status
  78. 2008-07-19 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Installfest/Hackfest Tomorrow
  79. 2008-07-20 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Installfest/Hackfest
  80. 2008-07-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] [notification+zjaayj4y-at-facebookmail.com: "Ted & Amy Supper Club (NYC)" sent you a message on Facebook...]
  81. 2008-07-22 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] C++ Workshop 2.2.3
  82. 2008-07-22 From: "Ronny Abraham" <ronny.coder-at-gmail.com> Re: [NYLXS - HANGOUT] [notification+zjaayj4y-at-facebookmail.com: "Ted & Amy Supper Club (NYC)" sent you a message on Facebook...]
  83. 2008-07-22 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] [notification+zjaayj4y-at-facebookmail.com: "Ted & Amy Supper Club (NYC)" sent you a message on Facebook...]
  84. 2008-07-23 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] C Programming Workshop
  85. 2008-07-23 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] [dalmolin-at-e-cology.ca: [Hardhats] COMMITTEE ON WAYS AND MEANS: Promoting Health IT Hearing]
  86. 2008-07-23 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] C++ Workshop 2.3.4
  87. 2008-07-24 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Dell GNU Systems
  88. 2008-07-25 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] [rick-at-linuxmafia.com: [conspire] DNS vulnerability details]
  89. 2008-07-25 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Re: [conspire] DNS vulnerability details
  90. 2008-07-25 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Re: [conspire] DNS vulnerability details
  91. 2008-07-25 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Radio Broadcasting
  92. 2008-07-25 prmarino1-at-gmail.com Re: [NYLXS - HANGOUT] [rick-at-linuxmafia.com: [conspire] DNS vulnerability details]
  93. 2008-07-25 prmarino1-at-gmail.com Re: [NYLXS - HANGOUT] [rick-at-linuxmafia.com: [conspire] DNS vulnerability details]
  94. 2008-07-25 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Re: [conspire] DNS vulnerability details
  95. 2008-07-26 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] unionfs
  96. 2008-07-26 Mark Simko <msimko-at-optonline.net> Re: [NYLXS - HANGOUT] unionfs
  97. 2008-07-26 From: "Michael L. Richardson" <mlr52-at-michaellrichardson.com> Re: [NYLXS - HANGOUT] unionfs
  98. 2008-07-27 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] unionfs
  99. 2008-07-27 Mark Simko <msimko-at-optonline.net> Re: [NYLXS - HANGOUT] unionfs
  100. 2008-07-27 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] unionfs
  101. 2008-07-27 Mark Simko <msimko-at-optonline.net> Re: [NYLXS - HANGOUT] unionfs
  102. 2008-07-27 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] unionfs
  103. 2008-07-28 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] [nyc-at-workatjelly.com: Jelly in Fort Greene Friday, 8/1]
  104. 2008-07-29 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] [Volunteer4-at-JohnMcCain.com: McCain Campaign Internships]
  105. 2008-07-30 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] August Plans
  106. 2008-07-30 From: <tameek-at-gmail.com> RE: [NYLXS - HANGOUT] August Plans
  107. 2008-07-30 From: "Michael L. Richardson" <mlr52-at-michaellrichardson.com> Re: [NYLXS - HANGOUT] August Plans
  108. 2008-07-30 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] August Plans
  109. 2008-07-30 email <ray-pub-at-rcn.com> Re: [NYLXS - HANGOUT] August Plans
  110. 2008-07-30 From: <tameek-at-gmail.com> RE: [NYLXS - HANGOUT] August Plans
  111. 2008-07-30 From: "Michael L. Richardson" <mlr52-at-mycouponmagic.com> Re: [NYLXS - HANGOUT] August Plans
  112. 2008-07-30 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] August Plans
  113. 2008-07-30 From: "Michael L. Richardson" <mlr52-at-michaellrichardson.com> Re: [NYLXS - HANGOUT] August Plans
  114. 2008-07-30 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] August Plans
  115. 2008-07-30 From: <mlr52-at-michaellrichardson.com> Re: [NYLXS - HANGOUT] August Plans
  116. 2008-07-31 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] Time to trash the eeepc
  117. 2008-07-31 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [NYLXS - HANGOUT] KDE really sucks
  118. 2008-07-31 email <ray-pub-at-rcn.com> Re: [NYLXS - HANGOUT] KDE really sucks
  119. 2008-07-31 prmarino1-at-gmail.com Re: [NYLXS - HANGOUT] Time to trash the eeepc
  120. 2008-07-31 prmarino1-at-gmail.com Re: [NYLXS - HANGOUT] Time to trash the eeepc
  121. 2008-07-31 prmarino1-at-gmail.com Re: [NYLXS - HANGOUT] KDE really sucks
  122. 2008-07-31 prmarino1-at-gmail.com Re: [NYLXS - HANGOUT] KDE really sucks
  123. 2008-07-31 From: "Stan Davenport" <stan-at-Etrtechcenter.com> Subject: [NYLXS - HANGOUT] Ruben,Opening On Long Island Near Hicksville RR Linix Developer Any
  124. 2008-07-31 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] KDE really sucks
  125. 2008-07-31 Mark Simko <msimko-at-optonline.net> Re: [NYLXS - HANGOUT] Time to trash the eeepc
  126. 2008-07-31 prmarino1-at-gmail.com Re: [NYLXS - HANGOUT] Time to trash the eeepc
  127. 2008-07-31 prmarino1-at-gmail.com Re: [NYLXS - HANGOUT] Time to trash the eeepc
  128. 2008-07-31 Ruben Safir <ruben-at-mrbrklyn.com> Re: [NYLXS - HANGOUT] Time to trash the eeepc
  129. 2008-07-31 From: <mlr52-at-michaellrichardson.com> Re: [NYLXS - HANGOUT] Time to trash the eeepc
  130. 2008-07-31 prmarino1-at-gmail.com Re: [NYLXS - HANGOUT] Time to trash the eeepc
  131. 2008-07-31 prmarino1-at-gmail.com Re: [NYLXS - HANGOUT] Time to trash the eeepc
  132. 2008-07-31 prmarino1-at-gmail.com Re: [NYLXS - HANGOUT] Time to trash the eeepc
  133. 2008-07-31 prmarino1-at-gmail.com Re: [NYLXS - HANGOUT] Time to trash the eeepc
  134. 2008-07-31 From: <mlr52-at-michaellrichardson.com> Re: [NYLXS - HANGOUT] Time to trash the eeepc

NYLXS are Do'ers and the first step of Doing is Joining! Join NYLXS and make a difference in your community today!