Sunday, January 8, 2012

String Part2





Running Codes
#include
#include
using namespace std;

int main()
{
string s1;
string s2("345");
string s3("678");
s1=s2;
cout << s1 << endl;
s1="012";
cout << s1 << endl;
s1=s1+s2+s3;
cout << s1 << endl;
s1+="9";
cout << s1 << endl;
s1.insert(0,s1);
cout << s1 << endl;
s1.insert(0,"abc");
cout << s1 << endl;
s1.erase(0,3);
cout << s1 << endl;
s1.replace(0,1,s1);
cout << s1 << endl;
cout << s1.at(0) << endl;
cout << s1.find("456") << endl;
cout << s1.substr(9,8) << endl;
return 0;


}

http://pages.cs.wisc.edu/~cs368-1/CppTutorial/NOTES/STRING.html

Creating an Http Handler in ASP

Creating an Http Handler

It’s possible to create a type that implements the IHttpHandlerinterface and have it respond
to any pattern of URL. The advantage is you have full control over the URL, and the URL of the
request doesn’t need to correspond to a physical file. The downside is that IIS configuration is
required to map the URL into the framework, and ASP.NET configuration is required to map
the URL to your specific handler.
The alternative is to use the built-in, simple handler factory. This handler is mapped to
files with an ASHX extension. The WebHandlerdirective is used to point an ASHX page at a type
that implements the IHttpHandlerinterface. Visual Studio adds a file with this directive to
your project via the Generic Handler option in the Add New Item dialog window.

Polymorphism without Inheritance

The num_sequence class of Section 4.10 simulates polymorphism. Each class object can be made
into any of the six numerical sequences at any point in the program through the set_sequence()
member function:

The ability to change the sequence type of ns is supported through programming rather than
through direct support of the language. Each class object contains an _isa data member that
identifies the current numeric sequence that it represents:




Running Codes
for (int ix = 1; ix < num_sequence::num_of_sequences(); ++ix)
{
ns.set_sequence(num_sequence::nstype(ix));
int elem_val = ns.elem(pos);
// ...
}


class num_sequence {
public:
// ...
private:
vector *_elem; // addresses current element vector
PtrType _pmf; // addresses current element generator
ns_type _isa; // identifies current sequence type
// ...
};

HTTP Handlers in ASP

HttpApplication is the type that manages the request as it moves through the pipeline. Up to
now we’ve examined the events along that pipeline and the mechanisms at your disposal for
extending its functionality. A critical step of that process is creating and executing the request
handler. The Pagehandler, which is an instance of System.Web.UI.Page(or any type derived
from that type), deals with ASPX pages. In this section we’re going to take a look at what it
takes to be a handler that the Framework recognizes, some of the other handlers that are built
into the Framework, and how to create your own handlers to custom process specialized
requests.
So what does it take to be a handler? How does the Framework know how deal with an
instance of the Pageclass, a derived type that didn’t exist at the time the Framework was
compiled? Via polymorphism, of course.
The only thing the pipeline cares about is a simple interface named IHttpHandler. Any
type that implements this interface qualifies to receive requests from the ASP.NET Framework
and process them however it sees fit. Once a type implements this interface, it’s associated
with requests via any combination of file name, file extension, or request type.
For example, the extension ASPX is mapped to the Page handler factory. The pipeline
hands the request off to this type by calling a method on the IHttpHandlerinterface. This class
looks at the request, creates an instance of the corresponding page object, and hands the request off to it via the same interface method.
Handlers Built into the Framework
A few handlers are built into the ASP.NET 1.x versions of the Framework, and ASP.NET 2.0 adds
quite a few more. Handlers can be used for any type of specialized request processing. They
can be mapped to a specific URL (as is the case with trace.axd), or the can be mapped to a
specific extension (as is the case with *.aspx).
Handlers can also respond to specific HTTP request types (GET, POST, HEAD, and oth-
ers). There actually is a handler that rejects outright any request type that is not a GET, POST,
or HEAD (the HttpMethodNotAllowedhandler).
Table 2-4 is a list of the handlers built into the Framework and a brief description of the
work that they do. A detailed discussion of some of the more prominent handlers follows.

Implementing an HttpModule ASP

