Tuesday 9 December 2014

1. Create a class named weather report that holds a daily weather report with data members day_of_month,hightemp,lowtemp,amount_rain and amount_snow. The constructor initializes the fields with default values: 99 for day_of_month, 999 for hightemp,-999 for low emp and 0 for amount_rain and amount_snow. Include a function that prompts the user and sets values for each field so that you can override the default values. Write a C++/Java/Python program that creates a monthly report. a) Menu driven program with options to Enter data and Display report b) Report Format


/*Problem Statement: 

Create a class named weather report that holds a daily weather report with data members day_of_month,hightemp,lowtemp,amount_rain and amount_snow. The constructor initializes the fields with default values: 99 for day_of_month, 999 for hightemp,-999 for low emp and 0 for amount_rain and amount_snow. Include a function that prompts the user and sets values for each field so that you can override the default values. Write a C++/Java/Python program that creates a monthly report.
a) Menu driven program with options to Enter data and Display report
b) Report Format

*/

#include<iostream>
using namespace std;
class weather
{
    int d_o_m;
    float htemp,ltemp,amt_of_rain,amt_of_snow;
public:
    weather();
    void inputdata(int);
    void display();
    void average(weather *w);
};
weather::weather()
{
       htemp=999;
    ltemp=-999;
    amt_of_rain=0;
    amt_of_snow=0;
    d_o_m=99;
}
void weather::inputdata(int d)
{
    d_o_m=d;
    cout<<"Enter high Temp:";
    cin>>htemp;
    cout<<"\nEnter low Temp:";
    cin>>ltemp;
    cout<<"\nEnter Amt of Rain:";
    cin>>amt_of_rain;
    cout<<"\nEnter Amt of Snow:";
    cin>>amt_of_snow;
}
void weather::display()
{
         cout<<"\t"<<d_o_m;
     cout<<"\t\t"<<htemp;
     cout<<"\t"<<ltemp;
     cout<<"\t"<<amt_of_rain;
     cout<<"\t"<<amt_of_snow;
}
void weather::average(weather w[31])
{
    int train,tsnow,tltemp,thtemp;
    float avghtemp,avgltemp,avgrain,avgsnow;
    train=tsnow=tltemp=thtemp=0;
    int i,count=0;
    for(i=1;i<=31;i++)
    {
          if(w[i].d_o_m==90)
        continue;
        else
        {
          thtemp+=w[i].htemp;
        tltemp+=w[i].ltemp;
        train+=w[i].amt_of_rain;
        tsnow+=w[i].amt_of_snow;
        count++;
        }
    }
avghtemp=thtemp/count;
avgltemp=tltemp/count;
avgrain=train/count;
avgsnow=tsnow/count;
cout<<"\nAverage High Temp:"<<avghtemp;
cout<<"\nAverage Low Temp:"<<avgltemp;
cout<<"\nAverage Amount of Rain:"<<avgrain;
cout<<"\nAverage Amount of Snow:"<<avgsnow;
}
int main()
{
  weather data[12][31],temp[31],obj;
  int ch,i,day,month;
  char ans;
cout<<"\nWEATHER REPORT";
do
{
cout<<"\n Main Menu";
cout<<"\n1.Enter Data.";
cout<<"\n2.Display Report.";
cout<<"\n3.Exit.";
cout<<"\nEnter your choice:";
cin>>ch;
switch(ch)
{
 case 1:
           cout<<"\nEnter the month:";
    cin>>month;
    cout<<"\nEnter the day:";
    cin>>day;
    data[month][day].inputdata(day);
    break;
 case 2:
    cout<<"\nEnter the month:";
    cin>>month;
    cout<<"\n\n\tDay\tDay_o_M\tAmt_Rain\tAmt_Snow\tHigh_temp\tLow_temp";
    for(int i=1;i<=31;i++)
    {
             cout<<"\n"<<i;
        data[month][i].display();
    }
    for(int i=1;i<=31;i++)
    {
        temp[i]=data[month][i];
    }
    obj.average(temp);
    break;
}
cout<<"\nDo u want to continue?";
cin>>ans;
}while(ans=='y');
return 0;
}

8. Create a C++ class named Television that has data members to hold the model number and the screen size in inches, and the price. Member functions include overloaded insertion and extraction operators. If more than four digits are entered for the model, if the screen size is smaller than 12 or greater than 70 inches, or if the price is negative or over $5000 then throw an integer. Write a main() function that instantiates a television object, allows user to enter data and displays the data members .If an exception is caught, replace all the data member values with zero values.


