Tuesday, 18 October 2016

5exceptionB1_1476775079740


#include <iostream>
#include <string.h>
using namespace std;
class data
{
    int age;
    string city;
    double income;
    char fw;
    int c=0;
public:
    void getage()
    {
        try
        {
            cout<<"Enter age:"<<endl;
            cin>>age;
            if(age<18||age>55)
                throw(age);
            else
                c++;
        }
        catch(int i)
        {
            cout<<"Exception caught: Age should be between 18-55 years"<<endl;
        }
    }
    void getcity()
    {
        try
        {
            cout<<"Enter the city you live in:"<<endl;
            cin>>city;
            if(city=="Pune"||city=="Mumbai"||city=="Bangalore"||city=="Chennai")
                c++;
            else
                throw(city);
        }
        catch(string s)
        {
            cout<<"Exception caught: City should be either Pune, Mumbai, Bangalore or Chennai"<<endl;
        }
    }
    void getincome()
    {
        try
        {
            cout<<"Enter monthly income:"<<endl;
            cin>>income;
            if(income<50000||income>100000)
                throw(income);
            else
                c++;
        }
        catch(double d)
        {
            cout<<"Exception caught:Income should be between Rs. 50,000- Rs. 1,00,000"<<endl;
        }
    }
    void fourw()
    {
        try
        {
            cout<<"Do you have a four wheeler? Y or N"<<endl;
            cin>>fw;
            if(fw=='y'||fw=='Y')
                c++;
            else
                throw(fw);
        }
        catch(char w)
        {
            cout<<"Exception caught: 4 wheeler not present"<<endl;
        }
    }
    void print()
    {
        if(c==4)
            cout<<"No incorrect data provided, thenks";
    }
};
int main()
{
    data obj;
    obj.getage();
    obj.getincome();
    obj.getcity();
    obj.fourw();
    obj.print();
    return 0;
}

/*Output:
[student@localhost ~]$ g++ age.cpp
[student@localhost ~]$ ./a.out
Enter age:
22
Enter monthly income:
15000
Exception caught:Income should be between Rs. 50,000- Rs. 1,00,000
Enter the city you live in:
Pune
Do you have a four wheeler? Y or N
N
Exception caught: 4 wheeler not present
[student@localhost ~]$ ./a.out
Enter age:
22
Enter monthly income:
15000
Exception caught:Income should be between Rs. 50,000- Rs. 1,00,000
Enter the city you live in:
Pune
Do you have a four wheeler? Y or N
Y
[student@localhost ~]$ /*

searching and sorting of detail_1476775079695



/*Write C++ program using STL for Sorting and searching with user-defined records such as Person Record (Name, birth date, telephone no), item record (item code, item name, quantity and cost)*/    


