Sunday 6 November 2011

I sem IP lab Programs


 Input/Output Formatting Functions
                
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>

void main()
{
            clrscr();
            int sno[10],qty[10],i,n;
            char itemcode[20][10];
            float price[10],ta[10];

            cout<<"\n\t\t i/o formatting functions"<<endl;
            cout<<"\n\t\t--------------------------"<<endl;
            cout<<"\n enter number of customers:";
            cin>>n;
            for(i=0;i<n;i++)
            {
                 cout<<endl<<setw(4)<<"\n enter item code:";
                 cin>>itemcode[i];
                 cout<<endl<<setw(4)<<"\n enter quantity:";
                 cin>>qty[i];
                 cout<<endl<<setw(4)<<"\n enter price:";
                 cin>>price[i];
                 ta[i]=price[i]*qty[i];
            }
            cout<<endl;
            cout<<"\n\t----------------------------------------------------------------"<<endl;
            cout<<setw(4)<<"\tsno"<<setw(15)<<"itemcode"<<setw(15)<<"qty"<<setw(15)<<"price"
            <<setw(15)<<"total amount";
            cout<<"\n\t----------------------------------------------------------------"<<endl;
            for(i=0;i<n;i++)
            {
                 cout<<endl;
                 cout.setf(ios::right,ios::adjustfield);
                 cout.width(10);
                 cout<<i+1;
                 cout.setf(ios::right,ios::adjustfield);
                 cout.width(15);
                 cout<<itemcode[i];
                 cout.setf(ios::right,ios::adjustfield);
                 cout.width(15);
                 cout<<qty[i];
                 cout.setf(ios::right,ios::adjustfield);
                 cout.width(15);
                 cout<<setprecision(3)<<price[i];
                 cout.setf(ios::right,ios::adjustfield);
                 cout.width(15);






    cout<<setprecision(3)<<ta[i]<<endl;
            }
               cout<<"\n\t----------------------------------------------------------------"<<endl;
               getch();
  }

OUTPUT:

i/o formatting functions
--------------------------

enter number of customers:2
enter item code:a12
enter quantity:5
enter price:15
enter item code:b21
enter quantity:64
enter price:32
   

       ----------------------------------------------------------------
        sno       itemcode            qty          price     total amount
        ----------------------------------------------------------------

         1                 a12                    5       15.00             75.00

         2                 b21                  64       32.00          2048.00
                                                        ---------------------------------------------------------------
             
 Concept Of Message Passing.

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void callbyval(int a,int b)
 {
   int k=a;
   a=b;
   b=k;
   cout<<"\n in fun()";
   cout<<"\n value of a="<<a<<"and b="<<b;
 }
void callbyadd(int *p,int *q)
 {
   int *r;
   *r=*p;
   *p=*q;
   *q=*r;
   cout<<"\n\n in fun()";
   cout<<"\n value of a="<<*p<<"and b="<<*q;
 }
void callbyref(int &x,int &y)
 {
   int z=x;
   x=y;
   y=z;
   cout<<"\n\t in function";
   cout<<"\n value of x="<<x<<"and y="<<y;
 }
int maxval(int &e,int &f)
 {
   if(e>f)
   return e;
   else
   return f;
 }
void main()
 {
       int choice;
       do
     {
       clrscr();
       cout<<"\n\n to determine the concept of message passing by using";
       cout<<"\n\n\t 1.call by value";
       cout<<"\n\n\t 2.call by address";
       cout<<"\n\n\t 3.call by refernce";
    

       cout<<"\n\n\t 4.return by refernce";
       cout<<"\n\n\t 5.exit";
       cout<<"\n\n\t enter your choice:";
       cin>>choice;
             switch(choice)
               {
                case 1:
                 {
                        int s,t;
                        cout<<"\n\n\t enter the value s,t:";
                        cin>>s>>t;
                        cout<<"\n\n in main fun()";
                        cout<<"\n\n before swapping s="<<s<<"and t="<<t;
                        callbyval(s,t);
                        cout<<"\n\n in main fun()";
                        cout<<"\n\n after swapping s="<<s<<"and t="<<t;
                        getch();
                        break;
                 }
                case 2:
                 {
                        int u,v;
                        cout<<"\n\n\t enter u and v:";
                        cin>>u>>v;
                        cout<<"\n\n in main fun";
                        cout<<"\n\n before swapping u="<<u<<"and v="<<v;
                        callbyadd(&u,&v);
                        cout<<"\n\n in main function";
                        cout<<"\n\n after swapping u="<<u<<"and v="<<v;
                        getch();
                        break;
                 }
                case 3:
                 {
                        int c,d;
                        cout<<"\n\n\t enter the value c and d:";
                        cin>>c>>d;
                        cout<<"\n\n in main function";
                        cout<<"\n\n before swapping c="<<c<<"and d="<<d;
                        callbyref(c,d);
                        cout<<"\n\n in main fun()";
                        cout<<"\n\n after swapping c="<<c<<"and d="<<d;
                        getch();
                        break;
                 }
                case 4:
                 {
                        int g,h,max;
                       

cout<<"\n\t enter the value g and h";
                        cin>>g>>h;
                        max=maxval(g,h);
                        cout<<"\n\n g value is:"<<g;
                        cout<<"\n\n h value is:"<<h;
                        cout<<"\n\n largest value is:"<<max;
                        getch();
                        break;
                 }
               }
     }while(choice!=5);
 }




 OUTPUT:
To determine the concept of message passing by using
 1.call by value
 2.call by addres
 3.call by refernce
 4.return by refernce
 5.exit
 enter your choice:2
 enter u and v:6
            4


 in main fun
 before swapping u=6and v=4
 in fun()
 value of a=4and b=6
 in main function
 after swapping u=4and v=6















 

 Concept Of Control Structure.

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h>
void personage()
  {
            int age;
            cout<<"\n\t enter your age:";
            cin>>age;
            if(age>=18)
            cout<<"\n you are eligible for voting----!";
  }
void biggest()
  {
            int x,y;
            cout<<"\n\t enter x and y values:";
            cin>>x>>y;
            if(x>y)
            cout<<"\n x is bigger:"<<x;
            else
            cout<<"\n y is bigger:"<<y;
  }
void student()
  {
            int rollno,s1,s2,s3,total;
            char sname[20];
            float avg;
            cout<<"enter roll number:";
            cin>>rollno;
            cout<<"enter student name:";
            cin>>sname;
            cout<<"enter sub1,sub2,sub3 marks:";
            cin>>s1>>s2>>s3;
            total=s1+s2+s3;
            avg=(total)/3;
            cout<<"\n rollno:"<<rollno<<"\n sname:"<<sname<<" ";
            cout<<"\n sub1:"<<s1<<"\n sub2:"<<s2<<"\n sub3:"<<s3;
            cout<<"\n total:"<<total<<"\n avg:"<<avg;
            if(s1>=35 && s2>=35 && s3>=35)
               {
                if(avg>=75)
                cout<<"\n distinction";
                else if(avg>=60 && avg<75)
                cout<<"firstclass";
                else if(avg>=50 && avg<60)
                cout<<"secocdclass";
             
             else
                cout<<"thirdclass";
               }
             else
             cout<<"\n fail----!";
  }