/* Problem Statement:

Create a C++ class named Television that has data members to hold the model number and the screen size in inches, and the price. Member functions include overloaded insertion and extraction operators. If more than four digits are entered for the model, if the screen size is smaller than 12 or greater than 70 inches, or if the price is negative or over $5000 then throw an integer. Write a main() function that instantiates a television object, allows user to enter data and displays the data members .If an exception is caught, replace all the data member values with zero values.


*/


/*  Television.cpp  */

#include<iostream>
#include<string.h>
Using namespace std;
Class television
{
    int price,e;
    float size                                                                  
    char model[20];
    public:
    friend istream &operator >>(istream &din,television &t)
    {
        cout<<"\n\n Enter model number of TV::";
        cin>>t.model;
        cout<<"\n\n Enter size of TV(Inches)::";                                                                               
        cin>>t.size;
        cout<<"\n\n Enter Price of TV::";
        cin>>t.price;
        return(din);
    }
    friend ostream &operator >>(oistream &dout,television &t)
    {
        try
        {
            if(strlen(t.model)>4)
            throw(1);
            if(t.size<12000)
            throw(2);
            if(t.size>70000)
            throw(3);
            if(t.price>50000)
            throw(4);
            else
            {
                cout<<"\n Model number of TV::"<<t.model;
                cout<<"\nSize of TV<<t.size;
                cout<<"\n Price of TV<<t.price;
            }
            catch(int e)
            {
                switch(e)
                {
                    case 1:
                        cout<<"\n Exception Caught";
                        cout<<"\n Model no should be less than 4 digits long!!!";
                    break;
                    case 2:
                        cout<<"\n Exception Caught";
                        cout<<"\nSize should be greater than 12 inches!!!";
                    break;
                    case 3:
                        cout<<"\n Exception Caught";
                        cout<<"\n Size should be less than 70 inches!!!";
                    break;
                    case 4:
                        cout<<"\n Exception Cauht";
                        cout<<"\n Price should be less than or equal to $5000!!!";
                    break;
                }
            }
            return(dout);
        }
    }
};   
void main()
{
    int ch;
    Television t1;
    cout<<"\n\t============Exception Handling===============\n";
    do
    {
        cout<<"\n\n\t 1.Insert data\n\t Display Data \n\t 3.Exit\n";
        cout<<"Enter your choice";
        cin>>ch;
        switch(ch)
        {
            case 1:
                cin>>t1;
            break;
            case 2:
                cout<<t2;
            break;
            case 3:
            break;
        default:
            cout<<"Enter correct choice";
        }
    }while(ch!=3);
    getch()
}

7. Design a C++ base class consisting of the data members such as name of the student, roll number and subject. The derived class consists of the data members subject code, internal assessment and university examination marks. Construct a virtual base class for the item name of the student and roll number. The program should have the facilities. i) Build a master table ii) List a table iii) Insert a new entry iv) Delete old entry v) Edit an entry vi) Search for a record


//Program Code

#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<iomanip>

using namespace std;
static int cnt;
class stud
{
 public:
 char name[20];
 int roll;
};
class s2 : public virtual stud
{
 public : char sub[10];
    int scode;
    int sem;
    char div[2];
};
class s1:virtual public stud
{
public : char addr[30];
    int pin;
};
class sdata:public s1,public s2
{
 public : int subc1;
          int im1;
          int um1;
};