#include <iostream>
#include<list>
using namespace std;
class record
{
    list<string>name,dob,phone,ni;
    list<string>::iterator it1,it2,it3,j,k,l,c,n;
    list<string>code;
    list<int>number;
    list<float>cost;
    list<int>::iterator no,j1;
    list<float>::iterator f,i;
public:
    void getp();
    void display();
    void searchp(string);
    void sortp();
    void checkempty();
    void getlist();
    void displayit();
    void searchlist();
    void sortitem();

};
void record::getp()
{
    int count;
    string n,d,p;
    cout<<"Enter the number of members in record:"<<endl;
    cin>>count;
    for(int i=1;i<=count;i++)
    {
        cout<<"Enter name:"<<endl;
        cin>>n;
        name.push_back(n);
        cout<<"Enter date of birth:"<<endl;
        cin>>d;
        dob.push_back(d);
        cout<<"Enter phone number:"<<endl;
        cin>>p;
        phone.push_back(p);
    }
}
void record::searchp(string data)
{
    int flag=0;
    it1=name.begin();
    it2=dob.begin();
    it3=phone.begin();
    while(it1!=name.end()&&it2!=dob.end()&&it3!=phone.end())
    {
        if(*it1==data)
        {
            cout<<"Record found!"<<endl;
            cout<<"Corresponding D.O.B: "<<*it2<<endl;
            cout<<"Corresponding phone number: "<<*it3<<endl;
            flag=1;
            break;
        }
        if(*it2==data)
        {
            cout<<"Record found!"<<endl;
            cout<<"Corresponding name "<<*it1<<endl;
            cout<<"Corresponding phone number: "<<*it3<<endl;
            flag=1;
            break;
        }
        if(*it3==data)
        {
            cout<<"Record found!"<<endl;
            cout<<"Corresponding name: "<<*it1<<endl;
            cout<<"Corresponding D.O.B: "<<*it2<<endl;
            flag=1;
            break;
        }
        it1++;
        it2++;
        it3++;
    }
    if(flag==0)
        cout<<"Record not found."<<endl;
}
void record:: display()
{
    it1=name.begin();
    it2=dob.begin();
    it3=phone.begin();
    while(it1!=name.end())
    {
        cout<<*it1<<"\t"<<*it2<<"\t"<<*it3<<endl;
        it1++;
        it2++;
        it3++;
    }
}
void record::sortp()
{
    string temp;
    it1=name.begin();
    it2=dob.begin();
    it3=phone.begin();
    j=it1;
    k=it2;
    l=it3;
    j++;
    k++;
    l++;
    while(it1!=name.end())
    {
        while(j!=name.end())
        {
            if(*it1>*j)
            {
                temp=*it1;
                *it1=*j;
                *j=temp;
                temp=*it2;
                *it2=*k;
                *k=temp;
                temp=*it3;
                *it3=*l;
                *l=temp;
            }
            j++;
            k++;
            l++;
        }
        it1++;
        it2++;
        it3++;
    }
}
void record::getlist()
{
    cout<<"Enter the number of items:"<<endl;
    int c,no;
    string n;
    float f;
    cin>>c;
    for(int i=1;i<=c;i++)
    {
        cout<<"Enter item name:"<<endl;
        cin>>n;
        ni.push_back(n);
        cout<<"Enter item code:"<<endl;
        cin>>n;
        code.push_back(n);
        cout<<"Enter cost:"<<endl;
        cin>>f;
        cost.push_back(f);
        cout<<"Enter the quantity:"<<endl;
        cin>>no;
        number.push_back(no);
    }
}
void record::displayit()
{
    c=code.begin();
    n=ni.begin();
    no=number.begin();
    f=cost.begin();
    while(c!=code.end())
    {
        cout<<*c<<"\t"<<*n<<"\t"<<*no<<"\t"<<*f<<endl;
        c++;
        n++;
        no++;
        f++;
    }
}
void record::sortitem()
{
    string temp;
    int tempno;
    float tempf;
    c=code.begin();
    n=ni.begin();
    no=number.begin();
    f=cost.begin();
    i=f;
    j1=no;
    k=c;
    l=n;
    i++;
    j1++;
    k++;
    l++;
    while(f!=cost.end())
    {
        while(i!=cost.end())
        {
            if(*f>*i)
            {
               tempf=*f;
               *f=*i;
               *i=tempf;

               temp=*n;
               *n=*l;
               *l=temp;

               temp=*c;
               *c=*k;
               *k=temp;

               tempno=*no;
               *no=*j1;
               *j1=tempno;
            }
            i++;
            j1++;
            k++;
            l++;
        }
        f++;
        n++;
        no++;
        c++;
    }
}
void record::searchlist()
{
    string key;
    cout<<"Enter the item code:"<<endl;
    cin>>key;
    c=code.begin();
    n=ni.begin();
    no=number.begin();
    f=cost.begin();
    while(c!=code.end())
    {
        if(key==*c)
        {
            cout<<"Item available!"<<endl;
            cout<<"Item name: "<<*n<<endl;
            cout<<"Item quantity: "<<*no<<endl;
            cout<<"Item cost: "<<*f<<endl;
        }
        c++;
        n++;
        no++;
        f++;
    }
}
int main()
{
    record obj;
    string key;
    int ch,chr;
    char x='y';
    do
    {
    cout<<"1. Personal record\n2. Item record\nEnter choice:\n";
    cin>>ch;
    do
    {
    if(ch==1)
    {
        cout<<"1. Enter details\n2. Display\n3. Search entry\n4. Sort records\nEnter choice\n";
        cin>>chr;
        switch(chr)
        {
        case 1:
            obj.getp();
            obj.display();
            break;
        case 2:
            obj.display();
            break;
        case 3:
            cout<<"Enter either name, d.o.b or phone number you want to find\n";
            cin>>key;
            obj.searchp(key);
            break;
        case 4:
            obj.sortp();
            obj.display();
            break;
        default:
            cout<<"Wrong choice"<<endl;
        }
    }
    else if(ch==2)
    {
        cout<<"1. Enter details\n2. Display\n3. Search entry\n4. Sort records\nEnter choice\n";
        cin>>chr;
        switch(chr)
        {
        case 1:
            obj.getlist();
            obj.displayit();
            break;
        case 2:
            obj.displayit();
            break;
        case 3:
            obj.searchlist();
            break;
        case 4:
            obj.sortitem();
            obj.displayit();
            break;
        default:
            cout<<"Wrong choice"<<endl;
        }
    }
    else
    {
        cout<<"Wrong choice"<<endl;
        break;
    }
    cout<<"Do you wish to continue? Y or N\n";
    cin>>x;
    }while(x=='y'||x=='Y');
    cout<<"Do you wish to select another type of record? Y or N\n";
    cin>>x;
    }while(x=='y'||x=='Y');
    return 0;
}

/*Output:
[student@localhost ~]$ g++ C3.cpp
[student@localhost ~]$ ./a.out
1. Personal record
2. Item record
Enter choice:
1
1. Enter details
2. Display
3. Search entry
4. Sort records
Enter choice
1
Enter the number of members in record:
2
Enter name:
abc
Enter date of birth:
5/6/1993
Enter phone number:
22556
Enter name:
pqr
Enter date of birth:
9/7/1993
Enter phone number:
22076
abc    5/6/1993    22556
pqr    9/7/1993    22076
Do you wish to continue? Y or N
y
1. Enter details
2. Display
3. Search entry
4. Sort records
Enter choice
2
abc    5/6/1993    22556
pqr    9/7/1993    22076
Do you wish to continue? Y or N
y
1. Enter details
2. Display
3. Search entry
4. Sort records
Enter choice
3
Enter either name, d.o.b or phone number you want to find
abc
Record found!
Corresponding D.O.B: 5/6/1993
Corresponding phone number: 22556
Do you wish to continue? Y or N
y
1. Enter details
2. Display
3. Search entry
4. Sort records
Enter choice
4
abc    5/6/1993    22556
pqr    9/7/1993    22076
Do you wish to continue? Y or N
n
Do you wish to select another type of record? Y or N
n
[student@localhost ~]$ */

calculatorA3_1476775079738