void number()
  {
            int i=0,n;
            cout<<"\n enter the range for display the numbers say n:";
            cin>>n;
            while(i<=n)
             {
              cout<<"\n"<<i;
              i++;
             }
  }
void power()
  {
            int m,y,j=1;
            cout<<"\n enter the range for display cube of the numbers m:";
            cin>>m;
            do
              {
               y=pow(j,3);
               cout<<"\n"<<y;
               j++;
              }while(j<=m);
  }
void factorial()
  {
            int p,k,f=1;
            cout<<"\n enter the values for factorial say p:";
            cin>>p;
            for(k=1;k<=p;k++)
            f=f*k;
            cout<<"\n factorial is:"<<f;
  }
void main()
  {
            int choice;
            char ch,ch1;
            do
              {
               clrscr();
               cout<<"\n\t control structures";
               cout<<"\n 1.conditional statements";
               cout<<"\n 2.looping statements";
               cout<<"\n 3.exit";
           

   cout<<"\n enter your choice:";
               cin>>choice;
               switch(choice)
                  {
                        case 1:
                        do
                          {
                            int choice1;
                            clrscr();
                            cout<<"\n\t your choice is conditional control statements";
                            cout<<"\n 1.the simple if statements";
                            cout<<"\n 2.the if-else statements";
                            cout<<"\n 3.the nested if statements";
                            cout<<"\n enter your choice:";
                            cin>>choice;
                            switch(choice)
                                    {
                                     case 1:personage();
                                                getch();
                                                break;
                                     case 2:biggest();
                                                getch();
                                                break;
                                     case 3:student();
                                                getch();
                                                break;
                                    default:cout<<"\n invalid choice----!";
                                                getch();
                                                break;
                                    }
                            cout<<"\n do you want to continue:(y/n)";
                            cin>>ch;
                          }while(ch=='y' || ch=='Y');
                            break;
                        case 2:
                        do
                          {
                           int choice2;
                           clrscr();
                           cout<<"\n\t your choice is looping control structures:";
                           cout<<"\n 1.while";
                           cout<<"\n 2.do-while";
                           cout<<"\n 3.for";
                           cout<<"\n enter your choice:";
                           cin>>choice2;
                           switch(choice2)
                                    {
                                      case 1:number();
                                   

                                                 getch();
                                                 break;
                                      case 2:power();
                                                 getch();
                                                 break;
                                      case 3:factorial();
                                                 getch();
                                                 break;
                                    }
                           cout<<"do you want to continue(y/n):";
                           cin>>ch1;
                          }while(ch1=='y' || ch1=='Y');
                          break;
                        case 3:exit(0);
                        default:cout<<"\n invalid choice----!";
                        getch();
                        break;
                  }
              }while(choice!=3);
  }



OUTPUT:


         Control Structures
 1.conditional statements
 2.looping statements
 3.exit
 enter your choice:1

 Your choice is conditional control statements
 1.the simple if statements
 2.the if-else statements
 3.the nested if statements
 enter your choice:2

         enter x and y values:5
                                          2

 x is bigger:5
 do you want to continue:(y/n)
                                                    n



Function Over Loading

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#define pi 3.14
void volume(int a)
  {
            int volume;
            volume=a*a*a;
            cout<<"\n volume of cube:"<<volume;
            getch();
  }
void volume(float radius,float height)
  {
            float volume;
            volume=pi*(radius*radius*height);
            cout<<"\n volume of the cylinder:"<<volume;
            getch();
  }
void volume(int length,int breadth,int r_height)
  {
            int volume;
            volume=(length*breadth*r_height);
            cout<<"\n volume of the rectangle:"<<volume;
            getch();
  }
void main()
  {
            clrscr();
            int choice,l,b,s,rh;
            float ra;
            do
              {
                clrscr();
                cout<<"\n to perform the values by using function over loading"<<endl;
                cout<<"\n\n\t 1.volume of cube";
                cout<<"\n\n\t 2. volume of cylinder";
                cout<<"\n\n\t 3.volume of rectangle";
                cout<<"\n\n\t 4.exit";
                cout<<"\n\n\t enter your choice:";
                cin>>choice;
                switch(choice)
                        {
                          case 1 :
                                    {
                                      cout<<"\n\n\t your choice is to be find the volumes of cube";


                                      cout<<"\n\n enter the side of the cube:";
                                      cin>>s;
                                      volume(s);
                                      break;
                                    }
                           case 2 :
                                    {
                                      cout<<"\n\n\t your choice is to be find the volumes of cylinder";
                                      cout<<"\n\n enter the radius & height of the cylinder:";
                                      cin>>ra>>rh;
                                      volume(ra,rh);
                                      break;
                                    }
                           case 3 :
                                    {
                                      cout<<"\n\n\t your choice is to be find the volumes of rectangle";
                                      cout<<"\n\n enter the length&breadth&height of the rectangle:";
                                      cin>>l>>b>>rh;
                                      volume(l,b,rh);
                                      break;
                                    }
                           case 4:
                                      exit(0);
                           default:
                                      cout<<"\n\n\t enter a valid choice----------!:";
                                      getch();
                        }
              }while(choice!=4);
  }


OUTPUT:

           
 To perform the values by using function over loading
 1.volume of cube
 2. volume of cylinder
 3.volume of rectangle
 4.exit
  Enter your choice:2
  Your choice is to be find the volumes of cylinder
  Enter the radius & height of the cylinder:5
      6
 Volume of the cylinder:471
  Enter your choice:4

 Array Of Objects.

#include<iostream.h>
#include<math.h>
#include<conio.h>
#include<iomanip.h>
#include<string.h>
class student
   {
       int sno,so;
       int dms,ps,ip,co,om,total,t[20],rank;
            float avg;
            char sname[10],grade[20];
public:
            void read();
            int cal();
            float average();
            void display();//
            void disp(int);
     };
void student::read()
    {
            cout<<"\n enter student number:";                                                         
            cin>>sno;
            cout<<"enter student name:";
            cin>>sname;
            cout<<"\n enter marks dms:";
            cin>>dms;
            cout<<"\n enter marks ps:";
            cin>>ps;
            cout<<"\n enter marks ip:";
            cin>>ip;
            cout<<"\n enter marks co:";
            cin>>co;
            cout<<"\n enter marks om:";
            cin>>om;
   }
int student::cal()
    {
            total=dms+ip+co+om+ps;
            return(total);
    }