int main()
{
  sdata m[100];
  char c='y',str2[10];
  int op,n,i,j,flag=0,rl,r;
  do
  { 
    cout<<"\n * * * * * * Menu  * * * * * *";
    cout<<"\n 1. Build Table \n 2. List a Table \n 3. insert new entry";
    cout<<"\n 4. Delete an entry \n 5. Edit an entry \n 6. Search for record \n Enter your choice :";
    cin>>op;
    switch(op)
     {
       case 1 : cout<<"\n building new Table";
        cout<<"\n Enter total number of Entries :";
                cin>>n;
                for(i=0;i<n;i++)
                {
         cout<<"\n Enter Name of Student :";
                cin>>m[i].name;
        cout<<"\n Enter Roll number     :";
                cin>>m[i].roll;
        cout<<"\n Enter Name of Subject :";
                cin>>m[i].sub;
        cout<<"\n Enter Subject code for Subject "<<m[i].sub<<":";
                cin>>m[i].scode;
        cout<<"\n Enter internal marks for Subject "<<m[i].sub<<":";
                cin>>m[i].im1;
        cout<<"\n Enter University exam marks for Subject "<<m[i].sub<<" :";
                cin>>m[i].um1;
        cnt++;
                 }//for
                break;
       case 2 : cout<<"\n Entries in Table are :";
        cout<<setw(20)<<"\n Name_of_Student"<<setw(8)<<"Roll No"<<setw(12)<<"Subject"<<setw(10)<<"Sub_code"<<setw(12)<<"Internal"<<setw(12)<<"External";   
        cout<<"\n----------------------------------------------------------------------------------------";
        for(i=0;i<cnt;i++)
        {
       
cout<<endl<<setw(10)<<m[i].name<<setw(10)<<m[i].roll<<setw(12)<<m[i].sub<<setw(10)<<m[i].scode<<setw(12)<<m[i].im1<<setw(12)<<m[i].um1;       
        }
        break;
    case 3:j=cnt;
        cout<<"\n Enter Name of Student :";
                cin>>m[j].name;
        cout<<"\n Enter Roll number     :";
                cin>>m[j].roll;
        cout<<"\n Enter Name of Subject :";
                cin>>m[j].sub;
        cout<<"\n Enter Subject code for Subject "<<m[j].sub<<":";
                cin>>m[j].scode;
        cout<<"\n Enter internal marks for Subject "<<m[j].sub<<":";
                cin>>m[j].im1;
        cout<<"\n Enter University exam marks for Subject "<<m[j].sub<<" :";
                cin>>m[j].um1;
        cnt++;
                 break;
     case 4: cout<<"\n Enter record number to delete :";
            cin>>r;
        if(r>0 && r<=cnt)
        {
        j=r-1;
        for(i=j;i<cnt-1;i++)
        {
        m[i]=m[i+1];
          }//for
        cnt--;
        cout<<"\n Record Deleted Successfully ";       
        }//if
        else
            cout<<"\n Entered wrong record number,please enter correct record number \n";   
        break;

    case 5: cout<<"\n Enter record number to edit :";
            cin>>r;
        if(r>0 && r<=cnt) {
        j=r-1;
        cout<<"\n Select Field to Edit : 1. Name \n 2. Roll Number \n 3. Subject Name \n4.Subject code \n5. Internal Marks  \n6. Universirt Exam marks  \n Choice : ";
        cin>>op;
        switch(op)
        {
        case 1 : cout<<"\n Enter New Name of student :";
        cin>>m[j].name;
        break;   

        case 2 : cout<<"\n Enter updated Roll Number of student :";
        cin>>m[j].roll;
        break;
        case 3 :cout<<"\n Enter New Name of Subject :";
                cin>>m[j].sub;
        break;
       
        case 4 : cout<<"\n Enter updated Subject code for Subject "<<m[j].sub<<":";
                cin>>m[j].scode;
        break;
        case 5 : cout<<"\n Enter updated internal marks for Subject "<<m[j].sub<<":";
                cin>>m[j].im1;
        break;
       
        case 6 : cout<<"\n Enter Updated University exam marks for Subject "<<m[j].sub<<" :";
                cin>>m[j].um1;   
        break;       
           }//switch
        }//if
        else
        cout<<"\n Entered wrong record number,please enter correct record number \n";
        break;
    case 6: cout<<"\n Select data type to search :\n 1. Name \n 2.Roll Number \n Choice :";
        cin>>op;
        switch(op)
        {
        case 1:cout<<"\n Enter Name to search in table :";
            cin>>str2;
            flag=0;
            for(i=0;i<cnt;i++)
            {
            if(strcmp(m[i].name,str2)==0)
            {
              flag=1;
              cout<<"\nRecord found for name "<<str2<<". Details are : ";
              cout<<"\n Name    :"<<str2<<"\t Roll :"<<m[i].roll;
              cout<<"\n Subject :"<<m[i].sub<<"\t Subject Code :"<<m[i].scode;   
               cout<<"\n Internal:"<<m[i].im1<<"\t External :"<<m[i].um1;
              }
            else
                continue;
            }//for ends
            if(flag==0)
                cout<<"\n No record found";       
            break;
        case 2 : cout<<"\n Enter roll number to search in table :";
            cin>>rl;
            flag=0;
            for(i=0;i<cnt;i++)
            {
            if(m[i].roll==rl)
            {
              flag=1;
              cout<<"\nRecord found for Roll number "<<rl<<". Details are : ";
              cout<<"\n Name    :"<<m[i].name<<"\t Roll :"<<rl;
              cout<<"\n Subject :"<<m[i].sub<<"\t Subject Code :"<<m[i].scode;   
               cout<<"\n Internal:"<<m[i].im1<<"\t External :"<<m[i].um1;
              }
            else
                continue;
            }//for ends
            if(flag==0)
                cout<<"\n No record found";
        } //switch
        break;
      } //switch completed
   cout<<"\n Do you want to continue (y/n) ? : ";
   cin>>c;
  } while(c=='y'||c=='Y');
cout<<"********** !!! HAVE A GREAT DAY !!!************ \n";
} // program exit

