Sunday, 2 April 2017

SF -II assignment group C



Assignments Unit - 2
SF -II

GROUP - C


1)    Online application form for only one user using multilevel inheritance.
2)    Working of lift in the form of infinite loop using multiple inheritance.
3)    Washing machine control (timer=15 min) using hybrid inheritance.
4)    Define a class bag of 50 integers. The values of the integers is between 1 and 10. Overload the subscript operator.
5)    Define a class license that has a license no, name and address. Define constructors that take on parameter that is just the number and another where all parameters are present.  
6)    Define a class template pair which can have a pair of values. The type of the values is the parameter of the template. Define a member function add() which adds the two values and returns the sum.

Solutions:
1)
#include<iostream>
#include<string.h>
#include<cstdio>
using namespace std;
class roll
{
          public:
          long rollNo;
};
class name:public roll
{
          public:
          char name[20],fname[20],mname[20];
};
class marks:public name
{
          public:
          int marks[5];
};
class address:public marks
{
          public:
          char houseNo[10],village[20],district[20],state[20];
          void get()
          {
                    cout<<"Enter your name\t";
                    gets(name);
                    cout<<"Enter your father name\t";
                    gets(fname);
                    cout<<"Enter your mother's name\t";
                    gets(mname);
                    cout<<"Enter your Address\nHouse no.\t";
                    gets(houseNo);
                    cout<<"Village/Town\t";
                    gets(village);
                    cout<<"District\t";
                    gets(district);
                    cout<<"State\t";
                    gets(state);
                    cout<<"Enter your Higher Secondary roll number\t";
                    cin>>rollNo;
                    cout<<"Enter your marks :\n";
                    for(int i=0;i<5;i++)
                    {
                              cout<<"Marks in subject "<<(i+1)<<"\t";
                              cin>>marks[i];
                    }
          }
          void show()
          {
                    cout<<"\nRoll number :\t"<<rollNo;
                    cout<<"\nName :\t"<<name;
                    cout<<"\nFather's name :\t"<<fname;
                    cout<<"\nMother's name :\t"<<mname;
                    cout<<"\nAddress\n";
                    cout<<"House No. : "<<houseNo;
                    cout<<"\t\tVillage/Town : "<<village;
                    cout<<"\nDistrict : "<<district;
                    cout<<"\t\tState : "<<state;
                    cout<<"\nMarks are";
                    for(int i=0;i<5;i++)
                              cout<<"\nSub "<<(i+1)<<" : "<<marks[i];
          }
};
int main()
{
          address obj;
          obj.get();
          cout<<"\n\nThe entered details are\n";
          obj.show();
          return 0;
}



2)
#include<iostream>
#include<windows.h>
#include<stdlib.h>
using namespace std;
class ground
{
          public:
                    void show0()
                    {
                              cout<<"\nGround level reached";
                    }
};
class first
{
          public:
                    void show1()
                    {
                              cout<<"\nFirst level reached";
                    }
};
class second
{
          public:
                    void show2()
                    {
                              cout<<"Second level reached";
                    }
};
class third
{
          public:
                    void show3()
                    {
                              cout<<"Third level reached";
                    }
};
class fourth
{
          public:
                    void show4()
                    {
                              cout<<"Fourth level reached";
                    }
};
class lift:ground,first,second,third,fourth
{
          int floorNo;
          public:
                    void travel()
                    {
                              while(1)
                              {
                              cout<<"\nEnter floor number\t";
                              cin>>floorNo;
                              switch(floorNo)
                              {
                                        case 0:
                                                  Sleep(1000);
                                                  show0();
                                                  break;
                                        case 1:
                                                  for(int i=1;i>=0;i--)
                                                  {
                                                            cout<<"Wait "<<(i)<<" Seconds";
                                                            Sleep(1000);
                                                            system("cls");
                                                  }
                                                  show1();
                                                  break;
                                        case 2:
                                                  for(int i=2;i>=0;i--)
                                                  {
                                                            cout<<"Wait "<<(i)<<" Seconds";
                                                            Sleep(1000);
                                                            system("cls");
                                                  }
                                                  show2();
                                                  break;
                                        case 3:
                                                  for(int i=3;i>=0;i--)
                                                  {
                                                            cout<<"Wait "<<(i)<<" Seconds";
                                                            Sleep(1000);
                                                            system("cls");
                                                  }
                                                  show3();
                                                  break;
                                        case 4:         
                                                  for(int i=4;i>=0;i--)
                                                  {
                                                            cout<<"Wait "<<(i)<<" Seconds";
                                                            Sleep(1000);
                                                            system("cls");
                                                  }
                                                  show4();
                                                  break;                                                 
                                        default:
                                                  cout<<"\nThis floor is not available";
                              }
                    }
                    }
};
int main()
{
          lift obj;
          obj.travel();
          return 0;
}