float student::average()
    {
            avg=(dms+ip+co+om+ps)/5;
            if(dms>=35&&ps>=35&&ip>=35&&co>=35&&om>=35)
            {
                        if(avg>=75)


                        strcpy(grade,"distn");
                        else if(avg>=60&&avg<75)
                        strcpy(grade,"first");
                        else if(avg>=50&&avg<60)
                        strcpy(grade,"second");
                        else
                                    strcpy(grade,"third");

                  //    return(avg);
                        }
                        else
                        strcpy(grade,"fail");
                        return(avg);
   }

void student::display()

       {
                 cout<<endl<<setw(10)<<sno<<setw(10)<<sname<<setw(4)<<dms<<setw(4)
                             <<ps<<setw(4)<<ip<<setw(4)<<co<<setw(4)<<om<<setw(8)<<total<<setw(8)<<avg
<<setw(8)<<grade<<endl;
      }
void student::disp(int so)
      {
   if(sno==so)
          {
              display();
           }
   else
          {
 cout<<"\n the number u have entered is wrong---!!";
           }
                 }
void menu()
     {
            cout<<endl;
            for(int i=0;i<70;i++)
            cout<<"-";
            cout<<endl;
     }
void main()
     {
            student s[10];
            int o[10];
            int i,j,n;
            float avg[10];
            clrscr();
            cout<<"\n enter number of students:";


            cin>>n;
            for(i=0;i<n;i++)
            {                                      
                        s[i].read();
                        o[i]=s[i].cal();                //total calculation
                        avg[i]=s[i].average();          //avg calculation
                }
                        clrscr();
                        menu();
                        cout<<endl<<setw(10)<<"sno"<<setw(10)<<"sname"<<setw(4)<<"dms"<<setw(4)<<"ps"
                    <<setw(4) <<"ip"<<setw(4)<<"co"<<setw(4)<<"om";                                                                                             
            cout<<setw(8)<<"total"<<setw(8)<<"avg"<<setw(8)<<"grade"<<endl;
            for(i=0;i<n;i++)
            {
                        for(j=0;j<n;j++)
                        {
                                    if(o[j]==s[i].cal())
                                    {
                                                s[i].display();
                                                cout<<setw(10)<<j+1;
                                    }

                        }
            }

            menu();
             int so;
            cout<<"\n enter number of students whose details to be display:";
            cin>>so;
            for(i=0;i<n;i++)
            {
                        s[i].disp(so);
            }
                        getch();
}


OUTPUT:

 enter number of students:2

 enter student number:101
enter student name : AJAY

 enter marks dms:56



 enter marks ps:68

 enter marks ip:57

 enter marks co:86

 enter marks om:77

 enter student number:102
enter student name : LOKESH

 enter marks dms:75

 enter marks ps:65

 enter marks ip:85

 enter marks co:67

 enter marks om:78


----------------------------------------------------------------------

       sno     sname dms  ps  ip  co  om   total     avg   grade

       101      AJAY  56  68  57  86  77     344      68   first
        
       102    LOKESH  75  65  85  67  78     370      74   first
        
----------------------------------------------------------------------

 enter number of students whose details to be display:102

       102    LOKESH  75  65  85  67  78     370      74   first
 Operations On Strings

#include<iostream.h>
#include<conio.h>
#include<process.h>
class string
{
   char str1[20],str2[20];
   public:
            void read();
            void length();
            void copy();
            void concat();
};
  void string::read()
     {
      cout<<"\nenter first string:";
      cin>>str1;
      cout<<"\nenter second string:";
      cin>>str2;
     }
 void string::length()
     {
     int length=0;
      for(int i=0;str1[i]!='\0';i++)
            {
               length++;
            }
            cout<<"\nlength of first string is:"<<length;
            length=0;
      for(i=0;str2[i]!='\0';i++)
            {
               length++;
            }
            cout<<"\nlength of first striong is:"<<length;
     }
void string::copy()
            {
             cout<<"\nBrefore copying string1:"<<str1;
             cout<<"\nBrefore copying string2:"<<str2;
             for(int j=0;str1[j]!='\0';j++)
                 {
                   str2[j]=str1[j];
                 }
                 str2[j]='\0';
                 cout<<"\nafter copying string:"<<str2;
            }
void string::concat()


            {
             int count=0,p,q,r;
             char str3[30];
             for(p=0;str1[p]!='\0';p++)
               {
                 str3[p]=str1[p];
                 count++;
               }
               r=count;
             for(q=0;str2[q]!='\0';q++)
               {
                 str3[r]=str2[q];
                 r++;
               }
               str3[r]='\0';
               cout<<"\nthe concatination of two strings:"<<str3;
            }
void main()
            {
              string s;
              int ch;
              do
              {
                clrscr();
                cout<<"\n\t\t   STRINGS     ";
                cout<<"\n\t\t1.string length";
                cout<<"\n\t\t2.string copy";
                cout<<"\n\t\t3.string concortenation";
                cout<<"\n\t\t4.exit";
                cout<<"\nenter your choice:";
                cin>>ch;
                switch(ch)
                  {
                         case 1:
                                     s.read();
                                     s.length();
                                     getch();
                                                                                                                                                                                                 break;

                          case 2:
                                     s.read();
                                     s.copy();
                                     getch();
                                     break;
                          case 3:
                                     s.read();
                                     s.concat();


                                     getch();
                                     break;
                           case 4:
                                    exit(0);
                          default:
                                    cout<<"enter correct choice";
                                    getch();
                                    break;
                          }
                        }while(ch!=4);
 }


OUTPUT:
                                STRINGS
                        1. String length
                        2. String copy
                        3. String concatination
                        4. Exit
Enter your choice:1
Enter first string: lokesh
Enter second string:mca1sem
Length of the first string is: 6
Length of the second string is: 7
Enter your choice: 3
Enter first string: lokesh
Enter second string: mca1sem
Concatination of two strings is: lokeshmca1sem





 Concept Of Sequential Access Using Files

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<iomanip.h>
class student
   {
    public:
            int sno;
            char sname[20];
            int sub1,sub2,sub3;
            int tot;
            float avg;
            char result[20];
            void read();
            void calculate();
            void displaystudent();
   };
void student::read()
  {
            cout<<"\n enter student no:";
            cin>>sno;
            cout<<"\n enter student name:";
            cin>>sname;
            cout<<"\n enter marks in three subjects:";
            cin>>sub1>>sub2>>sub3;
  }
void student::calculate()
  {
            if(sub1>=35&&sub2>=35&&sub3>=35)
             {
               strcpy(result,"pass");
             }
            else
             {
               strcpy(result,"fail");
             }
               tot=sub1+sub2+sub3;
               avg=tot/3;
  }
