Wednesday, February 27, 2013

Dynamic memory allocation with new and delete

There are many cases where it would be useful to be able to size or resize arrays while the program is being run. For example, we may want to use a string to hold someone’s name, but we do not know how long their name is until they enter it. Or we may want to read in a number of records from disk, but we don’t know in advance how many records there are. Or we may be creating a game, with a variable number of monsters chasing the player.
[http://efficientprograms.blogspot.in/]
If we have to declare the size of everything at compile time, the best we can do is try to make a guess the maximum number of variables we’ll need and hope that’s enough:
1
2
3
char szName[25]; // let's hope their name is less than 25 chars!
Record asRecordArray[500]; // let's hope there are less than 500 records!
Monster asMonsterArray[20]; // 20 monsters maximum
This is a poor solution for several reasons. First, it leads to wasted memory if the variables aren’t actually used. For example, if we allocate 25 chars for every name, but names on average are only 12 chars long, we’re allocating over twice what we really need! Second, it can lead to artificial limitations and/or buffer overflows. What happens when the user tries to read in 600 records from disk? Because we’ve only allocated 500 spaces, either we have to give the user an error, only read the first 500 records, or (in the worst case where we don’t handle this case at all), we overflow the record buffer and our program crashes.
Fortunately, these problems are easily solved via dynamic memory allocation. Dynamic memory allocation allows us to allocate memory of whatever size we want when we need it.

List of MBA colleges in Pune – Business Schools in Pune


  1. Symbiosis Institute of Business Management Pune (SIBM) – 411042
  2. MITCON Institute of Management (MIMA) Shivajinagar, Pune, 411005
  3. Suryadatta Education Foundation Vijayanagar Colony, Pune, 411030
  4. Data Systems Research foundation (DSRF) Behind IT Towers, Zensar, Pune
  5. Balaji Institute of Modern Management, Pune – 411 033
  6. Audyogik Shikshan Mandal’s Institute of Business Management & Research, Pune – 411019
  7. The Indian Institute of Planning & Management(IIPM) Deccan Gymkhana, Pune, 411004
  8. International Institute of Information Technology P-14, Pune Infotech Park, Hinjawadi, Pune, 57
  9. Indian Institute of Modern Management (IIMM) Yerawada, Pune, 411006
  10. Indian Institute of Management Training (IIMT) Bhosari, Pune, 411026
  11. Shree C. E. Society’s Indira Institute of Management, Pune – 411033
  12. Dr. D. Y. Patil Institute of Management & Researchi, Pimpri – 411018
  13. Dr. Vikhe Patil Foundation’s, Pravara Centre for Management Research & Development, Pune – 411016
  14. Institute of Science’s Institute of Business Management & Research, Pune – 411057
  15. Institute of Science’s Institute of Business Management & Research, Pune – 411057
  16. Poona District Education Association’s, Mahatma Phule Institute of Management & Computer Studies, Pune – 411028

Sunday, February 24, 2013

Difference between method overriding and overloading in C++


Overloading a function in C++ is the ability for functions of the same name to be defined as long as these methods have different signatures (different set of parameters). Method overriding is the ability of the inherited class rewriting the virtual method of the base class.
a) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method.
(b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass.
(c) In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass.
(d) Overloading must have different method signatures whereas overriding must have same signature.
Eg;
struct base {
   virtual void foo(); 
   void foo(int);      // overloads void foo()
};
struct derived : base {
   void foo();         // overrides void base::foo()
   void foo(int);      // overloads void derived::foo()
                       // unrelated to void::base(int)
};
int main() {
   derived d;
   base & b = d;
   b.foo( 5 );   // calls void base::foo(int)
   b.foo();      // calls the final overrider for void base::foo()
                 // in this particular case void derived::foo()
   d.foo( 5 );   // calls void derived::foo(int)
}

Saturday, February 23, 2013

SQL: LIKE Condition


The SQL LIKE condition allows you to use wildcards in the SQL WHERE clause of an SQL statement. This allows you to perform pattern matching. The SQL LIKE condition can be used in any valid SQL statement - SQL SELECT statementSQL INSERT statementSQL UPDATE statement, or SQL DELETE statement.
The patterns that you can choose from are:
  • % allows you to match any string of any length (including zero length)
  • _ allows you to match on a single character

SQL LIKE Condition - Using % wildcard example

Let's explain how the % wildcard works in the SQL LIKE condition. We are going to try to find all of the suppliers whose name begins with 'Hew'.
SELECT * FROM suppliers
WHERE supplier_name like 'Hew%';
You can also using the % wildcard multiple times within the same string. For example,
SELECT * FROM suppliers
WHERE supplier_name like '%bob%';
In this SQL LIKE condition example, we are looking for all suppliers whose name contains the characters 'bob'.
You could also use the SQL LIKE condition to find suppliers whose name does not start with 'T'.
For example:
SELECT * FROM suppliers
WHERE supplier_name not like 'T%';
By placing the not keyword in front of the SQL LIKE condition, you are able to retrieve all suppliers whose name does not start with 'T'.

Normalization of Database.


Description of Normalization

Normalization is the process of organizing data in a database. This includes creating tables and establishing relationships between those tables according to rules designed both to protect the data and to make the database more flexible by eliminating redundancy and inconsistent dependency. 

Redundant data wastes disk space and creates maintenance problems. If data that exists in more than one place must be changed, the data must be changed in exactly the same way in all locations. A customer address change is much easier to implement if that data is stored only in the Customers table and nowhere else in the database. 

What is an "inconsistent dependency"? While it is intuitive for a user to look in the Customers table for the address of a particular customer, it may not make sense to look there for the salary of the employee who calls on that customer. The employee's salary is related to, or dependent on, the employee and thus should be moved to the Employees table. Inconsistent dependencies can make data difficult to access because the path to find the data may be missing or broken. 

There are a few rules for database normalization. Each rule is called a "normal form." If the first rule is observed, the database is said to be in "first normal form." If the first three rules are observed, the database is considered to be in "third normal form." Although other levels of normalization are possible, third normal form is considered the highest level necessary for most applications. 

As with many formal rules and specifications, real world scenarios do not always allow for perfect compliance. In general, normalization requires additional tables and some customers find this cumbersome. If you decide to violate one of the first three rules of normalization, make sure that your application anticipates any problems that could occur, such as redundant data and inconsistent dependencies. 

Thursday, February 21, 2013

Program to Convert timing from 12 - 24 hours and vice versa in CPP


#include<iostream.h>
#include<conio.h>
int flag=0;

class tw4;
class tw2
{
private:
int hrs,secs,mins;
public:
tw2(int hr,int min,int sec)
{
hrs=hr;
mins=min;
secs=sec;
}
friend void conv(tw2 t1,tw4 t2);

};
class tw4
{
private:
int hrs,secs,mins;
public:
tw4(int hr,int min,int sec)
{
hrs=hr;
mins=min;
secs=sec;
}
friend void conv(tw2 t1,tw4 t2);

};
void conv(tw2 t1,tw4 t2)
{
if(t1.hrs<12)
{
if(flag==1)
{
goto print;
}
t1.hrs=t1.hrs+12;

print:
cout<<"Convertes time is > "<<t1.hrs<<":"<<t1.mins<<":"<<t1.secs;
}
else
{
t2.hrs=t2.hrs-12;
cout<<"Convertes time is > "<<t2.hrs<<":"<<t2.mins<<":"<<t2.secs;
}
}

void main()
{

int sec=0,min=0,hr=0;
clrscr();
cout<<"Enter the Time in format (hrs:mins:sec)";
cin>>hr>>min>>sec;
cout<<"1.am\n2.pm";
cin>>flag;

tw2 t1(hr,min,sec);
tw4 t2(hr,min,sec);
conv(t1,t2);
getch();

}

//OUTPUT



Wednesday, February 13, 2013

Project on ATM machine working in CPP

/*program of ATM machine working....*/

#include<string.h>
#include<iostream.h>
#include<conio.h>
class Atm               //classname......//
{
int choice,i;
float b,c;
char str[7];
public:
void get();              //function declaration.....//
};
void Atm::get()
{
cout<<"\tEnter Your Password: ";         //ATM  password(ABCDE)...//
for(i=0;i<=4;i++)
{
str[i]=getch();
cout<<"*";
}
str[i]='\0';
if(strcmp(str,"ABCDE")==0)
{
float a=30000;                         //ATM's front page....//
cout<<endl<<endl<<"\t** WELCOME TO SBI **"<<endl<<endl;
cout<<" \tHello Mr.Chinmay Mahajan\t"<<endl<<endl<<endl;
cout<<"\t1.Information.\t2.Balance enquiry.";
cout<<endl<<endl<<"\t3.Withdrawal\t4.Quit";
cout<<endl<<endl<<endl<<"\t-->please select your choice:";
cin>>choice;
switch(choice)
{
case 1:
cout<<endl<<endl<<"\tName-Chinmay Mahajan"<<endl<<endl;
cout<<"\t Account no.-0181cs081059"<<endl<<endl<<"\tBranch name-Bhopal";
cout<<endl<<endl<<"\tYour main balance is:"<<a<<endl<<endl<<endl<<"\t\tThank U";
break;
case 2:
cout<<endl<<"\tYour balance is: "<<a<<endl<<endl<<endl<<"\t  Thank U  ";
break;
case 3:
cout<<endl<<"\t your balance is: "<<a<<endl;
cout<<endl<<"\t Please enter your amount:";
cin>>b;
if(b>a)
{
cout<<endl<<endl<<"\tyou have not sufficient balance";
goto out;
}
else
{
c=a-b;
cout<<endl<<endl<<"\tyou have withdrawn Rs. "<<b;
cout<<endl<<endl<<"\tYour balance now:"<<c<<endl<<endl<<"\tThank U";
break;
}
out:
default:
cout<<endl<<endl<<"\tThank U";
}
}
else
{
cout<<endl<<endl<<"\tPassword incorrect";
cout<<endl<<endl<<"\tThank U";
 }
}
void main()
{
clrscr();
Atm A;
A.get();
getch();
}