/** The openFile method opens the file specified by filename and reads its contents into the text area. The method returns true if the file was opened and read successfully, or false if an error occurred. @param filename The name of the file to open. */

/** The saveFile method saves the contents of the text area to a file. The method returns true if the file was saved successfully, or false if an error occurred. @param filename The name of the file. @return true if successful, false otherwise. */

Thursday, December 11, 2008

This appendix provides a reference for the C++ library functions discussed in the book.The following table gives an alphabetical list of functions. Tables of functions that areorganized by their header files follow it.Table I-1 Alphabetical Listing of Selected Library FunctionsFunction Detailsabs(m)Header File:cmathDescription:Accepts an integer argument. Returns the absolute value of the argumentas an integer.Example:a = abs(m);atof(str)Header File:cstdlibDescription:Accepts a C-string as an argument. The function converts the string to adoubleand returns that value.Example:num = atof("3.14159");atoi(str)Header File:cstdlibDescription:Accepts a C-string as an argument. The function converts the string to anintand returns that value.Example:num = atoi("4569");atol(str)Header File:cstdlibDescription:Accepts a C-string as an argument. The function converts the string to alongand returns that value.Example:num = atol("5000000");2Appendix I: Header File and Library Function Referencecos(m)Header File:cmathDescription:Accepts adoubleargument. Returns the cosine of the argument. Theargument should be an angle expressed in radians. The return type isdouble.Example:a = cos(m);exit(status)Header File:cstdlibDescription:Accepts anintargument. Terminates the program and passes the valueof the argument to the operating system.Example:exit(0);exp(m)Header File:cmathDescription:Accepts adoubleargument. Computes the exponential function of theargument, which is ex. The return type isdouble.Example:a = exp(m);fmod(m, n)Header File:cmathDescription:Accepts twodoublearguments. Returns, as adouble, the remainder ofthe first argument divided by the second argument. Works like themodulus operator, but the arguments are doubles. (The modulus operatoronly works with integers.) Take care not to pass zero as the secondargument. Doing so would cause division by zero.Example:a = fmod(m, n);isalnum(ch)Header File:cctypeDescription:Accepts acharargument. Returns true if the argument is a letter of thealphabet or a digit. Otherwise, it returns false.Example:if (isalnum(ch))cout << ch << " is alphanumeric.\n";isdigit(ch)Header File:cctypeDescription:Accepts acharargument. Returns true if the argument is a digit 0 - 9.Otherwise, it returns false.Example:if (isdigit(ch))cout << ch << " is a digit.\n";Table I-1 Alphabetical Listing of Selected Library Functions(continued)Function DetailsAppendix I: Header File and Library Function Reference3islower(ch)Header File:cctypeDescription:Accepts acharargument. Returns true if the argument is a lowercaseletter. Otherwise, it returns false.Example:if (islower(ch))cout << ch << " is lowercase.\n";isprint(ch)Header File:cctypeDescription:Accepts acharargument. Returns true if the argument is a printablecharacter (including a space). Returns false otherwise.Example:if (isprint(ch))cout << ch << " is printable.\n";ispunct(ch)Header File:cctypeDescription:Accepts acharargument. Returns true if the argument is a printablecharacter other than a digit, letter, or space. Returns false otherwise.Example:if (ispunct(ch))cout << ch << " is punctuation.\n";isspace(ch)Header File:cctypeDescription:Accepts acharargument. Returns true if the argument is a whitespacecharacter. Whitespace characters are any of the following:• space................ ‘ ’• newline.............. ‘\n’• tab.................. ‘\t’• vertical tab......... ‘\v’Otherwise, it returns false.Example:if (isspace(ch))cout << ch << " is whitespace.\n";isupper(ch)Header File:cctypeDescription:Accepts acharargument. Returns true if the argument is an uppercaseletter. Otherwise, it returns false.Example:if (isupper(ch))cout << ch << " is uppercase.\n";log(m)Header File:cmathDescription:Accepts adoubleargument. Returns, as adouble, the natural logarithmof the argument.Example:a = log(m);Table I-1 Alphabetical Listing of Selected Library Functions(continued)Function Details4Appendix I: Header File and Library Function Referencelog10(m)Header File:cmathDescription:Accepts a double argument. Returns, as a double, the base-10 logarithmof the argument.Example:a = log10(m);pow(m, n) Header File: cmathDescription:Accepts two double arguments. Returns the value of argument 1 raisedto the power of argument 2.Example:a = pow(m, n);rand() Header File: cstdlibDescription:Generates a pseudorandom number.Example:x = rand();sin(m) Header File: cmathDescription:Accepts a double argument. Returns, as a double, the sine of theargument. The argument should be an angle expressed in radians.Example:a = sin(m);sqrt(m) Header File: cmathDescription:Accepts a double argument. Returns, as a double, the square root of theargument.Example:a = sqrt(m);srand(m) Header File: cstdlibDescription:Accepts an unsigned int argument. The argument is used as a seedvalue to randomize the results of the rand() function.Example:srand(m);strcat(str1, str2) Header File: cstringDescription:Accepts two C-strings as arguments. The function appends the contentsof the second string to the first string. (The first string is altered; thesecond string is left unchanged.)Example:strcat(string1, string2);Table I-1 Alphabetical Listing of Selected Library Functions (continued)Function DetailsAppendix I: Header File and Library Function Reference 5strcmp(str1, str2) Header File: cstringDescription:Accepts pointers to two string arguments. If string1 and string2 are thesame, this function returns 0. If string2 is alphabetically greater thanstring1, it returns a positive number. If string2 is alphabetically less thanstring1, it returns a negative number.Example:if (strcmp(string1, string2) == 0)cout << "The strings are equal.\n";strcpy(str1, str2) Header File: cstringDescription:Accepts two C-strings as arguments. The function copies the secondstring to the first string. The second string is left unchanged.Example:strcpy(string1, string2);strlen(str) Header File: cstringDescription:Accepts a C-string as an argument. Returns the length of the string (notincluding the null terminator).Example:len = strlen(name);strncpy(str1, str2, n) Header File: cstringDescription:Accepts two C-strings and an integer argument. The third argument, aninteger, indicates how many characters to copy from the second string tothe first string. If string2 has fewer than n characters, string1 is paddedwith ‘\0’ characters.Example:strncpy(string1, string2, n);strstr(str1, str2) Header File: cstringDescription:Searches for the first occurrence of string2 in string1. If an occurrence ofstring2 is found, the function returns a pointer to it. Otherwise, it returnsa NULL pointer (address 0).Example:cout << strstr(string1, string2);tan(m) Header File: cmathDescription:Accepts a double argument. Returns, as a double, the tangent of theargument. The argument should be an angle expressed in radians.Example:a = tan(m);Table I-1 Alphabetical Listing of Selected Library Functions (continued)Function Details6 Appendix I: Header File and Library Function Referencetolower(ch) Header File: cctypeDescription:Accepts a char argument. Returns the lowercase equivalent of itsargument.Example:ch = tolower(ch);toupper(ch) Header File: cctypeDescription:Accepts a char argument. Returns the uppercase equivalent of itsargument.Example:ch = toupper(ch);Table I-2 Selected cstdlib functionsFunction Detailsatof(str) Header File: cstdlibDescription:Accepts a C-string as an argument. The function converts the string to adouble and returns that value.Example:num = atof("3.14159");atoi(str) Header File: cstdlibDescription:Accepts a C-string as an argument. The function converts the string to anint and returns that value.Example:num = atoi("4569");atol(str) Header File: cstdlibDescription:Accepts a C-string as an argument. The function converts the string to along and returns that value.Example:num = atol("5000000");exit(status) Header File: cstdlibDescription:Accepts an int argument. Terminates the program and passes the valueof the argument to the operating system.Example:exit(0);Table I-1 Alphabetical Listing of Selected Library Functions (continued)Function DetailsAppendix I: Header File and Library Function Reference 7rand() Header File: cstdlibDescription:Generates a pseudorandom number.Example:x = rand();srand(m) Header File: cstdlibDescription:Accepts an unsigned int argument. The argument is used as a seedvalue to randomize the results of the rand() function.Example:srand(m);Table I-3 Selected cmath FunctionsFunction Detailsabs(m) Header File: cmathDescription:Accepts an integer argument. Returns the absolute value of the argumentas an integer.Example:a = abs(m);cos(m) Header File: cmathDescription:Accepts a double argument. Returns the cosine of the argument. Theargument should be an angle expressed in radians. The return type isdouble.Example:a = cos(m);exp(m) Header File: cmathDescription:Accepts a double argument. Computes the exponential function of theargument, which is ex. The return type is double.Example:a = exp(m);fmod(m, n) Header File: cmathDescription:Accepts two double arguments. Returns, as a double, the remainder ofthe first argument divided by the second argument. Works like themodulus operator, but the arguments are doubles. (The modulus operatoronly works with integers.) Take care not to pass zero as the secondargument. Doing so would cause division by zero.Example:a = fmod(m, n);Table I-2 Selected cstdlib functions (continued)Function Details8 Appendix I: Header File and Library Function Referencelog(m) Header File: cmathDescription:Accepts a double argument. Returns, as a double, the natural logarithmof the argument.Example:a = log(m);log10(m) Header File: cmathDescription:Accepts a double argument. Returns, as a double, the base-10 logarithmof the argument.Example:a = log10(m);pow(m, n) Header File: cmathDescription:Accepts two double arguments. Returns the value of argument 1 raisedto the power of argument 2.Example:a = pow(m, n);sin(m) Header File: cmathDescription:Accepts a double argument. Returns, as a double, the sine of theargument. The argument should be an angle expressed in radians.Example:a = sin(m);sqrt(m) Header File: cmathDescription:Accepts a double argument. Returns, as a double, the square root of theargument.Example:a = sqrt(m);tan(m) Header File: cmathDescription:Accepts a double argument. Returns, as a double, the tangent of theargument. The argument should be an angle expressed in radians.Example:a = tan(m);Table I-3 Selected cmath Functions (continued)Function DetailsAppendix I: Header File and Library Function Reference 9Table I-4 Selected cstring FunctionsFunction Detailsstrcat(str1, str2) Header File: cstringDescription:Accepts two C-strings as arguments. The function appends the contentsof the second string to the first string. (The first string is altered; thesecond string is left unchanged.)Example:strcat(string1, string2);strcmp(str1, str2) Header File: cstringDescription:Accepts pointers to two string arguments. If string1 and string2 are thesame, this function returns 0. If string2 is alphabetically greater thanstring1, it returns a positive number. If string2 is alphabetically less thanstring1, it returns a negative number.Example:if (strcmp(string1, string2) == 0)cout << "The strings are equal.\n";strcpy(str1, str2) Header File: cstringDescription:Accepts two C-strings as arguments. The function copies the secondstring to the first string. The second string is left unchanged.Example:strcpy(string1, string2);strlen(str) Header File: cstringDescription:Accepts a C-string as an argument. Returns the length of the string (notincluding the null terminator)Example:len = strlen(name);strncpy(str1, str2, n) Header File: cstringDescription:Accepts two C-strings and an integer argument. The third argument, aninteger, indicates how many characters to copy from the second string tothe first string. If string2 has fewer than n characters, string1 is paddedwith ‘\0’ characters.Example:strncpy(string1, string2, n);strstr(str1, str2) Header File: cstringDescription:Searches for the first occurrence of string2 in string1. If an occurrence ofstring2 is found, the function returns a pointer to it. Otherwise, it returnsa NULL pointer (address 0).Example:cout << strstr(string1, string2);10 Appendix I: Header File and Library Function ReferenceTable I-5 Selected cctype FunctionsFunction Detailsisalnum(ch) Header File: cctypeDescription:Accepts a char argument. Returns true if the argument is a letter of thealphabet or a digit. Otherwise, it returns false.Example:if (isalnum(ch))cout << ch << " is alphanumeric.\n";isdigit(ch) Header File: cctypeDescription:Accepts a char argument. Returns true if the argument is a digit 0 - 9.Otherwise, it returns false.Example:if (isdigit(ch))cout << ch << " is a digit.\n";islower(ch) Header File: cctypeDescription:Accepts a char argument. Returns true if the argument is a lowercaseletter. Otherwise, it returns false.Example:if (islower(ch))cout << ch << " is lowercase.\n";isprint(ch) Header File: cctypeDescription:Accepts a char argument. Returns true if the argument is a printablecharacter (including a space). Returns false otherwise.Example:if (isprint(ch))cout << ch << " is printable.\n";ispunct(ch) Header File: cctypeDescription:Accepts a char argument. Returns true if the argument is a printablecharacter other than a digit, letter, or space. Returns false otherwise.Example:if (ispunct(ch))cout << ch << " is punctuation.\n";isspace(ch) Header File: cctypeDescription:Accepts a char argument. Returns true if the argument is a whitespacecharacter. Whitespace characters are any of the following:• space................ ‘ ’• newline.............. ‘\n’• tab.................. ‘\t’• vertical tab......... ‘\v’Otherwise, it returns false.Example:if (isspace(ch))cout << ch << " is whitespace.\n";Appendix I: Header File and Library Function Reference 11isupper(ch) Header File: cctypeDescription:Accepts a char argument. Returns true if the argument is an uppercaseletter. Otherwise, it returns false.Example:if (isupper(ch))cout << ch << " is uppercase.\n";tolower(ch) Header File: cctypeDescription:Accepts a char argument. Returns the lowercase equivalent of itsargument.Example:ch = tolower(ch);toupper(ch) Header File: cctypeDescription:Accepts a char argument. Returns the uppercase equivalent of itsargument.Example:ch = toupper(ch);Table I-5 Selected cctype Functions (continued)Function Details