void student::displaystudent()
  {
            cout.setf(ios::left,ios::adjustfield);
            cout.width(10);
            cout<<sno;
            cout.setf(ios::left,ios::adjustfield);
            cout.width(10);
            cout<<sname;
            cout.setf(ios::left,ios::adjustfield);
            cout.width(10);
            cout<<sub1;
            cout.setf(ios::left,ios::adjustfield);
            cout.width(10);
            cout<<sub2;
            cout.setf(ios::left,ios::adjustfield);
            cout.width(10);
            cout<<sub3;
            cout.setf(ios::left,ios::adjustfield);
            cout.width(10);
            cout<<tot;
            cout.setf(ios::left,ios::adjustfield);
            cout.width(10);
            cout<<avg;
            cout.setf(ios::left,ios::adjustfield);
            cout.width(10);
            cout<<result;
            getch();
  }
void main()
  {
            student s[10];
            ofstream out;
            int sno,n;
            clrscr();
            out.open("lok1.txt",ios::out|ios::app);
            cout<<"\n enter no of students:";
            cin>>n;
            for(int i=0;i<n;i++)
              {
                s[i].read();
                s[i].calculate();
                out.write((char*)&s[i],sizeof(s[i]));
              }
            out.close();
            ifstream in;
            in.open("lok1.txt",ios::in);
            in.seekg(0,ios::beg);
            cout<<"\n enter roll no:";
            cin>>sno;
            while(in.read((char*)&s[i],sizeof(s[i])))
              {
               if(s[i].sno==sno)
                {
                             cout<<"sno"<<setw(10)<<"sname"<<setw(10)<<"sub1"<<setw(10)<<"sub2"
<<setw(10)<<"sub3"<<setw(10)<<"total"<<setw(10)<<"avg"<<setw(10)<<"result"
<<endl;

     s[i].displaystudent();
                 getch();
              }
  }
}


OUTPUT:
  
 enter no of students:2

 enter student no:101

 enter student name :RAJU

 enter marks in three subjects:58
68
78

 enter student no:102

 enter student name :LOKESH

 enter marks in three subjects:87
85
65

 enter roll no:102
sno     sname      sub1      sub2      sub3     total       avg    result
102       LOKESH    87        85        65        237       79        pass
















                                                                                                                    



 Concept Of Random Access Using Files

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<iomanip.h>
#include<stdio.h>
class invest
  {
public:
int code;
char item[20];
int price;
void getdata();
void putdata();
  };
void invest::getdata()
  {
cout<<"\n enter item code:";
cin>>code;
cout<<"\n enter item:";
cin>>item;
cout<<"\n enter item cost:";
cin>>price;
  }
void invest::putdata()
  {
cout<<setw(10)<<code;
cout<<setw(10)<<item;
cout<<setprecision(2)<<setw(10)<<price<<endl;
  }
void main()
  {
clrscr();
invest item;
int ch;
char ch1;
         do
          {
cout<<"\n 1.insert \n 2.display \n 3.update \n 4.delete";
cout<<"\nenter your choice:";
cin>>ch;
switch(ch)
              {
                   case 1:
ofstream out;
out.open("stock10.dat",ios::out|ios::app);
item.getdata();
out.write((char*)&item,sizeof(item));
out.close();
break;
                 case 2:
ifstream in;
in.open("stock10.dat",ios::in);
in.seekg(0,ios::beg);
cout<<"\n item details"<<endl;
while(in.read((char*)&item,sizeof(item)))
    {
       item.putdata();
     }
in.close();
break;
                 case 3:
ifstream fin1("stock10.dat",ios::in);
ofstream fout("stock20.dat",ios::out|ios::app);
cout<<"\n enter code:";
int c;
while(fin1.read((char*)&item,sizeof(item)))
    {
      if(item.code==c)
        {
           item.getdata();
           fout.write((char*)&item,sizeof(item));
       }
     else
      {
 fout.write((char*)&item,sizeof(item));
      }
  }
fin1.close();
fout.close();
remove("stock10.dat");
rename("stock20.dat","stock10.dat");
break;
                  case 4:
ifstream fin2("stock10.dat",ios::in);
ofstream fout1("stock20.dat",ios::out|ios::app);
cout<<"\n enter code:";
cin>>c;
fin2.seekg(0,ios::beg);
while(fin2.read((char*)&item,sizeof(item)))
    {
     if(item.code==c)
        {
           cout<<"\n record is deleted";
            break;
        }
      else
     {
         fout1.write((char*)&item,sizeof(item));
      }
}
fin2.close();
fout1.close();
remove("stock10.dat");
rename("stock20.dat","stock10.dat");
break;
              }
             cout<<"still you want to continue(y/n):";
             cin>>ch1;
          }while(ch1=='y'||ch1=='Y');
           getch();
}



OUTPUT:

 1.insert
 2.display
 3.update
 4.delete
enter your choice:1

 enter item code:1022

 enter item:pen

 enter item cost:26
still you want to continue(y/n):y

 1.insert
 2.display
 3.update
 4.delete
enter your choice:2

 item details
1022      pen       26
still you want to continue(y/n):n


Employee Details Using Constructors

             #include<iostream.h>
             #include<conio.h>
 #define max 3
             class emp
               {
                  public:
int eno;
char name[15];
float basic,hra,da,pf,net;
emp()
   {
cout<<"\n\t enter empno:";
cin>>eno;
cout<<"\n\t enter ename:";
cin>>name;
cout<<"\n\t enter basic:";
cin>>basic;
   }
void display()
  {
da=basic*0.2;
pf=basic*0.5;
hra=basic*0.3;
net=basic+hra+da-pf;
cout<<"\n\n\t***employee details***";
cout<<"\n\t employee name="<<name;
cout<<"\n\t employee number="<<eno;
cout<<"\n\t hra is="<<hra;
cout<<"\n\t da is="<<da;
cout<<"\n\t pfis="<<pf;
cout<<"\n\t net salary is="<<net;
                          }
};
          void main()
              {
                        clrscr();
                        int n;
                        n=5;
                        emp e[max];
                        cout<<"\n\t enter a no:";
                        cin>>n;
                        for(int i=0;i<max;i++)
                             {
                                    if(e[i].eno==n)
                                        {
                                                e[i].display();
                                         }
                             }
                          getch();
                }

Output:
enter empno:1
enter ename:LOKESH
enter basic:6000

enter empno:2
enter ename:KISHORE
enter basic:5000

enter empno:3
enter ename:NAVEEN
enter basic:4000

         enter a no:1

***employee details***
             employee name=LOKESH
            employee number=1
             hra is=1800
             da is=1200
             pf  is=3000
             net salary is=6000


























Types Of Constructors

                        #include<iostream.h>
