Thursday, October 16, 2014

C++ Programs



The OOP with C++ is an introductory course to C++ and the best efforts have been taken cover most of the topics specified in the VTU curriculum.

The Notes of OOP with C++ for III Semester CSE/ISE of VTU may refer to the following link:
In case of mistakes, the author (i.e. myself) doesn't take sole loss incurred by any individual after referring to the documents, it is only for academic purposes the notes have been typed and consolidated in its present form, the further versions may be soon released based on the feedback obtained. Thank you and All the Best !.


Mail to get the C++ Notes to:     rajkumar.manju@gmail.com
C++ Lab Programs



Design, develop, and execute a program in C++ to create a class called DATE with methods to accept two valid dates in the form dd/mm/yy and to implement the following operations by overloading the operators + and -. After every operation the results are to be displayed by overloading the operator <<.
i. no_of_days = d1 – d2; where d1 and d2 are DATE objects, d1 >=d2 and no_of_days is an integer.
ii. d2 = d1 + no_of_days; where d1 is a DATE object and no_of_days is an integer.
                   
 


#include < iostream.h >
#include < stdlib.h >
#include < conio.h >
class date{
  int dd,mm,yy;
public:
  int leap;
  date(){dd=0;mm=0;yy=0;}
  date(int d,int m, int y){
    dd=d; mm=m;  yy=y;
    if(y%4==0 || y%400==0 && y%100!=0)
       leap=1;
    else
       leap=0;

    if(!leap && m==2 && d>28)
     {
       cout<<"Non leap year can't have more than 28 days...\n!!!error";
       getch();
       exit(0);
     }
    if(m>13)
     {
       cout<<"Month can't be greater than 12...\n!!!error";
       getch();
       exit(0);
     }
    if(d>get_month_days(m))
     {
       cout<<"Number of days exceeds in the month...\n!!!error";
       getch();
       exit(0);
     }
  }
  date operator+(int days);
  int operator-(date d);
  int get_month_days(int month);
  friend ostream& operator<<(ostream &out, date &d);
};