3)

#include<iostream>
#include<stdlib.h>
#include<windows.h>
using namespace std;
class clothName
{
          public:
                    char name[20];
                    void getClothName()
                    {
                              cout<<"Enter the cloth name\t";
                              cin>>name;
                    }
};
class stir:public clothName                  //single inheritance
{
          public:
                    void stirring()
                    {
                              int i,j;
                              for(i=8;i>=0;i--)
                              {
                                        for(j=60;j>=0;j--)
                                        {
                                                  cout<<"Stirring \nTime Left\n";
                                                  cout<<i<<" : "<<j;
                                                  Sleep(1000);
                                                  system("cls");
                                        }
                              }
                    }
};

class rinse :public stir                           //multilevel inheritance
{
          public:
                    void rinseing()
                    {
                              int i,j;
                              for(i=7;i>=0;i--)
                              {
                                        for(j=60;j>=0;j--)
                                        {
                                                  cout<<"Rinsing \nTime Left\n";
                                                  cout<<i<<" : "<<j;
                                                  Sleep(1000);
                                                  system("cls");
                                        }
                              }       
                    }
                   
};
int main()
{
          rinse obj;
          obj.getClothName();
          obj.stirring();
          obj.rinseing();
          cout<<"Cloth Washed";
         
          return 0;
}





4)
#include<iostream>
using namespace std;
class bag
{
          int no[50];
          public:
                    bag()
                    {
                              for(int i=0;i<50;i++)
                              {
                                        no[i]=0;
                              }
                    }
                    int operator [](int n)
                    {
                              int i;
                              for(i=0;i<50;i++)
                              {
                                        no[i]=(i+1)%10;
                              }
                              if(n>50)
                              {
                                        cout<<"The index value is present default returning first element\t";
                                        return no[0];
                              }
                              return no[n];
                    }
};
int main()
{
          bag obj;
          int n;
          cout<<"Enter the index value of elemet you want to see\t";
          cin>>n;
          cout<<obj[n];
          return 0;
}



5)
#include<iostream>
#include<string.h>
using namespace std;
class license
{
          int licenseNo;
          char name[20],address[50];
          public:
          license(int lNo)
          {
                    licenseNo = lNo;
                    strcpy(name,"NULL");
                    strcpy(address,"NULL");
                    }       
          license(int lno,char *name1,char *address1)
          {
                    licenseNo=lno;
                    strcpy(name,name1);
                    strcpy(address,address1);
                   
          }
          void show()
          {
                    cout<<"\nLicense number\t"<<licenseNo;
                    cout<<"\nName \t "<<name;
                    cout<<"\nAddress \t "<<address;
          }
};
int main()
{
          license obj1(4568);
          license obj2(3423,"Knight","Oak Carlifornia USA ");
          obj2.show();
          obj1.show();
}



6)
#include<iostream>
using namespace std;
template <class T>
class pair1
{
          T a;
          T b;
          public:
          pair1(T x,T y)
          {
                    a=x;
                    b=y;
                    }       
                    T add()
                    {
                              return a+b;
                    }                                        
};                                                           
int main()
{
          pair1 <int>obj(4,6);
          cout<<"\nThe sum of the object is \t"<<obj.add();
          return 0;
}

SAMPLE OUTPUT:

No comments:

Post a Comment