#include<conio.h>
#include<string.h>
class construct
{
                            int a;
                            float b;
                            char*name;
                              public:
                              construct()
                                 {
                                    a=0;b=0.0;
                                    name="abc";
                                  }
                              construct(int x,float y)
                              {
                                     a=x;
                                     b=y;
                                     name="xy";
                                 }
                                 construct(char*s)
                                 {
                                       a=20;
   b=25.25;
                                        name=new char(strlen(s)+1);
                                        strcpy(name,s);
                                  }
                                 construct(construct &d)
                                 {
                                    a=d.a;
                                    b=d.b;
                                    name=new char(strlen(d.name)+1);
                                    strcpy(name,d.name);
                                 }
                                 void display()
                                     {
                                        clrscr();
                                        cout<<"\n\t value of a="<<a<<"b="<<b;
                                     }
                         };
                      void main()
                      {
                           clrscr();
                            int n;
                            do
                              {
                                  cout<<"\n\n\t types of constuctors";
                                 cout<<"\n\n\t ---------------------";
                                 cout<<"\n\t 1.Default constructor";
                                 cout<<"\n\t 2.Parameterised constructor";
                                 cout<<"\n\t 3.Overloaded constructor";
                                 cout<<"\n\t 4.Copy constructor";
                                 cout<<"\n\t 5.Dynamic constructor";
                                 cout<<"\n\t 6.exit";
                                 cout<<"\n\t enter your choice:";
                                 cin>>n;
                                 switch(n)
                                      {
                                    case 1:
                                                cout<<"\n\t Default constructor";
                                                construct c;
                                                c.display();
                                                break;
                                    case 2:
                                                cout<<"\n\t Parameterised constructor";
                                                construct c1(5,10.5);
                                                c1.display();
                                                break;
                                    case 3:
                                                cout<<"\n\t Overloaded constructor";
                                                construct c2("abc");
                                                c2.display();
                                                break;
                                    case 4:
                                                cout<<"\n\t copy constructor";
                                                construct c3=c2;
                                                c3.display();
                                                break;
                                    case 5:
                                                cout<<"\n\t Dynamic constructor";
                                                construct c4(c3);
                                                c4.display();
                                                break;
                                    case 6:
                                                cout<<"\n\n\t**end**";
                                                break;
                                    default:
                                                cout<<"\n\t your choice is wrong";
                                                break;
                                        }
                              }while(n!=6);
                               getch();
                        }




Output:
 types of constuctors
---------------------------    
         1.Default constructor
         2.Parameterised constructor
         3.Overloaded constructor
         4.Copy constructor
         5.Dynamic constructor
         6.exit
         enter your choice:1
            value of a=0b=0
types of constuctors
 --------------------------
         1.Default constructor
         2.Parameterised constructor
         3.Overloaded constructor
         4.Copy constructor
         5.Dynamic constructor
         6.exit
         enter your choice:2
         value of a=5b=10.5
types of constuctors
--------------------------
         1.Default constructor
         2.Parameterised constructor
         3.Overloaded constructor
         4.Copy constructor
         5.Dynamic constructor
         6.exit
         enter your choice:3
         value of a=20b=25.25
types of constuctors
--------------------------
         1.Default constructor
         2.Parameterised constructor
         3.Overloaded constructor
         4.Copy constructor
         5.Dynamic constructor
         6.exit
         enter your choice:4
         value of a=20b=25.25









Constructor Over Loading

#include<iostream.h>;
#include<conio.h>;
class area
    {
          public:
              area(float x,float y)
               {
                cout<<"\n area of tryangle is"<<x*y/2;
               }
               area(int x,int y)
               {
                cout<<"area of rectangle is"<<x*y;
               }
               area(int a)
               {
                cout<<"area of cercile is "<<3.14*a*a;
                }
               area(float a)
               {
                cout<<"area of sphere  is "<<4*3.14*a*a;
               }
} ;
void main()
  {
    clrscr();
    int n,a,b;
    float x,y;
      do
         {
    cout<<"\n\tenter ur choice here";
    cout<<"\n\t1.area of tryangle";
    cout<<"\n\t2.area of rectangle";
    cout<<"\n\t3.area of circle";
    cout<<"\n\t4.area of sphere";
    cout<<"\n\t0.exit";
    cout<<"\n\tenter ur choice here ";
    cin>>n;
    switch(n)
        {
           case 1:
                        cout<<"\n\t ur performing area  of triangle";
                        cout<<"\n\tenter base and height of try angle";
                        cin>>x>>y;
                        area a1(x,y);
                        break;

           case 2:
                        cout<<"\n\t ur performing area  of rectangle";
                        cout<<"enter length and breadth";
                        cin>>a>>b;
                        area a2(a,b);
                        break;


           case 3:
                        cout<<"\n\t ur performing area  of cercle";
                        cout<<"enter radius of cercle";
                        cin>>a;
                        area a3(a);
                        break;
          case 4:
                        cout<<"\n\t ur performing area  of sphere";
                        cout<<"enter radius ";
                        cin>>x;
                        area a4(x);
                        break;
          case 0:
                        cout<<"\n exit";
         default:    cout<<"enter a correct choice";

   }

       }while(n!=0);
            }


Output:           

                        Enter Ur choice
1.Area of Triangle

2.Area of Rectangle

3.Area of Circle

4.Area of Sphere

0.exit 3
Ur performing Area of Cricle
 Enter Radius3
 Area of Circle is:28.26
 Enter Ur choice
 1.Area of Triangle

 2.Area of Rectangle

 3.Area of Circle

 4.Area of Sphere

 0.exit 4
Ur performing Area of Sphere
Enter Radius5
Area of Sphere is:452.16                                                          
Enter Ur choice
1.Area of Triangle

2.Area of Rectangle

3.Area of Circle

4.Area of Sphere

0.exit 0
Enter correct choice4


Complex numbers using operator overloading

#include<iostream.h>
#include<conio.h>
class complex
{
  private:
                float real,imag;
  public:
             complex()
             {
                 real=imag=0;
             }
             void getdata()
                {
                   cout<<"\n\n Real part:";
                   cin>>real;
                   cout<<"\n\n Imaginary part:";
                   cin>>imag;
                }
              void outdata(char *msg)
                 {
                    cout<<endl<<msg;
                    cout<<"("<<real<<","<<imag<<")";
                  }
             complex operator+(complex c2);
             complex operator-(complex c2);
             complex operator*(complex c2);
             complex operator/(complex c2);
};
complex complex::operator+(complex c2 )
    {
      complex temp;
      temp.real=real+c2.real;
      temp.imag=imag+c2.imag;
      return(temp);

    }
complex complex::operator-(complex c2)
   {
      complex temp;
      temp.real=real-c2.real;
      temp.imag=imag-c2.imag;
      return(temp);
   }
complex complex::operator*(complex c2)
   {
      complex temp;
      temp.real=real*c2.real-imag*c2.imag;
      temp.imag=real*c2.imag+imag*c2.real;
      return(temp);
     }