\\Program for Calculator for arithmatic operation.
#include<iostream>
using namespace std;
class Calculator
{
   private:
   float num1,num2,result;
   char op;
   public:
   void get();
   void calculate();
};
void Calculator::get()
{
   cout<<"\n Enter first number,operator & second number";
   cin>>num1;
   cin>>op;
   cin>>num2;
}
void Calculator::calculate()
{
   switch(op)
   {
      case '+':
      result=num1+num2;
      break;  
      case '-':
      result=num1-num2;
      break;  
      case '*':
      result=num1*num2;
      break;  
      case '/':
      if(num2==0)
      cout<<"\n Error. Not valid.";
      result=num1/num2;
      break;
   }
   cout<<" "<<num1<<" "<<op<<" "<<num2<<" = "<<result;
}
int main()
{
   char ag;
   Calculator obj;
 x:obj.get();
   obj.calculate();
   cout<<"\n Do you want to perform another operation? y/n";
   cin>>ag;
   if(ag=='y'||ag=='Y')
   goto x;
   return 0;
}      
   
Output:
[student@localhost ~]$ g++ Calculator1.cpp
[student@localhost ~]$ ./a.out

 Enter first number,operator & second number 5+2
 5 + 2 = 7
 Do you want to perform another operation? y/n y

 Enter first number,operator & second number 7-3
 7 - 3 = 4
 Do you want to perform another operation? y/n y

 Enter first number,operator & second number 90*5
 90 * 5 = 450
 Do you want to perform another operation? y/n y

 Enter first number,operator & second number 60/20
 60 / 20 = 3
 Do you want to perform another operation? y/n n
[student@localhost ~]$
 

11dqueuestl_1476775079724

//  Write C++ program using STL for Dqueue (Double ended queue)

#include<iostream>
#include<string.h>
#include<deque>
using namespace std;

class Dequeue
{
    public :
        int a;
        deque <int> s;
        deque <int> :: iterator itr;


        void push_front()
        {
            cout<<"\n Enter a number : ";
                cin>>a;
                s.push_front(a);
        }

        void push_back()
        {
             cout<<"\n Enter a number : ";
             cin>>a;
             s.push_back(a);
        }

        void pop_back()
        {
            itr=s.end();
            itr--;
            s.pop_back();
            cout<<"\n The element popped out of the queue is "<<*itr;
        }

        void pop_front()
        {
            itr=s.begin();
            s.pop_front();
            cout<<"\n The element popped out of the queue is "<<*itr;
        }

        void displayqueue()
        {
                cout<<"\n The elements in the queue are : "<<"\n";
                for(itr=s.begin() ; itr!=s.end() ; itr++)
            {
                cout<<*itr<<"\t";
            }
        }

};

int main()
{
    Dequeue p;
    int choice;
    char ans;
    do
    {
        cout<<"\n 1. Add element from front \n 2. Add element from behind \n 3. Delete element front front \n 4. Delete element from behind \n 5. Display dequeue elements";
        cout<<"\n Enter the operation you want to perform : ";
        cin>>choice;
        switch(choice)
        {
            case 1 : p.push_front();
            break;
            case 2 : p.push_back();
            break;
            case 3 : p.pop_front();
            break;
            case 4 : p.pop_back();
            break;
            case 5 : p.displayqueue();
            break;
        }
        cout<<"\n Do you want to perform any other operation ?";
        cin>>ans;
    }while(ans=='Y' || ans=='y');
}

/*Output:
[student@localhost ~]$ g++ C2deque.cpp
[student@localhost ~]$ ./a.out

 1. Add element from front
 2. Add element from behind
 3. Delete element front front
 4. Delete element from behind
 5. Display queue elements
 Enter the operation you want to perform : 1

 Enter a number : 5

 Do you want to perform any other operation ? y

 1. Add element from front
 2. Add element from behind
 3. Delete element front front
 4. Delete element from behind
 5. Display queue elements
 Enter the operation you want to perform : 5

 The elements in the queue are :
5   
 Do you want to perform any other operation ? y

 1. Add element from front
 2. Add element from behind
 3. Delete element front front
 4. Delete element from behind
 5. Display queue elements
 Enter the operation you want to perform : 2

 Enter a number : 6

 Do you want to perform any other operation ? y

 1. Add element from front
 2. Add element from behind
 3. Delete element front front
 4. Delete element from behind
 5. Display queue elements
 Enter the operation you want to perform : 5

 The elements in the queue are :
5    6   
 Do you want to perform any other operation ? y

 1. Add element from front
 2. Add element from behind
 3. Delete element front front
 4. Delete element from behind
 5. Display queue elements
 Enter the operation you want to perform : 3

 The element popped out of the queue is 5
 Do you want to perform any other operation ? y

 1. Add element from front
 2. Add element from behind
 3. Delete element front front
 4. Delete element from behind
 5. Display queue elements
 Enter the operation you want to perform : 4

 The element popped out of the queue is 6
 Do you want to perform any other operation ?n
[student@localhost ~]$ */

10binaryadditionc2_1476775079730