6. Write a program in C++ using function template to read two matrices of different data types such as integers and floating point values and perform simple arithmetic operations on these matrices separately and display it


//Program using Template Function

#include<iostream>
#include<iomanip>
//void add(M, M);
int const size=3;
using namespace std;

//addition function
template <class M, class S>
void add(M a[][size],S b[][size])
{
 S c[size][size];
 for(int i=0;i<size;i++)
    for(int j=0;j<size;j++)
    {
    c[i][j]=a[i][j]+b[i][j];
    }

 for(int i=0;i<size;i++)
      {
    for(int j=0;j<size;j++)
    {
     cout<<"   "<<c[i][j];
      }
    cout<<endl;
    }
}

//substraction
template <class M,class S>
void sub(M a[][size],S b[][size])
{
 S c[size][size];
 for(int i=0;i<size;i++)
    for(int j=0;j<size;j++)
    {
    c[i][j]=a[i][j]-b[i][j];
    }

 for(int i=0;i<size;i++)
      {
    for(int j=0;j<size;j++)
    {
     cout<<"   "<<c[i][j];
      }
    cout<<endl;
    }
}

//multiplication
template <class M,class S>
void mul(M a[][size],S b[][size])
{
 S c[size][size];
 for(int i=0;i<size;i++)
    {
    for(int j=0;j<size;j++)
    {
      for(int k=0;k<size;k++)
        c[i][j]=a[i][k]*b[k][j];
     }
    }
 for(int i=0;i<size;i++)
      {
    for(int j=0;j<size;j++)
    {
     cout<<"   "<<c[i][j];
      }
    cout<<endl;
    }
}

//transpose
template <class M>
void trans(M a[][size])
{
 M c[size][size];
 for(int i=0;i<size;i++)
 {
    for(int j=0;j<size;j++)
    {
    c[i][j]=a[j][i];
    }
  }
cout<<endl<<endl<<"Transpose of matrix :"<<endl;
 for(int i=0;i<size;i++)
      {
    for(int j=0;j<size;j++)
    {
     cout<<c[i][j]<<"\t";
      }
    cout<<endl;
    }
}

int main()
{
 int x[size][size],y[size][size];
 float g[size][size],h[size][size];
 int ch;

//Read matrices
 cout<<endl<<"Enter values for Int matrix X:";
 for(int i=0;i<size;i++)
      {
    for(int j=0;j<size;j++)
    {
     cin>>x[i][j];
      }
    cout<<endl;
    }

 cout<<endl<<"Enter values for float matrix g:";
  for(int i=0;i<size;i++)
      {
    for(int j=0;j<size;j++)
    {
     cin>>g[i][j];
      }
    cout<<endl;
    }

//Display matrices as entered by user
cout<<endl<<endl<<"Int matrix X:"<<endl;
 for(int i=0;i<size;i++)
      {
    for(int j=0;j<size;j++)
    {
     cout<<x[i][j]<<"\t";
      }
    cout<<endl;
    }
cout<<endl<<endl<<"Float matrix G:"<<endl;
 for(int i=0;i<size;i++)
      {
    for(int j=0;j<size;j++)
    {
     cout<<g[i][j]<<"\t";
      }
    cout<<endl;
    }


 do
  {
 cout<<endl<<"************* Operations ****************  \n1.addition of matrix \n2.Substraction of Matrix \n3.Multiplication \n4.Transpose "<<endl<<endl<<"\t Enter Choice";;
 cin>>ch;
 switch(ch)
 {
 case 1 : cout<<endl<<"Result of Addition of matrix X and G : "<<endl;
    add(x,g);
    break;
case 2 : cout<<endl<<"Result of Substraction of matrix X and G : "<<endl;
     sub(x,g);
    break;
 case 3 : cout<<endl<<"Result of Multiplication of matrix X and G : "<<endl;
    mul(x,g);
    break;
case 4 : trans(x);
    trans(g);
    break;
default : cout<<endl<<"Enter valid option"<<endl<<endl;
    break;
 }
}while(ch<6);
return 0;
}



*********************************     *****************************************

//Program using class Template


#include<iostream.h>
#include<conio.h>
template <class t> class mat     //defining class mat
{
    int i,j;
    t m[10][10];
    public:
    void getdata(int,int);
    void putdata(int,int);
    void sub(mat&,mat&,int,int);
    void add(mat&,mat&,int,int);
    void mul(mat&,mat&,int,int,int);
    void trans(mat&,int,int);
};

