Pages

Wednesday 8 June 2011

Ignore case differences when comparing strings.



Ignore case differences when comparing strings.
#include <iostream>
#include <cctype>
using namespace std;
int strcmp_ign_case(const char *str1, const char *str2);
void showresult(const char *str1, const char *str2, int result);
int main() {
char strA[]= "tesT";
char strB[] = "Test";
char strC[] = "testing";
char strD[] = "Tea";
int result;
cout << "Here are the strings: " << endl;
cout << "strA: " << strA << endl;
cout << "strB: " << strB << endl;
cout << "strC: " << strC << endl;
cout << "strD: " << strD << "\n\n";

// Compare strings ignoring case.
result = strcmp_ign_case(strA, strB);
showresult(strA, strB, result);
result = strcmp_ign_case(strA, strC);
showresult(strA, strC, result);
result = strcmp_ign_case(strA, strD);
showresult(strA, strD, result);
result = strcmp_ign_case(strD, strA);
showresult(strD, strA, result);
return 0;
}
// A simple string comparison function that ignores case differences.
int strcmp_ign_case(const char *str1, const char *str2) {
while(*str1 && *str2) {
if(tolower(*str1) != tolower(*str2))
break;
++str1;
++str2;
}
return tolower(*str1) - tolower(*str2);
}
void showresult(const char *str1, const char *str2, int result) {
cout << str1 << " is ";
if(!result)
cout << "equal to ";
else if(result < 0)
cout << "less than ";
else
cout << "greater than ";
cout << str2 << endl;

Reverse a string in place by using recursion.


// Reverse a string in place by using recursion.
void revstr_r(char *str) {
revstr_recursive(str, 0, strlen(str)-1);
}

void revstr_recursive(char *str, int start, int end) {
if(start < end)
revstr_recursive(str, start+1, end-1);
else
return;
char t = str[start];
str[start] = str[end];
str[end] = t;
}

Reverse a string in place. Use pointers rather than array indexing.


Reverse a string in place. Use pointers rather than array indexing.
void revstr(char *str) {
char t;
char *inc_p = str;
char *dec_p = &str[strlen(str)-1];
while(inc_p <= dec_p) {
t = *inc_p;
*inc_p++ = *dec_p;
*dec_p-- = t;
}
}

Reverse a string in place.


// Reverse a string in place.
void revstr(char *str) {
int i, j;
char t;
for(i = 0, j = strlen(str)-1; i < j; ++i, --j) {
// Exchange corresponding characters, front to back.
t = str[i];
str[i] = str[j];
str[j] = t;
}
}

The following program shows revstr( ) in action:
// Reverse a string in place.
#include <iostream>
#include <cstring>
using namespace std;
void revstr(char *str);
int main() {
char str[] = "abcdefghijklmnopqrstuvwxyz";
cout << "Original string: " << str << endl;
revstr(str);
cout << "Reversed string: " << str << endl;
return 0;
}
// Reverse a string in place.
void revstr(char *str) {
int i, j;
char t;
for(i = 0, j = strlen(str)-1; i < j; ++i, --j) {
t = str[i];
str[i] = str[j];
str[j] = t;
}
}
The output is shown here:
Original string: abcdefghijklmnopqrstuvwxyz
Reversed string: zyxwvutsrqponmlkjihgfedcba

Operator Meaning



Operator Meaning

= Assignment
+ Concatenation
+= Concatenation assignment
== Equality
!= Inequality
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
[ ] Subscripting
<< Output
>> Input

The following example shows strcpy( ), strcat( ), strcmp( ), and strlen( ) in action:



The following example shows strcpy( ), strcat( ), strcmp( ), and strlen( ) in action:
// Demonstrate the basic null-terminated string functions.

#include <iostream>
#include <cstring>
using namespace std;
int main() {
char strA[7] = "Up";
char strB[5] = "Down";
char strC[5] = "Left";
char strD[6] = "Right";
cout << "Here are the strings: " << endl;
cout << "strA: " << strA << endl;
cout << "strB: " << strB << endl;
cout << "strC: " << strC << endl;
cout << "strD: " << strD << "\n\n";
// Display the length of strA.
cout << "Length of strA is " << strlen(strA) << endl;
// Concatenate strB with strA.
strcat(strA, strB);
cout << "strA after concatenation: " << strA << endl;
cout << "Length of strA is now " << strlen(strA) << endl;
// Copy strC into strB.
strcpy(strB, strC);
cout << "strB now holds: " << strB << endl;
// Compare strings.
if(!strcmp(strB, strC))
cout << "strB is equal to strC\n";

int result = strcmp(strC, strD);
if(!result)
cout << "strC is equal to strD\n";
else if(result < 0)
cout << "strC is less than strD\n";
else if(result > 0)
cout << "strC is greater than strD\n";
return 0;
}
The output is shown here:
Here are the strings:
strA: Up
strB: Down
strC: Left
strD: Right
Length of strA is 2
strA after concatenation: UpDown
Length of strA is now 6
strB now holds: Left
strB is equal to strC
strC is less than strD

Function Description



Function Description
char *strcat(char *str1, const char *str2) Concatenates the string pointed to by str2 to the end of
the string pointed to by str1. Returns str1. If the strings
overlap, the behavior of strcat( ) is undefined.
char *strchr(const char *str, int ch) Returns a pointer to the first occurrence of the low-order
byte of ch in the string pointed to by str. If no match is
found, a null pointer is returned.
int strcmp(const char *str1, const char str2) Lexicographically compares the string pointed to by str1
with the string pointed to by str2. Returns less than zero
if str1 is less than str2, greater than zero if str1 is greater
than str2, and zero if the two strings are the same.
10 H e r b S c h i l d t ' s C + + P r o g r a m m i n g C o o k b o o k
Function Description
char *strcpy(char *target,
const char *source)
Copies the string pointed to by source to the string pointed
to by target. Returns target. If the strings overlap, the
behavior of strcpy( ) is undefined.
size_t strcspn(const char *str1,
const char *str2)
Returns the index of the first character in the string
pointed to by str1 that matches any character in the string
pointed to by str2. If no match is found, the length of str1
is returned.
size_t strlen(const char *str) Returns the number of characters in the string pointed to
by str. The null terminator is not counted.
char *strncat(char *str1,
const char *str2,
size_t count)
Concatenates not more than count characters from
the string pointed to by str2 to the end of str1. Returns
str1. If the strings overlap, the behavior of strncat( ) is
undefined.
int strncmp(const char *str1,
const char *str2,
size_t count)
Lexicographically compares not more than the first count
characters in the string pointed to by str1 with the string
pointed to by str2. Returns less than zero if str1 is less
than str2, greater than zero if str1 is greater than str2, and
zero if the two strings are the same.
char *strncpy(char *target,
const char *source,
size_t count)
Copies not more than count characters from the string
pointed to by source to the string pointed to by target.
If source contains less than count characters, null
characters will be appended to the end of target until
count characters have been copied. However, if source is
longer than count characters, the resultant string will not
be null-terminated. Returns target. If the strings overlap,
the behavior of strcnpy( ) is undefined.
char *strpbrk(const char *str1,
const char *str2)
Returns a pointer to the first character in the string
pointed to by str1 that matches any character in the string
pointed to by str2. If no match is found, a null pointer is
returned.
char *strrchr(const char *str, int ch) Returns a pointer to the last occurrence of the low-order
byte of ch in the string pointed to by str. If no match is
found, a null pointer is returned.
size_t strspn(const char *str1,
const char *str2)
Returns the index of the first character in the string
pointed to by str1 that does not match any of the
characters in the string pointed to by str2.
char *strstr(const char *str1,
const char *str2)
Returns a pointer to the first occurrence of the string
pointed to by str2 in the string pointed to by str1. If no
match is found, a null pointer is returned.
char *strtok(char *str, const char *delims) Returns a pointer to the next token in the string pointed
to by str. The characters in the string pointed to by delims
specify the delimiters that determine the boundaries of a
token. A null pointer is returned when there is no token to
return. To tokenize a string, the first call to strtok( ) must
have str point to the string to be tokenized. Subsequent
calls must pass a null pointer to str.

C++ basics

// One way to implement the standard strcpy() function.
char *strcpy(char *target, const char *source) {
char *t = target;
// Copy the contents of source into target.
while(*source) *target++ = *source++;
// Null-terminate the target.
*target = '\0';
// Return pointer to the start of target.
return t;
}
Pay special attention to this line:
while(*source) *target++ = *source++;

C++ Basics From H e r b S c h i l d t ' s C + + P r o g r a m m i n g C o o k b o o k



String Handling
There is almost always more than one way to do something in C++. This is one reason
why C++ is such a rich and powerful language. It lets the programmer choose the best
approach for the task at hand. Nowhere is this multifaceted aspect of C++ more evident
than in strings. In C++, strings are based on two separate but interrelated subsystems. One
type of string is inherited from C. The other is defined by C++. Together, they provide the
programmer with two different ways to think about and handle sequences of characters.
The first type of string supported by C++ is the null-terminated string. This is a char array
that contains the characters that comprise a string, followed by a null. The null-terminated
string is inherited from C and it gives you low-level control over string operations. As a
result, the null-terminated string offers a very efficient way in which to handle character
sequences. C++ also supports wide-character, null-terminated strings, which are arrays of
type wchar_t.
The second type of string is an object of type basic_string, which is a template class
defined by C++. Therefore, basic_string defines a unique type whose sole purpose is to
represent sequences of characters. Because basic_string defines a class type, it offers a highlevel
approach to working with strings. For example, it defines many member functions
that perform various string manipulations, and several operators are overloaded for string
operations. There are two specializations of basic_string that are defined by C++: string
and wstring. The string class operates on characters of type char, and wstring operates on
characters of type wchar_t. Thus, wstring encapsulates a wide-character string.
As just explained, both null-terminated strings and basic_string support strings of types
char and wchar_t. The main difference between strings based on char and those based on
wchar_t is the size of the character. Otherwise, the two types of strings are handled in
essentially the same way. For the sake of convenience and because char-based strings are, by
far, the most common, they are the type of strings used in the recipes in this chapter. However,
the same basic techniques can be adapted to wide-character strings with little effort.
The topic of C++ strings is quite large. Frankly, it would be easy to fill an entire book
with recipes about them. Thus, limiting the string recipes to a single chapter presented quite
a challenge. In the end, I selected recipes that answer common questions, illustrate key
aspects of each string type, or demonstrate general principles that can be adapted to a wide
variety of uses.

C++ Basics


Returning a Value from main( )
The code examples in this book always explicitly return an integer value from main( ).
By convention, a return value of zero indicates successful termination. A non-zero return
value indicates some form of error.
Explicitly returning a value from main( ) is not technically necessary, however, because
in the words of the International Standard for C++:
"If control reaches the end of main without encountering a return statement, the effect
is that of executing return 0;"
For this reason, you will occasionally find code that does not explicitly return a value from
main( ), relying instead upon the implicit return value of zero. But this is not the approach
used by this book.
Instead, all of the main( ) functions in this book explicitly return a value because of two
reasons. First, some compilers issue a warning when a non-void method fails to explicitly
return a value. To avoid this warning, main( ) must include a return statement. Second, it
just seems good practice to explicitly return a value, given that main( ) is declared with an
int return type!

Using Namespace std ?
One of the problems that a writer of a C++ book faces is whether or not to use the line:
using namespace std;
C h a p t e r 1 : O v e r v i e w 5
near the top of each program. This statement brings the contents of the std namespace into
view. The std namespace contains the C++ standard library. Thus, by using the std namespace,
the standard library is brought into the global namespace, and names such as cout can be
referred to directly, rather than as std::cout.
The use of
using namespace std;
is both very common and occasionally controversial. Some programmers dislike it, suggesting
that it defeats the point of packaging the standard library into the std namespace and invites
conflicts with third-party code, especially in large projects. While this is true, others point out
that in short programs (such as the examples shown in this book) and in small projects, the
convenience it offers easily offsets the remote chance of conflicts, which seldom (if ever) occur
in these cases. Frankly, in programs for which the risk of conflicts is essentially zero, having to
always write std::cout, std::cin, std::ofstream, std::string, and so on is tedious. It also makes
the code more verbose.
The foregoing debate notwithstanding, this book uses
using namespace std;
in the example programs for two reasons. First, it makes the code shorter, which means that
more code can fit on a line. In a book, line-length is limited. Not having to constantly use
std:: shortens lines, which means that more code can fit on a single line without causing the
line to break. The fewer broken lines, the easier the code is to read. Second, it makes the code
examples less verbose, which enhances their clarity on the printed page. It has been my
experience that using namespace std is very helpful when presenting example programs
shown in a book. However, its use in the examples is not meant as an endorsement of the
technique in general. You must decide what is appropriate for your own programs.

Banking Management System


Project can be categorized in two ways :-

1.      Local area network projects.

2.      Distributed Projects.

Local Area Network projects are those projects where application has to be incorporated in the Local area network of the client i.e within its premises only. In LAN case server is not remotely located and client access this application through this network. Here the question of platform independence does not  arise and we use technologies like : Visual Basic , Fox pro , D2k  or C,C++.

Distributed projects are those projects where application is remotely situated. In these kind of projects application is remotely situated on to the remote server from where client machine access this application. WAN and aInternet is a kind of distributed application where client machine connects to the remote server and application is downloaded on to client machine. Here the question of platform independence arises and we use technologies like Java Servlets , Java Server Pages , EJB , RMI etc.

Weather you are working on LAN projects or Distributed projects there are two sides of it :-

1.      Front End.

2.      Back End.

Front End remains on client side. Front end is made for end user who uses our application. Basically in front end our input-output forms reside which takes the input from the client and gives output back to client.

Backend remains on server side and has two components i.e.

1.      Server side program
2.      Data Base.

Data base is the most important thing in this universe as data base gives identity to a thing without data base existence of a thing is impossible.
While working on a project first step is to design a database.

What is data base ?

Data Base is a collection of tables and table is a collection of records in a tabular form i.e. in row and columns.

Data Base can be divided into two parts :-

1.      RDBMS.

2.      DBMS.

We will be using RDBMS (Relational Database Management System) in our project i.e. oracle 8i Enterprise edition.





Why we are using Oracle (RDBMS)?

Some of the merits of using Oracle (RDBMS) is as under  :-

·        Centralization of database.
·        Client Server Technology.
·        Security.
·        Normalization of Data Base.
·        Relationship.
·        Transaction Processor.
·        It gives some internet related features.

Hence because of these features we are using Oracle as a back end technology.

ABOUT ORACLE 8.0


Oracle 8.0 contains all the features of previous version. It also supports some new features  & enhancement to some existing features. Oracle servers provides deficient & effective solution for the major features.

·        Large Database  & Space Management Control


Oracle supports the largest database potential hundreds of Giga Bytes in size. To make  efficient  use of expensive devices , it allows full control of space usage.

·        Many Concurrent Database Performances


It supports large no of concurrent users executing a variety of database Applications operation on the same data. It minimizes  data connection & guarantees data concurrency.

·        High Transaction Processing Performance


Oracle maintains the processing features with a high degree of overall system performance. Database user doesn’t suffer from slow processing performance.

·        High Availability


At some sets Oracle works 24 Hours per day with  no downtime or limit database throughput. Normal system operation such as database backup & partial completion system failure don’t interrupt database use.

·        Controlled Availability


 Oracle can selectively control the availability of data at the database level & sub Database level. e.g. an administrator  can disallow  use of a specific application .Data can be reloaded without affecting other application.

·        Industry Accepted Standards


Oracle adheres to industry accepted standards for the data access language operating system, user interface & network communication protocols . It is open system that protocols a customer invention.

·        Manageable Security


To protect against unauthorized database aspects & users .Oracle provides failsafe security features to limit & monitor the data area. The system make it easy to manage even the most completed designs for data assets.

·        Database  Enforced Integrity


Oracle enforces data integrity “Business rules” that dictates the standards for applicable data. As result the cost of coding & managing checks in many database applications are eliminated.

·        Distributed Database System


For community environment that are connected via networks. Oracle combines the data physically located on the different computers in one logical database that can be accessed by all the network users. Distributed systems have same degree of user transparency & data consistency as non-distributed systems. Yet receives the advantages of local database management.

·        Portability


Oracle software is compatible to work under different operating system & same on all system. Application  developed on Oracle can be used on virtually any system with little or no more modification.

·        Compatibility


Oracle software is compatible with industry standards, including most industry standards operating systems. Application developed on Oracle can be used on virtually any system with little or no modification.

·        Connectivity


Oracle software allows different types of computers & operating system  to share information networks.

NEW FEATURES OF ORACLE 8.0


·        Improved Scalability


The maximum size of an Oracle database has been increased to support hundreds of terabytes depending on the operating system on which it resides.

·        Improved Security


Oracle 8.0 server  now includes password management so that a password has a limited lifetime & must meet certain complexity  such as minimum length. An account can be locked after a specified no of failed login attempts.

·        Improved Performance Via Partition


A table of index can divided into smaller pieces called patrons, based on the value of one  or more columns. A table patron can be individually managed so that operation in one partition do not affect the availability of data on the other partitions. Also Insert ,Update ,Delete operation against a partitioned table can be processed partially.
In other words, the Oracle 8 server can assign a portion of the work to execute a single DML statement to multiple processes , which may then be allocated to multiple processes by  the server operating system. As a result ,the parallel DML operation is completed more quickly.

·        Enhanced Support for Database Replication


The performance & manageability of database replication have been significantly improved.

·        Capability To Handle  a Much Larger Number Of Concurrent Users


By pooling database connection, the Oracle 8 server is able t9o service a much larger number of concurrent users up to  3000, depending on the server operating system & server hardware resources.

·        New & Improved Data Types


Some existing data types have been enhanced & new data types have been introduced.

·        Improved Select Statement


A new feature of the select  statement allows a sub query to be used in place of a table
in a from clause.


Now when we are discussing Data Base there is one more thing attached to it i.e. Data Base Models.

DataBase Models :

                        There are three kind of database models :-
1.      Single tier architecture.
2.      Two tier architecture.
3.      N- tier architecture.

Single tier Architecture :- In this kind of architecture Database and Client Application remains on One machine i.e there is no client server technology , there is no centralization of database and basically it is a stand alone system.

Two tier Architecture :- In this Kind of architecture Database and client application is on two different machine i.e. Database on one machine and Application on another machine. In this type of architecture there is client server technology and centralisation of data base is there, but it has two demerrits :-

1.      Security is not there,
2.      Multiple Client access is not there.

N- tier Architecture :- In this kind of architecture there is a middle ware in between client and database. Middle ware checks the validity of the client i.e. weather client can access the database or not. Hence there is security in it as well as middle ware allows multiple client access.

What is Middle Ware ?

Middle Ware is a concept , Middle Ware provides centralization of business logic i.e. instead of putting logic on each and every client machine we put logic on a centralized server hence middle ware is nothing but a server side program where all your business logic and business methods reside. It remains on server side and it has all the logical building. Middle ware provides :-

  1. Multiple Client access.
  2. centralized business logic in case of distributed application.

Because we are working on Distributed Application Based Project we need platform independent Language :-

Introduction to Java

Java is a high level, third-generation programming language, like C, Fortran, Perl and many others. It is a platform for distributed computing – a development and run-time environment that cointains built-in support for the World Wide Web.




History of Java

Java development began at Sun Microsystem in 1991, the same year the World Wide Web was conceived. Java’s creator , James Gosling did not design java for the Internet. His Objective was to create a common development environment for consumer electronic devices which was easily portable from one device to another. This effort evolved into a language , code named Oak and later renamed Java that retains much of the syntax and power of c++ , but is simpler and more platform independent.

Java Features

Some of the important features of Java are as follows:

  • Simplicity
  • Orientation
  • Platform Independence
  • Security
  • High Performance
  • Multi Threading
  • Dynamic linking.
  • Garbage Collection.

One of the most important feature of Java is Platform Independence which makes it famous and suitable language for World Wide Web.

Why java is Platform Independent ?

Java is Platform Independent because of Java Virtual Machine (JVM).


Java Virtual Machine (JVM)

The client application or operating system must have a java byte-code interpreter to execute byte-code instructions. The interpreter is a part of a lager program called the JVM. The JVM interprets the byte code into native code and is available on platforms that supports java.

When the user runs a Java program, it is upto the JVM to load , possibly verify, and then execute it. The JVM can perform this function from within a browser or any other container program or directly on top of the operating system.

When a browser invokes the JVM to run a Java program, the JVM does a number of things :

  1. It validates the requested byte-codes, verifying that they pass various formatting and security checks.
  2. It allocates memory for the in coming java class files and guarantees that the security of JVM is not violated. This is known as the class loader.
  3. it interprets the byte code instructions found in the class files to execute the program.

Connectivity using JDBC :-

There are four kind of drivers available in Jdbc :-

1.      JdbcOdbc Bridge Driver.
2.      Partly Java Driver.
3.      Pure Java Driver.
4.      Native Driver.

JdbcOdbcDriver : This provides Jdbc access via Odbc drivers. Note that Odbc binary code , and in many case database client code, must be loaded an each client machine that uses this driver. As a result this kind of driver is most appropriate on a corporate network where client installations are not a major problem.

Partly Java Driver : This Driver translates Jdbc calls into a Net Protocol which is then translated to a RDBMS protocolby a server.In this kind of driver part of the binary code should be on client machine and part should be on server, hence this kind of driver has same problem that was with JdbcOdbc driver and it is mostly used in Intranet.

Pure Java Driver : This is a platform independent driver as this kind of driver remains on server. This kind of driver is provided by third party vendor. This net server middle ware is able to connect its pure java clients to many different databases.

Native Driver : This kind of driver converts JDBC calls into the network protocol used by Dbms directly. This allows a direct call from client machine to the DBMS server and is a practical solution for Intranet access.

Note :- We are using 3rd Type of driver i.e. Thin Driver in our project.

Client Side Interface :-

In client side interface we are using :-

a)     Swings – In WAN Application.
b)     Servlet / JSP – In Internet Based Application.