/*write c++ program using STL to add binary numbers(assume one bit as one number);use STL stack*/
#include<iostream>
#include<stack>
using namespace std;
int main()
{
int i;
stack<int> A;
stack<int> B;
stack<int> C;
char First_number[5],Second_number[5];
int a=0,b=0;
cout<<"\n Enter the First binary number";
cin>>First_number;
for(i=0;First_number[i]!='\0';i++)
{
if(First_number[i]=='0')
A.push(0);
else
A.push(1);
}
//A stack stores first binary number
cout<<"\nEnter the Second binary number";
cin>>Second_number;
for(i=0;Second_number[i]!='\0';i++)
{
if(Second_number[i]=='0')
B.push(0);
else
B.push(1);
}
//B satck stores second binary number
int carry=0;
while(!A.empty()||!B.empty())
{
a=0;b=0;
if(!A.empty())//length of first number is larger than second
{
a=A.top();
A.pop();
}
if(!B.empty())//length of second number is larger than first
{
b=B.top();
B.pop();
}
int sum=carry+a+b;//performing addition
C.push(sum%2);//pushing the result onto the third stack
carry=sum/2;//setting carry
}
if(carry==1)//if carry is there then
C.push(carry);//it is pushed at the end onto the stack
cout<<"\nAddition of two binary numbers is...";
while(!C.empty())//C stack is popped to display result
{
cout<<C.top();
C.pop();
}
cout<<"\n";
return 0;
}



/*output
[student@localhost ~]$ g++ assignment10.cpp
[student@localhost ~]$ ./a.out

 Enter the First binary number1101

Enter the Second binary number1100

Addition of two binary numbers is...11001 */



9stlstackc1_1476775079741


//  Write C++ program using STL for implementation of stack using SLL

#include<iostream>
#include<string.h>
#include<list>
using namespace std;

class Stack
{
    public :
        int a;
        list <int> s;
        list <int> :: iterator itr;


        void push()
        {
            cout<<"\n Enter a number : ";
                cin>>a;
                s.push_back(a);
        }

        void displaystack()
        {
            cout<<"\n The elements in the stack are : "<<"\n";
            for(itr=s.begin() ; itr!=s.end() ; itr++)
            {
                cout<<*itr<<"\t";
            }
        }

        void pop()
        {
            itr=s.end();
            itr--;
            s.pop_back();
            cout<<"\n The element popped out of the stack is "<<*itr;
        }

};

int main()
{
    Stack p;
    int choice;
    char ans;
    do
    {
        cout<<"\n 1. Add element \n 2. Delete element \n 3. Display stack elements";
        cout<<"\n Enter the operation you want to perform : ";
        cin>>choice;
        switch(choice)
        {
            case 1 : p.push();
            break;
            case 2 : p.pop();
            break;
            case 3 : p.displaystack();
            break;
        }
        cout<<"\n Do you want to perform any other operation ?";
        cin>>ans;
    }while(ans=='Y' || ans=='y');
}

/*Output:
[student@localhost ~]$ g++ C1stack.cpp
[student@localhost ~]$ ./a.out

 1. Add element
 2. Delete element
 3. Display stack elements
 Enter the operation you want to perform : 1

 Enter a number : 9

 Do you want to perform any other operation ? y

 1. Add element
 2. Delete element
 3. Display stack elements
 Enter the operation you want to perform : 1

 Enter a number : 70

 Do you want to perform any other operation ? y

 1. Add element
 2. Delete element
 3. Display stack elements
 Enter the operation you want to perform : 3

 The elements in the stack are :
9    70   
 Do you want to perform any other operation ?y

 1. Add element
 2. Delete element
 3. Display stack elements
 Enter the operation you want to perform : 2

 The element popped out of the stack is 70
 Do you want to perform any other operation ?n
[student@localhost ~]$  */

9stlqueuec1_1476775079750

// Write C++ program using STL for implementation of queue using SLL

#include<iostream>
#include<string.h>
#include<list>
using namespace std;

class Queue
{
    public :
        int a;
        list <int> s;
        list <int> :: iterator itr;


        void push()
        {
            cout<<"\n Enter a number : ";
                cin>>a;
                s.push_back(a);
        }

        void displaystack()
        {
            cout<<"\n The elements in the queue are : "<<"\n";
            for(itr=s.begin() ; itr!=s.end() ; itr++)
            {
                cout<<*itr<<"\t";
            }
        }

        void pop()
        {
            itr=s.begin();
            s.pop_front();
            cout<<"\n The element popped out of the queue is "<<*itr;
        }

};

int main()
{
    Queue p;
    int choice;
    char ans;
    do
    {
        cout<<"\n 1. Add element \n 2. Delete element \n 3. Display queue elements";
        cout<<"\n Enter the operation you want to perform : ";
        cin>>choice;
        switch(choice)
        {
            case 1 : p.push();
            break;
            case 2 : p.pop();
            break;
            case 3 : p.displaystack();
            break;
        }
        cout<<"\n Do you want to perform any other operation ?";
        cin>>ans;
    }while(ans=='Y' || ans=='y');
}

/*Output:
[student@localhost ~]$ g++ C1.cpp
[student@localhost ~]$ ./a.out

 1. Add element
 2. Delete element
 3. Display queue elements
 Enter the operation you want to perform : 1

 Enter a number : 6

 Do you want to perform any other operation ? y

 1. Add element
 2. Delete element
 3. Display queue elements
 Enter the operation you want to perform : 1

 Enter a number : 8

 Do you want to perform any other operation ? y

 1. Add element
 2. Delete element
 3. Display queue elements
 Enter the operation you want to perform : 3

 The elements in the queue are :
6    8   
 Do you want to perform any other operation ? y

 1. Add element
 2. Delete element
 3. Display queue elements
 Enter the operation you want to perform : 2

 The element popped out of the queue is 6
 Do you want to perform any other operation ?n
[student@localhost ~]$ */