//defining getdata function
template <class t> void mat <t> :: getdata(int r,int c)
{
    //accepting data from user
    int i=0,j=0;
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            cout<<"Enter value a["<<i<<'] ["<<j<<"]";
            cin>>m[i][j];
        }
    }
}
//defining add function
template <class t> void mat <t> :: add(mat<t> &a1,mat<t>&a2,int r,int c)
{
    int i=0,j=0;
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            //adding two values
            M[i][j]=a1.m[i][j]+a2.m[i][j];
        }
    }
}
//defining subtract function
template <class t> void mat <t> :: sub(mat<t> &a1,mat<t>&a2,int r,int c)
{
    int i=0,j=0;
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            //adding two values
            M[i][j]=a1.m[i][j]-a2.m[i][j];
        }
    }
}
//defining multiplication function
template <class t> void mat <t> :: mult(mat<t> &a1,mat<t>&a2,int r,int c)
{
    int i=0,j=0,k=0;//declaring local variables
    //initializing matrix all values to zero
    for(i=0;i<r;i++)
    for(j=0;j<c;j++)
    m[i][j]=0
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            for(k=0;k<r;k++)
            M[i][j]=m[i][j]+(a1.m[i][k]*a2.m[k][j]);
        }
    }
}
//defining transpose function
template <class t> void mat <t> :: trans(mat<t> &a1,mat<t>&a2,int r,int c)
{
    int i=0,j=0;
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            //adding two values
            M[i][j]=a1.m[j][i];
        }   
    }
}
//defining putdata function
template <class t> void mat <t> :: putdata(mat<t> &a1,mat<t>&a2,int r,int c)
{
    int i=0,j=0;
    for(i=0;i<r;i++)
    {
        cout<<"\n";
        for(j=0;j<c;j++)
        {
            cout<<"\t";
            cout<<m[i][j];
        }
    }
}
int main()
{
    int ch,m,n,x,y   //declaring local variables
    mat<double> p,q,s;
    cout<<"Enter rows & columns of 1st matrix";
    cin>>m>>n;  //accepting rows and columns for 1st matrix;
    cout<<"\n Enter 1st  matrix\n";
    p.getdata(m,n); //calling getdata function
    cout<<"Enter rows and columns of 2nd matrix";
    cin>>x>>y  //accepting rows and columns of second matrix;
    cout<<"\n Enter 2nd matrix\n";
    q.getdata(x,y);  //calling getdata function
    do
    {
        //displaying menu
        cout<<"\nMenu"
        <<"\n1.addition"
        <<"\n2.substraction"
        <<"\n3.Multiplication"
        <<"\n4.Transpose"
        <<"\n Exit"
        <<"\n Enter Your Choice: ;
        cin>>ch;  //accepting choice from user
        switch(ch)
        {
            case 1:
                if(m==x && n==y)  //if rows and cols are same
            {
                cout<<"addition is";
                s.add(p,q,m,n);
                s.putdata(m,n);
            }
            else
            {
                cout<<"addition is not possible";
            }
        break;
            case 2:
                if(m==x && n==y)  )  //if rows and cols are same
            {
                cout<<"sunstraction is";
                s.sub(p,q,m,n);
                s.putdata(m,n);
            }
            else
            {
                cout<<"substrction is not possible";
            }
        break;
            case 3:
                if (n==x)  //if cols of first matrix is equal to rows of second matrix
            {
                cout<<"Multiplication is";
                s.mult(p,q,m,n);
                s.putdata(m,n);
            }
            else
            {
                cout<<"multiplication is not possible";
            }
        break;
            case 4:
                cout<<"Transpose is:\n";
                s.trans(p,m,n);
                s.putdata(m,n);
        break;
            case 5:
                cout<<"\n Exiting..\n";
        }\\end of switch
    }while(ch!=5);//end of while
    return 0;
}end of main

5. Write a C++ program to perform String operations : i. = Equality ii. == String Copy iii. + Concatenation iv. << To display a string v. >> To reverse a string vi. Function to determine whether a string is a palindrome To find occurrence of a sub-string. Use Operator Overloading



/* Problem Statement:

Write a C++ program to perform String operations :
i.     = Equality                 ii.     == String Copy
iii.     + Concatenation            iv.     << To display a string
v.     >> To reverse a string        vi.     Function to determine whether a string is a palindrome
vii. To find occurrence of a sub-string.
             Use Operator Overloading   */


// Code

#include<iostream>
#include<string>
#include<stdlib.h>

using namespace std;

class stg
{
  char str[20];
  int len;
  public:
  stg() { len=0; }

  void read()
  {
    cout<<"\nEnter the string : ";
    cin>>str;
  }