Swings components are platform independent components and we are designing client side forms using Swings and we are calling EJB (Server side business logic) on event.

Servlets / JSP are middleware technologies which are used in web based projects because they use :-
1.      HTTP Protocol to handle Request and Response.
2.      They are invoked through Browser.
3.      They give out put in HTML format.
4.      They need Browser Support.

We have designed web based forms using servlets and servlets call EJB in which we have defined business logic.




EJB :- EJB is a server side component in which we define business logic which is reuseable.

Features of EJB are:-

1.                       Wider Scope i.e. it can be used in both application based projects and web based projects.
2.                       Reusability.
3.                       Economical and efficient.
4.                       Connection Pool.
5.                       Transaction and Persistency.
6.                       Security.
7.                       Multi threading.


           






System Analysis and Software Requirement Specification(According to IEEE Standard no. 830-1984)


Banking Management System


The main objective of study: -

Objective of the proposed project is to provide Computerized Bank Service and maintain all the transaction using Computer in a WAN where all branches are connected to each other. That means all the customer of the bank would be able to access their accounts and related information by linking to the site , on the internet.

Objective of WAN based Application :-

1.      To provide centralized business logic ( Server Side Component) so that different branches can be connected to each other in wide area network.
2.      To maintain Customer Information.
3.      To maintain Account Information.
4.      To maintain Cheque, DD, Loan Information.