complex complex::operator/(complex c2)
   {
       complex temp;
       float qt;
      qt=c2.real*c2.real+c2.imag*c2.imag;
       temp.real=(real*c2.real+imag*c2.imag)/qt;
       temp.imag=(imag*c2.real-real*c2.imag)/qt;
       return(temp);
   }
void main()
   {
  clrscr();
  complex c1,c2,c3;
  cout<<"\n\n Enter complex number c1:"<<endl;
  c1.getdata();
  cout<<"\n\n Enter complex number c2:"<<endl;
  c2.getdata();
  cout<<"\n\n Entered complex numbers are";
  c1.outdata("c1=");
  c2.outdata("c2=");
  cout<<"\n\n COMPUTAIONAL RESULTS ARE.....";
  c3=c1+c2;
  c3.outdata("c3=c1+c2");
  c3=c1-c2;
  c3.outdata("c3=c1-c2");
  c3=c1*c2;
  c3.outdata("c3=c1*c2");
  c3=c1/c2;
  c3.outdata("c3=c1/c2");
  c3=c1+c2+c1+c2;
  c3.outdata("c3=c1+c2+c1+c2");
  c3=c1*c2+c1/c2;
  c3.outdata("c3=c1*c2+c1/c2");
  getch();
    }













 OUTPUT:



 Enter complex number c1:

 Real part:3

 Imaginary part:-5

 Enter complex number c2:

 Real part:2

 Imaginary part:8

 Entered complex numbers are
 c1=(3,-5)

 c2=(2,8)

 COMPUTAIONAL RESULTS ARE.....

 c3=c1+c2(5,3)

 c3=c1-c2(1,-13)

 c3=c1*c2(46,14)

 c3=c1/c2(-0.5,-0.5)

 c3=c1+c2+c1+c2(10,6)

c3=c1*c2+c1/c2(45.5,13.5)















// MATHEMATICAL OPERATIONS ON MATRICES

#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
class matrix
  {
            int r,c,a[10][10];
            public:
                        matrix(){}
                        matrix(int a,int b)
                          {    r=a;
                                c=b;
                          }
                        matrix operator +(matrix) ;
                        matrix operator -(matrix);
                        matrix operator *(matrix);
                        void show();
                        void read();
    };
 matrix matrix::operator +(matrix m)
      {
             matrix n;
             if((r==m.r)&&(c==m.c))
             {
                 n.r=r;
                 n.c=c;
                 for(int i=0;i<r;i++)
                 {
                        for(int j=0;j<c;j++)
                        {
                           n.a[i][j]=a[i][j]+m.a[i][j];

                         }
                  }
              }
              else
              cout<<"matrix addition not possible";
              return n;
      }
 matrix  matrix:: operator -(matrix m)
     {
            matrix n;
            if((r==m.r)&&(c==m.c))
            {
              n.r=r;
              n.c=c;
              for(int i=0;i<r;i++)
                 {
                     for(int j=0;j<c;j++)
                      {
                         n.a[i][j]=a[i][j]-m.a[i][j];
          }
    }
         }
      else
      cout<<"matrix subtraction not possible";
      return n;
}
matrix matrix::operator *(matrix m)
{
   matrix n;
   if(c==m.r)
      {
        n.r=r;n.c=c;
         for(int i=0;i<r;i++)
           {
              for(int j=0;j<c;j++)
                {
                   n.a[i][j]=0;
                   for(int k=0;k<c;k++)
                    {
                       n.a[i][j]=n.a[i][j]+a[i][k]*m.a[k][j];
                    }
               }
         }
     }
    else
    cout<<"\n matrix multiplication is not possible";
    return n;
}
void matrix::read()
  {
     for(int i=0;i<r;i++)
      {
         for(int j=0;j<c;j++)
           {
              cin>>a[i][j];
           }
       }
   }
void matrix::show()
{
       for(int i=0;i<r;i++)
          {
             for(int j=0;j<c;j++)
               {
              cout<<a[i][j]<<" ";
            }
             cout<<endl;
        }
 }
void main()
{
int a,b,x,y,n;
char ch;
clrscr();
cout<<"Enter rows and columns for first matris";
cin>>x>>y;
matrix m(x,y);
cout<<"Enter number of rows and columns for second matrix";
cin>>a>>b;
matrix m1(a,b);
cout<<"\n Enter elements for first matrix";
m.read();
cout<<"\n Enter elements for second matrix";
m1.read();
do
              {

cout<<"\n 1.addition \n 2.subtraction \n 3.multiplication \n 4.exit";
cout<<"\n Enter your choice";
cin>>n;
switch(n)
    {
case 1:matrix a;
            a=m+m1;
            a.show();
            break;
case 2: matrix a1;
            a1=m-m1;
            a1.show();
            break;
case 3: matrix a2;
            a2=m*m1;
            a2.show();
            break;
            case 4:return;
            default:cout<<"invalid option";
       }
cout<<"\n Do you want to continue(y/n)";
cin>>ch;
             }while(ch=='y'||ch=='Y');
        getch();
 }






 OUTPUT:

Enter rows and columns for first matris2
2
Enter number of rows and columns for second matrix2
2

 Enter elements for first matrix12
12
23
23

 Enter elements for second matrix12
12
23

23

 1.addition
 2.subtraction
 3.multiplication
 4.exit
 Enter your choice:3
420 420
805 805

 Do you want to continue(y/n): y

 1.addition
 2.subtraction
 3.multiplication
 4.exit
 Enter your choice: 1
24 24
46 46

 Do you want to continue(y/n): n