Sunday, November 9, 2008

Heap Demo is a project designed to show the relationship between virtual and committedmemory during heap use. Using a contrived scenario, a stair-step growth of virtualmemory can be observed in perfmon.

Open a new cpp file in Visual Studio. copy and paste code from this post. compile the file it will create project for u. then u can proceed further

1. Start the HeapDemo application.2. Open perfmon.3. Add counters for Virtual Bytes and Private Bytes for the HeapDemo Process.4. Change the scale for each counter to 0.0000001 (lowest value).5. Press ENTER on the console for HeapDemo to start the allocations.6. Watch the perfmon window as memory is allocated.

Note the stair step behavior of virtual memory. Each time the private bytes nears the amountof virtual bytes reserved, the memory manager extends the heap by reserving more virtualmemory. Each time the heap is extended, it reserves twice as much as the previous reservation.

// Tthe entry point for the console application.//

#include #include

void Test();

int main(int argc, char* argv[]){ Test();

return 0;}

void Test(){ int nCount = 0; int nTotal = 0; char c;

// scanf in here only to hold process in initial loaded state to set up PerfMon. printf("Set up Process Object's Private and Virtual Bytes for Heapdemo.exe, then hit ENTER to start the test\n"); scanf(&c);

Thursday, October 23, 2008

This is the implementation of "System.Net.Sockets". In this example we will learn how to use the "TCPListener" and "TCPClient" classes from the "System.Net.Sockets" namespace.
This example consists of two files. The "DateServer" class which uses the "TCPListener" class to accept requests from new clients. Once the client is connected with the server, the server will send it the the Current Date and Time and then disconnect it, and listen for more clients.
The "DateClient" class uses the 'TCPClient" class. It connects to the server on the specified port and send the clients name to the server upon connection.
Once connected it receives the current Date Time from the server and then disconnects from the server.

Execution :
1) Run the DateServer.exe first to start the server .(The server by default listens for connection on port 4554).
2) Run the DateClient.exe which will connect to the server and get the current date time from it.