Objective of Internet based Application :-

  1. Supply of account information on Line.
  2. Servicing of application and request.
  3. Transfer of accounts.
  4. On Line clarifications.
  5. On Line Stop Payment.
  6. On Line Loan Information.

Client’s Requirement :-


1.      Customer detail.
2.      Financial Records
3.      Employee Records
4.      Banking Records
5.      On Line Transactions.

PURPOSE: -


            Computerized Bank Management system is developed to facilitate the general administration system to manage the various information of the Banks and the processes involved in a Bank Transactions. So, that organization can access accurate information quickly and easily as and when required, thereby improving its operational efficiency & effectiveness.


 

 Why is the topic chosen: -


                                                  In today’s competitive environment, where everybody wants to be on the top, Information plays very crucial role.
As fast as information is accessed and processed, it can give good results.
Computerized system help to fulfill these goals . Computerization of the official works will help in doing lot of manual work quickly . It will help in easy storage and access of  all information , in short period of time.


 

What contribution would the Project make: -


This is a era of Information Technology where getting information is the base of each and every thing. Success of any business depends upon its popularity and goodwill. Today market has been expanded and you have to be a global player , today client want to access most of the information from his residence and then do transaction.


                                                  The project would help in effective and systematic record keeping that is storing and retrieving of useful data. Project will be able to give the report so that management can make decisions on the basis of those reports.



Project Category:-

Category of this project is RDBMS based N-tier architecture Distributed Environment based project with server side component.

Search This Blog