//  CONCEPTS OF FILES

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<iomanip.h>
class employee
{
 public:
            int empno;
            char name[20];
            float salary;
            void getdata();
            void putdata();
};
void employee::getdata()
{
            cout<<"\n\n Enter employee number:";
            cin>>empno;
            cout<<"\n\n Enter name of the employee:";
            cin>>name;
            cout<<"\n\n Enter employee salary:";
            cin>>salary;
}
void employee::putdata()
{
  cout<<setw(10)<<empno;
  cout<<setw(10)<<name;
  cout<<setprecision(2)<<setw(10)<<salary<<endl;
 }
 void main()
 {
  employee obj;
  int ch;
  char ch1;
  clrscr();
  do
     {
   cout<<"\n\n\t 1.Insert \n\n\t 2.Display \n\n\t 3.Update \n\n\t 4.Delete";
   cout<<endl;
   cout<<"\n\n Enter your choice:";
   cin>>ch;
  
   switch(ch)
      {
    case 1:
               ofstream out;
               out.open("employee1.dat",ios::out|ios::app);
               obj.getdata();
               out.write((char*)&obj,sizeof(obj));
               out.close();
               break;
    case 2:
               ifstream in;
               in.open("empolyee1.dat",ios::in);
               in.seekg(0,ios::beg);
               cout<<"\n\n Employee details";
               cout<<endl;
               while(in.read((char*)&obj,sizeof(obj)))
                 {
                   obj.putdata();
                 }
               in.close();
               break;
    case 3:
               int c;
               ifstream fin1("employee1.dat",ios::in);
               ofstream fout("emp2.dat",ios::out|ios::app);
               cout<<"\n\n Enter employee number:";
               cin>>c;
               while(fin1.read((char*)&obj,sizeof(obj)))
               {
                   if(obj.empno==c)
                     {
                        obj.getdata();
                        fout.write((char*)&obj,sizeof(obj));
                     }
                else
                    {
                        fout.write((char*)&obj,sizeof(obj));
                    }
               }
               fin1.close();
               fout.close();
               remove("employee1.dat");
               rename("emp2.dat","employee1.dat");
               break;


   case 4:
              ifstream fin3("employee1.dat",ios::in);
              ofstream fout5("emp2.dat",ios::out|ios::app);
              int c1;
              cout<<"\n\n Enter employee number:";
              cin>>c1;
              while(fin3.read((char*)&obj,sizeof(obj)))
                 {
                    if(obj.empno==c1)
                     {
                        fout5.write((char*)&obj,sizeof(obj));
                 }
               else
                  {
                        fout5.write((char*)&obj,sizeof(obj));
                   }
                }
              fin3.close();
              fout5.close();
              remove("employee1.dat");
              rename("emp2.dat","employee1.dat");
              break;
   case 5:
              ifstream fin4("employee1.dat",ios::in);
              ofstream fout6("emp2.dat",ios::out|ios::app);
              int c2;
              cout<<"\n\n Enter employe number:";
              cin>>c2;
              fin4.seekg(0,ios::beg);
              while(fin4.read((char*)&obj,sizeof(obj)))
                 {
                    if(obj.empno==c2)
                      {
                        cout<<"\n Record deleted";
                        break;
                     }
               else
                     {
                        fout.write((char*)&obj,sizeof(obj));
                     }
                 }
              fin4.close();
              fout6.close();
              remove("employee1.dat");
              rename("emp2.dat","employee1.dat");
              break;
             }
             cout<<"\n\n Do you want to conyinue[y/n];";
             cin>>ch1;
}while(ch1=='y'||ch1=='Y');
       getch();
}










 OUTPUT:
           1. Insert
           2. Display
           3. Update
           4. Delete
Enter your choice: 1
Enter employee number: 1010
Enter employee name: MUNI
Enter employee salary: 5000
Do you want to continue[y/n]:y
           1. Insert
           2. Display
           3. Update
           4. Delete
Enter your choice:2
Employee details
 1010      MUNI      5000
Do you want to continue[y/n]: y
            1. Insert
            2. Display
            3. Update
            4. Delete
Enter your choice: 3
Enter employee number: 1010
Enter employee number: 120
Enter employee name: SEKHAR
Enter employee salary: 10000
Do you want to continue[y/n]: y
              1. Insert
              2. Display
              3. Update
              4. Delete
Enter your choice: 2
Employee details
  120   SEKHAR   10000
Do you want to continue[y/n]:n   


// CONCEPT OF HIERARCHICAL INHERITANCE

#include<iostream.h>
#include<conio.h>
const int maxlength=25;
class vehicle
{
  protected:
                 char name[maxlength];
                 int wheelcount;
  public:
                 void getdata()
                    {
                   cout<<"\n Enter name of the vehicle:";
                   cin>>name;
                   cout<<"\n Enter number of wheels:";
                   cin>>wheelcount;
                    }
                 void displaydata()
                    {
                   cout<<"\n\n Name of Vehicle:"<<name;
                   cout<<"\n\n  Wheelcount:"<<wheelcount;
                    }
};
class lightmotor:public vehicle
{
  protected:
                int speedlimit;
  public:
              void getdata()
      {
                 vehicle::getdata();
                 cout<<"\n\n Enter speedlimit:";
                 cin>>speedlimit;
      }
              void displaydata()
                 {
                 vehicle::displaydata();
                 cout<<"\n\n Speed limit:"<<speedlimit;
                 cout<<endl;
                 }
};
class heavymotor:public vehicle
{
  protected:
                 int lc;
                 int pr;
  public:
               void getdata()
                  {
                 vehicle::getdata();
                 cout<<"\n\n Load capacity:"<<lc;
                 cout<<"\n\n Permit:"<<pr;
                  }
};
class gearmotor:public lightmotor
{
  protected:
                 int gearcount;
  public:
                 void getdata()
                     {
                    lightmotor::getdata();
                   cout<<"\n\n Enter no.of gears:";
                   cin>>gearcount;
                    }
                 void displaydata()
                    {
                   lightmotor::displaydata();
                   cout<<"\n\n Gears are:"<<gearcount;
                    }
};
class nongearmotor:public lightmotor
{
  public:
             void getdata()
               {
                   lightmotor::displaydata();
               }
};
class passenger:public heavymotor
{
  protected:
                 int sit;
                 int stand;
  public:
                 void getdata()
                    {
                   heavymotor::getdata();
                   cout<<"\n\n Enter maximum seats:";
                   cin>>sit;
                   cout<<"\n\n Enter minimum seats:";
                   cin>>stand;
                     }
                 void displaydata()
                    {
                   heavymotor::displaydata();
                   cout<<"\n\n Maximum seats:"<<sit;
                   cout<<"\n\n minimum seats:"<<stand;
                     }
};
class goods:public heavymotor
{
  public:
               void getdata()
                  {
                    heavymotor::getdata();
                  }
               void displaydata()
                  {
                     heavymotor::displaydata();
                  }
};
void main()
 {
 clrscr();
 gearmotor vehi1;
 passenger vehi2;
 cout<<"\n\n\t" ;
 cout<<"\n\n Enter data for gearmotor vehicle"<<endl;
 vehi1.getdata();
 cout<<"\n\n\t";
 cout<<"\n\n Enter data for passenger vehicle:"<<endl;
 vehi2.getdata();
 cout<<"\n\n\t";
 cout<<"\n\n Data of motor vehicle"<<endl;
 vehi1.displaydata();
 cout<<"\n\n\t";
 cout<<"\n\n Data of passenger vehicle"<<endl;
 vehi2.displaydata();
 cout<<endl;
 cout<<"\n\n All are executed successfully"<<endl;
 getch();
 }


 OUTPUT:

 Enter data for gearmotor vehicle

 Enter name of the vehicle:car

 Enter number of wheels:4


 Enter speedlimit:120


 Enter no.of gears:4




 Enter data for passenger vehicle:

 Enter name of the vehicle:bus

 Enter number of wheels:6


 Load capacity:240

 Permit:-29184

 Enter maximum seats:40

 Enter minimum seats:30




 Data of motor vehicle


 Name of Vehicle:car

  Wheelcount:4

 Speed limit:120


 Gears are:4



 Data of passenger vehicle


 Name of Vehicle:bus

  Wheelcount:6

 Maximum seats:40

 minimum seats:30


 All are executed successfully