8telephoneB4-1_1476775079732

#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<cstring>

using namespace std;
class telephone
{
    char name[20];
        int number;
public:
    void accept()
    {
          cout<<"Enter the name and telephone number:";         
          cin>>name;
          cin>>number;
        }
      void display()
      {
          cout<<"\n"<<name<<"\t"<<number;         
       }
     int search1(int num)
     {
      if(number==num)
       {
         cout<<"\n Record found";
         cout<<"\n"<<name<<"\t"<<number;
         return 1;
      }       
     else
          return 0;
    }


int serach(char n[])
{  
  if(!strcmp(name,n))
       {
         cout<<"\n Record found";
         cout<<"\n"<<name<<"\t"<<number;
         return 1;
      }    
   else
         return 0;
}

};

int main()
{
   telephone t;
   fstream file;
   int ch,i,n,flag;
   int number;
   char name[100];

while(1)
 {
   cout<<"\n1.Enter information";
   cout<<"\n2.Display information";     
   cout<<"\n3.Search using number";     
   cout<<"\n4.Search using name";
   cout<<"\n5.Exit";
   cout<<"\n Enter your choice:";
   cin>>ch;
              switch(ch)
        {
        case 1:
            file.open("number.txt",ios::out);
            cout<<"\n How many number wanted to add:";
                        cin>>n;
                   for(i=0;i<n;i++)
                      {
                         t.accept();
                         file.write((char*)&t,sizeof(t));
                       }
                     file.close();
                  break;
        case 2:
            file.open("number.txt",ios::in);
            cout<<"\n Telephone information is:";
                        while(file)
                         {
                            file.read((char*)&t,sizeof(t));                         
                             t.display();
                          }
                     file.close();
                  break;
                case 3:
            file.open("number.txt",ios::in);
            cout<<"\n Enter number you want to search: ";
                        cin>>number;
                        flag=0;                       
                      while(file)
                         {
                            file.read((char*)&t,sizeof(t));                         
                             if(t.search1(number))
                              {
                                 flag=1;
                                  break;
                               }
                         }
                         if(flag==0)                    
                       cout<<"\n Record not found: ";
            file.close();
                        break;
        case 4:
            file.open("number.txt",ios::in);
            cout<<"\n Enter name you want to search: ";
                        cin>>name;
                        flag=0;                       
                      while(file)
                         {
                            file.read((char*)&t,sizeof(t));                         
                             if(t.serach(name))
                              {
                                 flag=1;
                                  break;
                               }
                         }
                         if(flag==0)                    
                       cout<<"\n Record not found: ";
            file.close();
                        break;
           
        case 5:
            exit(0);
        }
    }

          return 0;
   }















8telephoneB4_1476775079728

#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<cstring>

using namespace std;
class telephone
{
    char name[20];
        int number;
public:
    void accept()
    {
          cout<<"Enter the name and telephone number:";         
          cin>>name;
          cin>>number;
        }
      void display()
      {
          cout<<"\n"<<name<<"\t"<<number;         
       }
     int search1(int num)
     {
      if(number==num)
       {
         cout<<"\n Record found";
         cout<<"\n"<<name<<"\t"<<number;
         return 1;
      }       
     else
          return 0;
    }


int serach(char n[])
{  
  if(!strcmp(name,n))
       {
         cout<<"\n Record found";
         cout<<"\n"<<name<<"\t"<<number;
         return 1;
      }    
   else
         return 0;
}

};

int main()
{
   telephone t;
   fstream file;
   int ch,i,n,flag;
   int number;
   char name[100];

while(1)
 {
   cout<<"\n1.Enter information";
   cout<<"\n2.Display information";     
   cout<<"\n3.Search using number";     
   cout<<"\n4.Search using name";
   cout<<"\n5.Exit";
   cout<<"\n Enter your choice:";
   cin>>ch;
              switch(ch)
        {
        case 1:
            file.open("number.txt",ios::out);
            cout<<"\n How many number wanted to add:";
                        cin>>n;
                   for(i=0;i<n;i++)
                      {
                         t.accept();
                         file.write((char*)&t,sizeof(t));
                       }
                     file.close();
                  break;
        case 2:
            file.open("number.txt",ios::in);
            cout<<"\n Telephone information is:";
                        while(file)
                         {
                            file.read((char*)&t,sizeof(t));                         
                             t.display();
                          }
                     file.close();
                  break;
                case 3:
            file.open("number.txt",ios::in);
            cout<<"\n Enter number you want to search: ";
                        cin>>number;
                        flag=0;                       
                      while(file)
                         {
                            file.read((char*)&t,sizeof(t));                         
                             if(t.search1(number))
                              {
                                 flag=1;
                                  break;
                               }
                         }
                         if(flag==0)                    
                       cout<<"\n Record not found: ";
            file.close();
                        break;
        case 4:
            file.open("number.txt",ios::in);
            cout<<"\n Enter name you want to search: ";
                        cin>>name;
                        flag=0;                       
                      while(file)
                         {
                            file.read((char*)&t,sizeof(t));                         
                             if(t.serach(name))
                              {
                                 flag=1;
                                  break;
                               }
                         }
                         if(flag==0)                    
                       cout<<"\n Record not found: ";
            file.close();
                        break;
           
        case 5:
            exit(0);
        }
    }

          return 0;
   }















7selectionsort by template_1476775079737

//selection using function templates

#include <iostream>
using namespace std;