  int operator ~()
  {
    int i;
    len=0;
    for(i=0;str[i]!='\0';i++)
    {
     len++;
    }
    return(len);
  }

  friend istream &operator >>(istream &in,stg &s)
  {
    int i;
    ~s;
    cout<<"\nReverse string: ";
    for(i=s.len-1;i>=0;i--)
    {
      cout<<s.str[i];
    }
  }

  void operator ==(stg s)
  {
     read();
     int i;
     char str2[20];
     for(i=0;str[i]!='\0';i++)
       str2[i]=str[i];
     str2[i]='\0';
    cout<<"\nCopied String : ";
    cout<<str2;
  }

  void operator +(stg s2)
  {
    ~*this;
    int j=len;
    for(int i=0;s2.str[i]!='\0';i++)
    {
       str[j]=s2.str[i];
       j++;
    }
    str[j]='\0';
    cout<<str;
  }

  void operator =(stg s2)
  {
    int i,f=0;
    for(i=0;str[i]!='\0';i++)
    {
       if(str[i]==s2.str[i])
       {
     f=1;
       }
      else
     f=0;
     break;
    }
    if(f==1)
     cout<<"\nStings are equal!";
    else
     cout<<"\nStrings are not equal";
  }
  void operator ||(stg s2)
  {
    int i,j=0,f=0,count=0;
    cout<<"\nPositions of occurence: ";
    for(i=0;str[i]!='\0';i++)
    {
       if(str[i]==s2.str[j])
       {
    j++;
       }
       else
       {
    j=0;
       }
       if(s2.str[j]=='\0')
       {
     f=1;
     count++;
     cout<<"  "<<(i-j+2);
     j=0;
       }
    }
    cout<<"\nNo of occurence of substring: "<<count;
  }

  void operator !()
  {
    int f=0;
    ~*this;
    for(int i=0;i<len;i++)
    {
      if(str[i]==str[len-i-1])
     f=1;
      else
       {
     f=0; break;
       }
    }
    if(f==1)
      cout<<"\nIt is a pallindrome!";
    else
    cout<<"\nIt is a NOT pallindrome!";
  }


friend ostream &operator <<(ostream &out,stg &s)
  {
     out<<s.str;
     return(out);
  }
};

int main()
{
int c,l;
 char m;
 stg s1,s2;
 do
 {
 cout<<"\n\n\n\tMENU:\n1.Length of the string\n2.Copy\n3.Reverse\n4.Concatination\n5.Compare two strings\n6.Find Substring\n7.Pallindrome \n8. Exit \nChoice= ";
 cin>>c;
 switch(c)
 {
  case 1: s1.read();
      l=~s1;
      cout<<"\nLength of the string is: "<<l;
      break;
  case 2: s1==s2;
      break;
  case 3: s1.read();
      cin>>s1;
      break;
  case 4: cout<<"First String :"; s1.read();
      cout<<"Second String :"; s2.read();
      s1+s2;
      break;
  case 5: cout<<"First String :"; s1.read();
      cout<<"Second String :"; s2.read();
      s1=s2;
      break;
  case 6: cout<<"Original String :"; s1.read();
      cout<<"Substring to search :"; s2.read();
      s1||s2;
      break;
  case 7: s1.read();
      !s1;
      break;
  case 8: exit(1);
      break;
  default:cout<<"Invalid";
      break;
  }
  //cout<<"\nDo you want to continue?-y/n: ";
  //cin>>m;
  }while(c!=8);
 return 0;
}

4. Design a C++ Class ‘Complex’ with data members for real and imaginary part. Provide default and parameterized constructors. Write a program to perform arithmetic operations of two complex numbers using operator overloading (using either member functions or friend functions).


Design a C++ Class ‘Complex’ with data members for real and imaginary part. Provide default and parameterized constructors. Write a program to perform arithmetic operations of two complex numbers using operator overloading (using either member functions or friend functions).

*/


/* Complex.cpp*/

#include<iostream>
Using namespace std;

class complex
{
  float real,imag;
  public:
  complex()
  {
    real=imag=0;
  }

  void getdata()
  {
    cout<<"\nEnter the real and imaginary part of complex no : ";
    cin>>real>>imag;
  }

  void display()
  {
       if(imag>=0)
         cout<<"\n"<<real<<"+"<<imag<<"i";
      else
      cout<<"\n"<<real<<"-"<<abs(imag)<<"i";
 
  }

  complex operator +(complex c1)
  {
    complex c3;
    c3.real=real+c1.real;
    c3.imag=imag+c1.imag;
    return c3;
  }

  complex operator -(complex c1)
  {
    complex c3;
    c3.real=real-c1.real;
    c3.imag=imag-c1.imag;
    return c3;
  }