date date::operator+(int days)
{
 int i;
 for(i=1;i<=days;i++)
 {
  dd++;
  if(dd>get_month_days(mm) && mm<13 br="">   {
     mm++;
     if (mm==13) {mm=1; yy++;}
     dd=1;
   }
 }
 return *this;
}

int date::operator-(date d2)
{
  int diff=0, mon_days,month;
  if(yy   {
    cout<<"Not possible to find the difference\nSecond date is greater\n";
    return -1;
   }
  int diff=0;
  while(dd!=d2.dd || mm!=d2.mm || yy!=d2.yy)
  {
   d2.dd++;
   if(d2.dd>get_month_days(d2.mm) && d2.mm<13 br="">    {
     d2.mm++;        //incr month if days crosses the no. of days of the month
     if (d2.mm==13) {d2.mm=1; d2.yy++;}   
     d2.dd=1;                //reset days to 1 on incrementing month
    }
    diff++;
   }
return diff;
}

int date::get_month_days(int month)
{  int days;
   switch (month)
   {
    case 1: case 3: case 5: case 7: case 8: case 10: case 12:days=31; break;

    case 2:if(yy%4==0 || yy%400==0 && yy%100!=0)
         days=29;
       else
         days=28;
       break;
    case 4: case 6: case 9: case 11:days=30; break;
   }
   return days;
}
ostream& operator<<(ostream& out,date &d)
{
 out< return out;
}

int main()
{
 int no_of_days=0;
 int days=0;
 int day,mon,year;
 clrscr();
 cout<<"\nEnter the two dates in the format (dd mm yyyy)";
 cout<<"\nEnter first date:";
 cin>>day>>mon>>year;
 date d1(day,mon,year);
 cout<<"\nEnter the second date(less than first date):";
 cin>>day>>mon>>year;
 date d2(day,mon,year);
 cout<<"\nThe dates are:";
 cout< cout< no_of_days=d1-d2;
 cout<<"\nThe difference is :"< cout<<"\nEnter the no. of days to be added:";
 cin>>days;
 d1=d1+days;
 cout<<"\nThe new date is:";
 cout< getch();
return 0;
}



/*Design, develop, and execute a program in C++ to create a class called OCTAL, which has the
characteristics of an octal number.
Implement the following operations by writing an appropriate constructor and an overloaded operator +.
i. OCTAL h = x ; where x is an integer
ii. int y = h + k ; where h is an OCTAL object and k is an integer.
Display the OCTAL result by overloading the operator <<. Also display the values of h and y.
*/
#include < iostream >
#include < cmath >
using namespace std;
class OCTAL{
    int oct;
    int dec;
public:
    OCTAL(){
        oct=0;
        dec=0;
    }
    OCTAL(int n){
        oct = decimal_oct(n);
    }
    int decimal_oct(int);
    int octal_decimal(int);
    int operator+(int);
    friend ostream & operator<<(ostream& out,OCTAL Oct);
};


int OCTAL::decimal_oct(int n)
{
 int rem, i=1, octal=0;
    while (n!=0)            //decimal to octal
    {
        rem=n%8;
        n/=8;
        octal+=rem*i;
        i*=10;
    }
   return octal;
}

int OCTAL::octal_decimal(int n) /* Function to convert octal to decimal */
{
    int decimal=0, i=0, rem;
    while (n!=0)
    {
        rem = n%10;
        n/=10;
        decimal += rem*pow(8,i);
        ++i;
    }
    return decimal;
}

int OCTAL :: operator+(int k)
{
    dec = octal_decimal(oct);
    return (dec+k);
}

ostream & operator <<(ostream &out, OCTAL O)
{
    out<    return out;
}
int main()
{
    int x,k,y;
    cout<<"\nEnter the value of x:";
    cin>>x;

    OCTAL h=x;  //invokes the single parameterized constructor
    cout<<"\nThe output of h=x in octal is:"<
    cout<<"\nEnter the value of k:";
    cin>>k;

    y=h+k;      //invokes the operator +() overloaded function
    cout<<"The output of y=h+k in octal is:"<
    return 0;
}






Design, develop, and execute a program in C++ to create a class called BIN_TREE that represents a Binary Tree, with member functions to perform inorder, preorder and postorder traversals. Create a BIN_TREE object and demonstrate the traversals.


#include < iostream >
#include < cstdlib >
using namespace std;
class TREE
{
 public:
    int data;
    TREE *left;
    TREE *right;
};
class BIN_TREE
{
    TREE *tree;
    public:
        BIN_TREE()
        {
            tree=NULL;
        }
        void insert(int);
        void inorder(TREE *tree);
        void preorder(TREE *tree);
        void postorder(TREE *tree);
        TREE *tree_ret()
        {
            return tree;
        }
};
void BIN_TREE::insert(int item)
{
    TREE *cur,*prev,*temp;
    temp=new TREE;
    temp->data=item;
    temp->left=temp->right=NULL;
    if(tree==NULL)
    tree=temp;
    else
    {
        prev=NULL;
        cur=tree;
        while(cur!=NULL)
        {
            prev=cur;
            if(item
< temp->data)
              cur=cur->left;
            else
              cur=cur->right;
        }
        if(item < temp->data)
          prev->left=temp;
        else
          prev->right=temp;
    }
}
void BIN_TREE::inorder(TREE *tree)
{
    TREE *temp;
    temp=tree;
    if(temp!=NULL)
    {
        inorder(temp->left);
        cout<data<<"\t";
        inorder(temp->right);
    }
}
void BIN_TREE::preorder(TREE *tree)
{
    TREE *temp;
    temp=tree;
    if(temp!=NULL)
    {
        cout<data<<"\t";
        preorder(temp->left);
        preorder(temp->right);
    }
}
void BIN_TREE::postorder(TREE *tree)
{
    TREE *temp;
    temp=tree;
    if(temp!=NULL)
    {
        postorder(temp->left);
        postorder(temp->right);
        cout<data<<"\t";
    }
}

int main()
{
    BIN_TREE BT;
    TREE *tree;
    int ch;
    int item;
    while(1)
    {
        cout<<"\n 1.insert \n 2.display \n3.exit";
        cout<<"\n enter the choice";
        cin>>ch;
        switch(ch)
        {
            case 1:
                cout<<"enter data to insert";
                cin>>item;
                BT.insert(item);
                break;
            case 2:
                cout<<"the contents of BT\n";
                cout<<"\ninorder\n";
                tree=BT.tree_ret();
                BT.inorder(tree);
                cout<<"\npreorder\n";
                tree=BT.tree_ret();
                BT.preorder(tree);
                cout<<"\npostorder\n";
                tree=BT.tree_ret();
                BT.postorder(tree) ;
            break;
            default:
                exit(0);
        }
    }
return 0;
}

Friday, January 29, 2010

EU clears Oracle's takeover of Sun



New York: The European Union's (EU) antitrust watchdog has approved the Sun-Oracle transaction last week saying the deal would not restrict competition in the database's market. In April last year, Oracle has agreed to buy Sun Microsystems for $7.4 billion or $9.50 a share in cash, reports PTI.

The approval from the EU came after months of investigation. Software major Oracle Corp has completed the takeover of hardware company Sun Microsystems for $7.4 billion. The deal, which was announced nine months ago, would transform the IT industry, Oracle said in a statement yesterday. The two companies, which have a significant presence in India, together employs more than 26,000 people in the country. Oracle has more than 25,000 employees in India, while Sun Microsystems has 1,200 people.

The Sun Solaris operating system is the leading platform for the Oracle database, Oracle's largest business. With the acquisition of Sun, Oracle can optimise Oracle database for some of the unique, high-end features of Solaris.

"With the addition of servers, storage, SPARC processors, the Solaris operating system, Java, and the MySQL database to Oracle's portfolio of database, middleware, and business applications, we plan to engineer and deliver open and integrated systems - from applications to disk - where all the pieces fit and work together out of the box," Oracle said.

Sunday, December 13, 2009

Database Management Systems

Hi all,
The main purpose of the blog is to create a lot of interests in the students to try and solve the problems involved in DBMS at undergraduate level as well post graduate