template <class T>
void sort()
{
    int i, j;
    T temp;
    T n[5];
    cout<<"\n Enter five numbers : ";
    for(i=0;i<5;i++)
    {
        cin>>n[i];
    }
    for(i=0;i<4;i++)
    {
        for(j=i;j<5;j++)
        {
            if(n[i]>n[j])
            {
                temp=n[i];
                n[i]=n[j];
                n[j]=temp;
            }
        }
    }
    cout<<"\n The array in the sorted order is : "<<endl;
    for(i=0;i<5;i++)
    {
        cout<<"\t"<<n[i];
    }
}

int main()
{
    int choice;
    char ans;
    do
    {
        cout<<"\n 1. Integer  sort. \n 2. Float sort.";
        cout<<"\n Enter the input you want to sort : ";
        cin>>choice;
        switch(choice)
        {
            case 1 : sort<int>();
                     break;
            case 2 : sort<float>();
                     break;
            case 3 : cout<<"\n Invalid choice.";
                     break;
        }
        cout<<"\n Do u wish to continue (Y/N)?";
        cin>>ans;
    }while(ans=='Y' || ans=='y');
    return 0;
}

/*Output:
[student@localhost ~]$ g++ B2selectionsort.cpp
[student@localhost ~]$ ./a.out

 1. Integer  sort.
 2. Float sort.
 Enter the input you want to sort : 1

 Enter five numbers : 70
90
1
5
60

 The array in the sorted order is :
    1    5    60    70    90
 Do u wish to continue (Y/N)?y

 1. Integer  sort.
 2. Float sort.
 Enter the input you want to sort : 2

 Enter five numbers : 2.6
5.9
2.1
4.7
5.3

 The array in the sorted order is :
    2.1    2.6    4.7    5.3    5.9
 Do u wish to continue (Y/N)?n
[student@localhost ~]$   */

6fileB2_1476775079727

/*write c++ program that create an output file,write information to it,close the file and open it again as an input file and read the information from the file*/

#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
const int MAX=10;
int array1[MAX]={10,20,30,40,50};
int array2[MAX];
int main()
{
ofstream os;//create output stream
os.open("test.txt",ios::trunc | ios::binary);//opening file
if(!os)
{
   cerr<<"could not open output file\n";//error handling
   exit(1);
}
cout<<"writing the content to the file...\n\n";
os.write((char*)&array1,sizeof(array1));//writing 'array1'to file
if(!os)
{
   cerr<<"could not write to file\n";//error handling
   exit(1);
}
os.close();//close the file
ifstream is;//create input stream for reading the content from file
is.open("test.txt",ios::binary);
if(!is)
{
   cerr<<"could not open input file\n";//error handling
   exit(1);
}
cout<<"reading the content from the file....\n";
is.read((char*)&array2,sizeof(array2));//reading the content in
                                       //another array 'array2'
if(!is)
{
   cerr<<"could not read from file\n";//error handling
   exit(1);
}
for(int j=0;j<MAX;j++)//check data
   cout<<" "<<array2[j];
 return 0;
}


/*output
 [student@localhost ~]$ g++ file.cpp
[student@localhost ~]$ ./a.out
writing the content to the file...

reading the content from the file....
 10 20 30 40 50 0 0 0 0 0[student@localhost ~]$ */







4employeedetailA5_1476775079726

\\Program for Employee details.
#include <iostream>
using namespace std;

class personal
{
    string name,address,dob,email,mob;
public:
    void accept()
    {
    cout<<"Enter your name\n";
    getline(cin,name);

    cout<<"Enter your address\n";
    getline(cin,address);

    cout<<"Enter your date of birth (Format - > 11/10/1988)\n";
    getline(cin,dob);

    cout<<"Enter your E-mail\n";
    getline(cin,email);

    cout<<"Enter your mobile number\n";
    getline(cin,mob);
    }

    void display()
    {
        cout<<"Name          : "<<name<<endl;
        cout<<"Address       : "<<address<<endl;
        cout<<"DOB           : "<<dob<<endl;
        cout<<"E-mail        : "<<email<<endl;
        cout<<"Mobile number : "<<mob<<endl;
    }
};

class professional
{
    string emp_id,sal,xp,dept,doj;
public:
    void accept1()
    {
        cout<<"Enter your Employee ID\n";
        getline(cin,emp_id);

        cout<<"Enter your salary\n";
        getline(cin,sal);

        cout<<"Enter your date of joining (Format - > 1/1/2011)\n";
        getline(cin,doj);

        cout<<"Enter your department\n";
        getline(cin,dept);

        cout<<"Enter your experience\n";
        getline(cin,xp);
    }

    void display1()
    {
        cout<<"Employee ID   : "<<emp_id<<endl;
        cout<<"Salary        : "<<sal<<endl;
        cout<<"DOJ           : "<<doj<<endl;
        cout<<"Department    : "<<dept<<endl;
        cout<<"Experience    : "<<xp<<endl;
    }
};

class academic: public personal , public professional
{
    int ten,twel;
public:
    void accept2()
    {
        cout<<"Enter your 10th grade marks (Total out of 800)\n";
        cin>>ten;
        cout<<"Enter your 12th grade marks (Total out of 800)\n";
        cin>>twel;
    }

    void display2()
    {
        cout<<"10th marks    : "<<ten<<endl;
        cout<<"12th marks    : "<<twel<<endl;
    }
};

int main()
{
    academic a1;
    a1.accept();
    a1.accept1();
    a1.accept2();
    cout<<"The biodata has been created\n\n";
    a1.display();
    a1.display1();
    a1.display2();
    return 0;
}