// CONCEPT OF MULTIPLE  INHERITANCE

#include<iostream.h>
#include<conio.h>
#include<string.h>
class student
{
public:
            int rno;
            char name[20],subname[20],subcode[20];
            void read();
            void display();
};
class marks
{
public:
            int inmarks,exmarks;
            void read();
            void display();
};
class result:public student,public marks
{
public:
            int total;
            void read()
               {
            student::read();
            marks::read();
               }
            void cal()
              {
                       total=inmarks+exmarks;
               }
            void display()
               {
            student::display();
            marks::display();
               }
};
void student::read()
{
cout<<"\n Enter student regno:";
cin>>rno;
cout<<"\n Enter student name:";
cin>>name;
cout<<"\n Enter subject name:";
cin>>subname;
cout<<"\n Enter subject code:";
cin>>subcode;
}                
void student::display()
{
cout<<"\n student regno:"<<rno;
cout<<"\n student name:"<<name;
cout<<"\n subject name:"<<subname;
cout<<"\n subject code:"<<subcode;
}
void marks::read()
  {
cout<<"\n Enter student internal marks:";
cin>>inmarks;
cout<<"\n Enter student external marks:";
cin>>exmarks;
  }
void marks::display()
  {
cout<<"\n internal marks:"<<inmarks;
cout<<"\n external marks:"<<exmarks;
  }
void menu()
  {
cout<<"\n 1.insert new entry";
cout<<"\n 2.delete an entry";
cout<<"\n 3.display all";
cout<<"\n 4.display the selected entry";
cout<<"\n 5.exit";
  }
void main()
{
result r1[20];
int n=0,i,j,count=0,ch,no;
clrscr();
menu();
cout<<"\n Enter ur choice:";
cin>>ch;
while(ch<=4)
{
   switch(ch)
     {
case 1:
            r1[count].read();
            r1[count].cal();
            n++;
            count++;
            break;
case 2:
            cout<<"\n Enter regno to delete:";
            cin>>no;
            for(i=0;i<n;i++)
               {
                  if(r1[i].rno==0)
                       {
                          count--;
                          for(j=i;j<n;j++)
                            {
            r1[i].rno=r1[i+1].rno;
            strcpy(r1[i].name,r1[i+1].name);
            strcpy(r1[i].subname,r1[i+1].subname);
            strcpy(r1[i].subcode,r1[i+1].subcode);
            r1[i].exmarks=r1[i+1].exmarks;
            r1[i].inmarks=r1[i+1].inmarks;
            r1[i].total=r1[i+1].total;
            i++;
                             }
                     }
              }
            break;
case 3:
            for(i=0;i<count;i++)
               {
                   r1[i].display();
               }
            break;
case 4:
            cout<<"\n Enter regno to display:";
            for(i=0;i<count;i++)
               {
                  if(r1[i].rno==no)
                     {
                        r1[i].display();
                     }
              }
            break;
                }
             menu();
             cout<<"\n Enter u r choice to continue:";
             cin>>ch;
        }

 OUTPUT:


 1.insert new entry
 2.delete an entry
 3.display all
 4.display the selected entry
 5.exit


 Enter ur choice:1

 Enter student regno:10

 Enter student name:priya

 Enter subject name:ip

 Enter subject code:123

 Enter student internal marks:30

 Enter student external marks:70

 1.insert new entry
 2.delete an entry
 3.display all
 4.display the selected entry
 5.exit
 Enter u r choice to continue:2

 Enter regno to delete:10

 1.insert new entry
 2.delete an entry
 3.display all
 4.display the selected entry
 5.exit
 Enter u r choice to continue:3

 student regno:10
 student name:priya
 subject name:ip
 subject code:123
 internal marks:30
 external marks:70
 1.insert new entry
 2.delete an entry
 3.display all
 4.display the selected entry
 5.exit
 Enter u r choice to continue:n


//EMPLOYEE DETAILS USING CLASSES


#include<iostream.h>
#include<conio.h>
class employee
{
protected:
            int eno;
            char ename[10];
public:
            void accept()
               {
            cout<<"enter emp no:";
            cin>>eno;
            cout<<"enter name of the employee:";
            cin>>ename;
                }
            void displayemp()
               {
                       cout<<"\n empno="<<"\t"<<eno<<"\n empname="<<"\t"<<ename;
                }
};
class job:public employee
{
protected:
            char dsgn[20];
            float sal;
public:
            void getemp()
               {
            accept();
            cout<<"\n enter designation:";
            cin>>dsgn;
            cout<<"\n enter salary:";
            cin>>sal;
               }
            void display()
               {
                      displayemp();
                      cout<<"\n designation"<<"\t"<<dsgn<<"\n sal"<<"\t"<<sal;
                      cout<<endl;
               }
};
class salary:public job
  {
float nsal,da,hra;
public:
            void read()
               {
                  getemp();
                }
            void calculate()
                {
            da=sal*0.02;
            hra=sal*0.06;
            nsal=da+hra+sal;
               }
            void putdata()
                {
                        display();
                         cout<<"\n da="<<"\t"<<da<<"\n hra="<<"\t"<<hra<<"\n sal="<<"\t"<<sal<<endl;
                 }
};
void main()
{
clrscr();
salary s[10];
int n,i,ch;
cout<<"\n enter no.of employees:";
cin>>n;
cout<<"\n 1.read 2.calculate 3.display";
cout<<"\n enter ur choice:";
cin>>ch;
while(ch<=3)
   {
      switch(ch)
          {
case 1:
            for(i=0;i<n;i++)
            s[i].read();
            break;
case 2:
            for(i=0;i<n;i++)
            s[i].calculate();
            cout<<"\n caluculated completed";
            break;
case 3:
            cout<<"\n                 \n";
            for(i=0;i<n;i++)
            s[i].putdata();
            cout<<"\n                  \n";
            break;
            }
  cout<<"\n 1.read 2.calculate 3.display";
  cout<<"\n enter u r choice";
   cin>>ch;
}
getch();
}

    OUTPUT:



 enter no.of employees:1

 1.read 2.calculate 3.display
 enter ur choice:1
enter emp no:1
enter name of the employee:ABC

 enter designation:SOFTWARE

 enter salary:40000

 1.read 2.calculate 3.display
 enter u r choice2

 caluculated completed
 1.read 2.calculate 3.display
 enter u r choice3



 empno= 1
 empname=       ABC
 designation    SOFTWARE
 sal    40000

 da=    800
 hra=   2400
 sal=   40000



 1.read 2.calculate 3.display
 enter u r choice:4

No comments:

Post a Comment