  complex operator *(complex c1)
  {
    complex c3;
    c3.real=real*c1.real-imag*c1.imag;
    c3.imag=real*c1.imag+imag*c1.real;
    return c3;
  }

  complex operator /(complex c1)
  {
    complex c3;
    float den;
    den=c1.real*c1.real-c1.imag*c1.imag;
    c1.imag=c1.imag*(-1);
    c3.real=real*c1.real-imag*c1.imag;
    c3.imag=real*c1.imag+imag*c1.real;
    c3.real=c3.real/den;
    c3.imag=c3.imag/den;
    return c3;
  }
};

void main()
{
  int m;
  char n;
  complex c1,c2,c3,c4,c5,c6;
  c1.getdata();
  c2.getdata();
  cout<<"\nGiven two complex numbers:\n";
  c1.display();
  c2.display();
  do
  {
  cout<<"\nMENU:\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\nChoice= ";
  cin>>m;
  switch(m)
  {
  case 1: cout<<"\n\nAddition:\n ";
      c3=c1+c2;
      c3.display();
      break;
  case 2: cout<<"\n\nSubtraction:\n ";
      c4=c1-c2;
      c4.display();
      break;
  case 3: cout<<"\n\nMultiplication:\n ";
      c5=c1*c2;
      c5.display();
      break;
  case 4: cout<<"\n\nDivision:\n ";
      c6=c1/c2;
      c6.display();
      break;
  }
  cout<<"\nDo you want to continue-y/n : ";
  cin>>n;
  }while(n=='y');
}

3. Develop an object oriented program in C++ to create a database of the personnel information system containing the following information: Name, Date of Birth, Blood group, Height, Weight, Insurance Policy, number, Contact address, telephone number, driving license no. etc Construct the database with suitable member functions for initializing and destroying the data viz. constructor, default constructor, copy, constructor, destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation operators-new and delete.


/* Problem Statement:

Develop an object oriented program in C++ to create a database of the personnel information system containing the following information: Name, Date of Birth, Blood group, Height, Weight, Insurance Policy, number, Contact address, telephone number, driving license no. etc Construct the database with suitable member functions for initializing and destroying the data viz. constructor, default constructor, copy, constructor, destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation operators-new and delete.

*/

#include<iostream>
#include<string>
#include<cstring>
using namespace std;
class person
{
    private:
    char name[40],dob[15],bdg[15];
    int h,w;
    public:
    static int count;
    friend class personal;
    person()
    {
        char * name=new char[40];
        char *dob=new char[80];
        char *bdg=new char[15];
        h=w=0;
    }
    static void recordcount()
    {
        cout<<"\n Total no of records :"<<count;
    }
};

class personal
{
private:
  char add[70],telephone[15],policy_no[10];
public:
 personal()
{
    strcpy(add,"");
    strcpy(telephone,"");
    strcpy(policy_no,"");
}
void getdata(person *obj);
void displaydata(person *obj);
friend class person;
};
int person::count=0;
void personal::getdata(person *obj)
{
cout<<"\n Enter Name of Person=";
cin>>obj->name;
cout<<"\n Enter date of birth of person=";
cin>>obj->dob;
cout<<"\n Enter blood group of person=";
cin>>obj->bdg;
cout<<"\n Enter height and weigth of person=";
cin>>obj->h>>obj->w;
cout<<"\n Enter Contact no of person=";
cin>>this->telephone;
cout<<"\n Enter addreass of person=";
cin>>this->add;
cout<<"\n Enter the insurance policy no=";
cin>>this->policy_no;
obj->count++;
}
void personal::displaydata(person *obj)
{

cout<<obj->name<<"\t"<<obj->dob<<"\t\t"<<obj->bdg<<"\t"<<obj->h<<"\t\t"<<obj->w<<"\t"<<this->telephone<<"\t"<<this->policy_no<<"\t"<<this->add;
}
int main()
{
personal *p1[30];
person *p2[30];
int n=0,ch,i;
do
{
cout<<"\n Menu";
cout<<"\n 1.Information of Person \n 2.Display Information \n 3.Exit";
cout<<"\n Enter your choice";
cin>>ch;
switch(ch)
{
case 1:
 cout<<"\n Enter The Information";
 cout<<"\n";
 p1[n]=new personal;
 p2[n]=new person;
p1[n]->getdata(p2[n]);
n++;
person::recordcount();
break;
case 2:
 cout<<"\n";
cout<<"\n*******************************************************************\n";
cout<<"NAME"<<"\t"<<"DATE OF BIRTH"<<"\t"<<"BLOOD GROUP"<<"\t"<<"HEIGHT"<<"\t"<<"WEIGHT"<<"\t"<<"TELEPHONE NO"<<"\t"<<"INSU.POLICYNO"<<"\t"<<"ADDRESS \n";
cout<<"\n";
for(i=0;i<n;i++)
{
p1[i]->displaydata(p2[i]);

}
person::recordcount();
break;
}
}while(ch!=4);
return 0;
}