/*Output:

[student@localhost ~]$ g++ inharitance.cpp
[student@localhost ~]$ ./a.out
Enter your name
sumit
Enter your address
pune
Enter your date of birth (Format - > 11/10/1988)
5/6/1996
Enter your E-mail
abc@gmail.com
Enter your mobile number
8877556612
Enter your Employee ID
2159
Enter your salary
40000
Enter your date of joining (Format - > 1/1/2011)
9/6/2015
Enter your department
Comp
Enter your experience
10
Enter your 10th grade marks (Total out of 800)
86
Enter your 12th grade marks (Total out of 800)
85
The biodata has been created

Name          : sumit
Address       : pune
DOB           : 5/6/1996
E-mail        : abc@gmail.com
Mobile number : 8877556612
Employee ID   : 2159
Salary        : 40000
DOJ           : 9/6/2015
Department    : Comp
Experience    : 10
10th marks    : 86
12th marks    : 85
[student@localhost ~]$ */

3studentdatabaseA4_1476775079721

\\Program for Student Database.
#include <iostream>
using namespace std;
class data
{
private:
     string name;
     char bg;
     string address;
     string dob;
     string cldiv;
     string lic;
     static int c;
     int roll;
     long int phone;
public:
    data();
    static int getcount();
    void getdata();
    void show();
    data(data *obj);
    data(int roll,long int phone,string name,string address,string dob,string cldiv, string lic);
    ~data();
};              
  int data::c=0;
  data::data(data *obj)
  {
      cout<<"Copy constructor implemented"<<endl;
  }
  data::~data()
  {
      cout<<"Destructor called \n";
  }
 void data::getdata()
 {
          cout<<"Enter roll number \n";
          cin>>roll;
          cout<<"Enter telephone number \n";
          cin>>phone;
          cout<<"Enter Name \n";
         ws(cin);
          cin>>name;
         cout<<"Enter address \n";
         ws(cin);
         cin>>address;
         cout<<"Enter D.O.B \n";
         cin>>dob;
         cout<<"Enter Class and Division\n";
         ws(cin);
         cin>>cldiv;
         cout<<"Enter license number \n";
         cin>>lic;
 }
 void data::show()
 {
     cout<<"Name :"<<name<<endl;
     cout<<"Roll Number :"<<roll<<endl;
     cout<<"Telephone Number :"<<phone<<endl;
     cout<<"Address :"<<address<<endl;
      cout<<"Date of birth :"<<dob<<endl;
     cout<<"Class and division: "<<cldiv<<endl;
     cout<<"License number :"<<lic<<endl;
 }
 data::data(int roll,long int phone,string name,string address,string dob,string cldiv,string lic)
 {
     cout<<"Parameterized Constructor"<<endl;
     c++;
     this->roll=roll;
     this->phone=phone;
     this->name=name;
     this->address=address;
      this->dob=dob;
     this->cldiv=cldiv;
     this->lic=lic;
 }
 data::data()
 {
     roll=0;
     phone=0;
     name="Name";
     address="Address";
     dob="DOB";
     cldiv="Class and Division";
     lic="License no.";
     cout<<"Default Constructor"<<endl;
     c++;
 }
  int data::getcount()
 {
     return c;
 }
int main()
 {
    int num;
    data *d1= new data();
    d1->show();
    delete d1;
    data *d2=new data(23,9822794182,"Dhruvatara","Kalyani Nagar","22.02.97","SE A","MSIN92U");
    d2->show();
    data *d3=new data(d2);
    d3->show();
    delete d2;
    cout<<"Enter size of database";
    cin>>num;
    data dx[num];
    for(int i=0;i<num;i++)
    {
        dx[i].getdata();
    }
    for(int i=0;i<num;i++)
        {
            dx[i].show();
        }
    cout<<"Number of constructor calls and total number of objects:"<<data::getcount()<<endl;
    return 0;
}

/*Output:

[student@localhost ~]$ g++ student.cpp
[student@localhost ~]$ ./a.out
Default Constructor
Name :Name
Roll Number :0
Telephone Number :0
Address :Address
Date of birth :DOB
Class and division: Class and Division
License number :License no.
Destructor called
Parameterized Constructor
Name :Dhruvatara
Roll Number :23
Telephone Number :9822794182
Address :Kalyani Nagar
Date of birth :22.02.97
Class and division: SE A
License number :MSIN92U
Copy constructor implemented
Name :
Roll Number :0
Telephone Number :0
Address :
Date of birth :
Class and division:
License number :
Destructor called
Enter size of database 2
Default Constructor
Default Constructor
Enter roll number
1
Enter telephone number
9988777446
Enter Name
Yogita
Enter address
pune
Enter D.O.B
2/6/1996
Enter Class and Division
SE
Enter license number
2013456
Enter roll number
3
Enter telephone number
9966332211
Enter Name
ayush
Enter address
pune
Enter D.O.B
9/8/1996
Enter Class and Division
SE
Enter license number
778899456
Name :Yogita
Roll Number :1
Telephone Number :9988777446
Address :pune
Date of birth :2/6/1996
Class and division: SE
License number :2013456
Name :ayush
Roll Number :3
Telephone Number :9966332211
Address :pune
Date of birth :9/8/1996
Class and division: SE
License number :778899456
Number of constructor calls and total number of objects:4
Destructor called
Destructor called
[student@localhost ~]$*/



2A2cpparray_1476775079736