The second method of extending the pipeline is to implement an HttpModule. Modules are
Microsoft’s intentional design for reusing pre- and post-processors across IIS applications.
The last technique you looked at (that of inheriting from HttpApplication in a standalone
assembly and reusing across IIS applications) has a serious limitation that modules don’t
have: You can only use one class per application (even though you can reuse that same class
across several applications).
HttpModules are designed so that several can be plugged into a single IIS application. The
extensions that Microsoft adds to the pipeline that you examined previously are implemented
as HttpModules. So by default, any IIS application has about a dozen modules plugged in and
extending the pipeline.
Modules are designed to be “plugged into” the pipeline using the web.configfile. You can
add a module to all IIS applications by adding it to the web.configat the root of a web server,
or you can add modules to specific applications by adding them to the web.configat the
virtual root of an application.
Under the system.webelement of the web.configis an HttpModules element. Any number
of modules can be added using child Add elements under the HttpModules element. Here’s a
configuration snippet that adds the module SomeModule
Running Codes



String Part 1




The string class is part of the C++ standard library. A string represents a sequence of characters.
To use the string class, #include the header file:
#include
Constructors:
string ()
- creates an empty string ("")
string ( other_string )
- creates a string identical to other_string
string ( other_string, position, count )
- creates a string that contains count characters from other_string, starting at position. If count is missing (only the first two arguments are given), all the characters from other_string, starting at position and going to the end of other_string, are included in the new string.
string ( count, character )
- create a string containing character repeated count times

MANIPULATING STRING OBJECTS
1.insert()
2.erase()
3.replace()
4.append()
More Methods IN String Class:

size():Number of elements currently
stored
length():Number of elements currently
stored
capacity():Total elements that can be stored
max_size():Maximum size of a string object
that a system can support
emply():Return true or 1 if the string is
empty otherwise returns false or 0
resize():Used to resize a string object
(effects only size and length)
at(): For accessing individual characters
substr(): For retrieving a substring
find(): For finding a specific substring
find_first_of(): For finding the location of first occurrence of the specific
character(s)
find_last_of(): For finding the location of first occurrence of the specific
character(s)
[] operator: For accessing individual character. Makes the string
object to look like an array.
Running Codes
http://pages.cs.wisc.edu/~cs368-1/CppTutorial/NOTES/STRING.html

How to Use Arrays and Vectors

Following are the first eight elements from six numerical sequences:
Fibonacci: 1, 1, 2, 3, 5, 8, 13, 21
Lucas: 1, 3, 4, 7, 11, 18, 29, 47
Pell: 1, 2, 5, 12, 29, 70, 169, 408
Triangular: 1, 3, 6, 10, 15, 21, 28, 36
Square: 1, 4, 9, 16, 25, 36, 49, 64
Pentagonal: 1, 5, 12, 22, 35, 51, 70, 92
Our program must display a pair of elements from a sequence and allow the user to guess the next element.
If the user guesses right and wishes to continue, the program then displays a second pair of elements, then
a third, and so on. How might we do that?
If succeeding element pairs are taken from the same sequence, the user, recogni zing one pair, recognizes
them all. That is not very interesting. So we'll pick an element pair from a different numeric sequence with
each iteration of the main program loop.
For now, we'll display a maximum of six element pairs per session: one pair from each of the six
sequences. We'd like to implement this so that we can loop through the display of the element pairs
without having to know which sequence we are disp laying with each loop iteration. Each iteration must
have access to three values: the element pair and the element that follows them in the sequence.
The solution we discuss in this section uses a container type that can hold a contiguous sequence of integer
values that we can reference not by name but by position within the container. We store 18 values in the
container as a collection of six tuples: The first two represent the element pair to display; the third
represents the next sequence element. With each iterati on of the loop, we add 3 to the index value, in this
way stepping through the six tuples in turn.
In C++, we can define a container as either a built-in array or an object of the stan-dard library vector class.
In general, I recommend the use of the vector class over that of the built-in array. However, a great deal of
existing code uses the built-in array, and it is important to understand how to use both representations.
To define a built-in array, we must specify the type of element the array is to hold, give the array a name,
and specify a dimension — that is, the number of elements the array can hold. The dimension must be a
constant expression — that is, an expression that does not require run-time evaluation. For example, the
following code declares pell_seq to be an array of 18 integer elements.

To define a vector class object, we must first include the vector header file. The vector class is a
template, so we indicate the type of its element in brackets following the name of the class. The dimension is placed in parentheses; it does not need to be a constant expression. The following code defines
pell_seq as a vector class object holding 18 elements of type int . By default, each element is initialized
to 0.


Running Codes
const int seq_size = 18;
int pell_seq[seq_size];


#include
vector pell_seq(seq_size);