2. A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays the book details and requests for the number of copies required. If the requested copies book details and requests for the number of copies required. If the requested copies are available, the total cost of the requested copies is displayed; otherwise the message “Required copies not in stock” is displayed. Design a system using a class called books with suitable member functions and Constructors. Use new operator in constructors to allocate memory space required. Implement C++ program for the system

/* Problem Statement:

A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays the book details and requests for the number of copies required. If the requested copies book details and requests for the number of copies required. If the requested copies are available, the total cost of the requested copies is displayed; otherwise the message “Required copies not in stock” is displayed.
Design a system using a class called books with suitable member functions and Constructors. Use new operator in constructors to allocate memory space required. Implement C++ program for the system

*/


/* Bookshop.cppp*/
#include<iostream>
#include<string.h>
#include<stdlib.h>

using namespace std;
class book
{

 char author[20]; 
 char title[20];
 char publisher[20];
 double price;
 int stock;
   public:
     book();    
   void insertdata();
   void display();
   int search(char[],char[]);
   void nocopies(int);     
};
  book::book()
  {
    char *author=new char[50];
    char * title=new char[50];
    char *publisher=new char[50];
    price=0;
    stock=0;
   }
void book::insertdata()
         {
  cout<<"\n Enter the name of Book:";
  cin>>title;
  cout<<"\n Enter The Name Of Author:";
  cin>>author;
  cout<<"\n Enter The name of Publisher:";
  cin>>publisher;
  cout<<"\n Enter the Price of book:";
  cin>>price;
  cout<<"\n Enter Stock of book:";
  cin>>stock;
 }


  void book::display()
 {
 cout<<"\n "<<title<<"\t\t "<<author<<"\t\t  "<<publisher<<" \t\t\t "<<price<<"\t "<<stock;
        }
  int book::search(char t[],char a[])
  {
      if(strcmp(title,t)&&(strcmp(author,a)))
 {
 return 0;
 }
 else
 {
 return 1;
 }
  }

 void book::nocopies(int num)
{
if(stock>=num)
{
cout<<"\n Title is avilable";
cout<<"\n Cost of"<<num<<"Books is Rs."<<(price*num);
}
else
{
cout<<"\n Required copies not in stock";
}
}
int main()
{
 int ch,n,i,flag=0,copies,key=0;
          book b[100];
          char bname[50];
          char key_title[50],key_author[50];
   do
    {
 cout<<"\n************Book Store*******************";
 cout<<"\n 1.Insert Details of book \n 2.Display \n 3.search \n 4.exit";
 cout<<"\n Enter Your Choice:";
 cin>>ch;
 switch(ch)
  {
      case 1:
                    cout<<"\n How many books data u want to enter";
                    cin>>n;
                    for(i=0;i<n;i++)
                      {
                       b[i].insertdata();
   }
                     break;
     case 2:
                       cout<<"\n"<<"TITLE"<<"\t \t "<<"AUTHOR"<<"\t\t"<<"PUBLISHER"<<"\t\t"<<"PRICE"<<"\t "<<"STOCK";
                        for(i=0;i<n;i++)
    {
                        cout<<"\n";
   
         b[i].display();   
     }
   
                        break;
                    
   case 3:
                          cout<<"\n Enter title of required book";
                           cin>>key_title;
                           cout<<"\n Enter author of required book";
                            cin>>key_author;
                             
                            for(i=0;i<n;i++)
                          {
                              if(b[i].search(key_title,key_author))
                               {
                                  flag=1;
 cout<<"\n"<<"TITLE"<<"\t \t "<<"AUTHOR"<<"\t\t"<<"PUBLISHER"<<"\t\t"<<"PRICE"<<"\t "<<"STOCK";
                                  b[i].display();                        
    //break;
    key=i;
            }
    }
   if(flag==1)                          
    cout<<"\n Book is available";
   else
 {
     cout<<"\n book is Not available";
        break;
 }        
              if(flag==1)
                      {
                      cout<<"\n Please enter the required number of copies of the book";
                       cin>>copies;
                      b[key].nocopies(copies);
                     }
                   
                     break;
                case 4: exit(EXIT_SUCCESS);
   break;
  default :
                    cout<<"\n Wrong Choice";
                       break;
 }   
   }while(ch!=5);
 return 0;
}