/*Implement a class CppArray which is identical to a one-dimensional C++ array (i.e.,
the index set is a set of consecutive integers starting at 0) except for the following :
1. It performs range checking.
2. It allows one to be assigned to another array through the use of the
assignment operator (e.g. cp1= cp2)
3. It supports a function that returns the size of the array.
4. It allows the reading or printing of array through the use of cout and cin.
*/
#include<iostream>
using namespace std;
class CppArray
{
   private:
   int a[10],i,j,n,b[10],temp;
   public:
   void get();
   void print();
   void sort();
   void range();
   void exchange();
   int size();
};
void CppArray::get()
{
   cout<<"\n Enter the limit of array ";
   cin>>n;
   cout<<"\n Enter the array elements ";
   for(i=0;i<n;i++)
   {
       cout<<"\n a["<<i<<"]=";
       cin>>a[i];
   }
}
void CppArray::print()
{
   cout<<"\n The entered array is ";
   for(i=0;i<n;i++)
   {
       cout<<"\n a["<<i<<"]="<<a[i];
   }
}
void CppArray::sort()
{
   for(j=0;j<n;j++)
   {
      for(i=0;i<n-1;i++)
      {
         if(a[i]>a[i+1])
         {
            temp=a[i+1];
            a[i+1]=a[i];
            a[i]=temp;
         }
      }
   }
   cout<<"\n The sorted array is ";
   for(i=0;i<n;i++)
   {
       cout<<"\n a["<<i<<"]="<<a[i];
   }
}
void CppArray::range()
{
   cout<<"\n The range of array is from "<<a[0]<<" to "<<a[n-1];
}
void CppArray::exchange()
{
   for(i=0;i<n;i++)
   {
       b[i]=a[i];
   }
   cout<<"\n The exchanged array is ";
   for(i=0;i<n;i++)
   {
       cout<<"\n b["<<i<<"]="<<b[i];
   }
}
int CppArray::size()
{
   return n;
}
int main()
{
   int a;
   CppArray obj;
   obj.get();
   obj.print();
   obj.range();
   obj.exchange();
   obj.sort();
   a=obj.size();
   cout<<"\n The size of array is "<<a;
   return 0;
}

/*Output:
[student@localhost ~]$ g++ Array.cpp
[student@localhost ~]$ ./a.out

 Enter the limit of array 5

 Enter the array elements
 a[0]=2

 a[1]=6

 a[2]=10

 a[3]=1

 a[4]=21

 The entered array is
 a[0]=2
 a[1]=6
 a[2]=10
 a[3]=1
 a[4]=21
 The range of array is from 2 to 21
 The exchanged array is
 b[0]=2
 b[1]=6
 b[2]=10
 b[3]=1
 b[4]=21
 The sorted array is
 a[0]=1
 a[1]=2
 a[2]=6
 a[3]=10
 a[4]=21
 The size of array is 5[student@localhost ~]$
*/

1complexA1_1476775079739


//Program for Complex number which represents the complex number data type.
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
class complex
{
float x;
float y;
public:
complex operator+(complex);
complex operator-(complex);
complex operator*(complex);
complex operator/(complex);
complex();
complex(float,float);
void display();
void getdata();
};
complex::complex()
{
x=0;
y=0;
}
complex::complex(float a,float b)
{
x=a;
y=b;
}
complex complex::operator+(complex c)
{
complex temp;
temp.x=x+c.x;
temp.y=y+c.y;
return(temp);
}
complex complex::operator-(complex c)
{
complex temp1;
temp1.x=x-c.x;
temp1.y=y-c.y;
return(temp1);

}
complex complex::operator*(complex c)
{
complex temp2;
temp2.x=(x*c.x)-(y*c.y);
temp2.y=(y*c.x)+(x*c.y);
return (temp2);
}

complex complex::operator /(complex c)
{
complex temp3;
temp3.x=((x*c.x)+(y*c.y))/((c.x*c.x)+(c.y*c.y));
temp3.y=((y*c.x)-(x*c.y))/((c.x*c.x)+(c.y*c.y));
return(temp3);
}
void complex::getdata()
{
cout<<"Enter the real part";
cin>>x;
cout<<"Enter the imaginary part";
cin>>y;
}
void complex::display()
{
cout<<x<<"+"<<y<<"i\n";
}
int main()
{
complex c1,c2,c3,c4,c5,c6;
cout<<"\n Enter the 1st number\n";
c1.getdata();
cout<<"\n Enter the 2nd number\n";
c2.getdata();
//c1=complex(2.5,3.5);
//c2=complex(1.6,2.7);
c3=c1+c2;
c4=c1-c2;
c5=c1*c2;
c6=c1/c2;
cout<<"\n The first number is ";
c1.display();
cout<<"\n The second number is ";
c2.display();
cout<<"\n The addition is ";
c3.display();
cout<<"\n The subtraction is ";
c4.display();
cout<<"\n The multiplication is ";
c5.display();
cout<<"\n The division is";
c6.display();
}

/*Output:
[student@localhost ~]$ g++ Complex.cpp
[student@localhost ~]$ ./a.out

 Enter the 1st number
Enter the real part 2
Enter the imaginary part3

 Enter the 2nd number
Enter the real part 4
Enter the imaginary part 5

 The first number is 2+3i

 The second number is 4+5i

 The addition is 6+8i

 The subtraction is -2+-2i

 The multiplication is -7+22i

 The division is0.560976+0.0487805i
[student@localhost ~]$
*/