Assignment Unit -2
SF-2
GROUP - D
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 hierarchy inheritance.
4) 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.
5) Define
a class “word” which can hold a word where the length of the word is specified
in the constructor. Implement the constructor and destructor.
6) Write a
c++ program that will give the conditions of the environment required, food
habits and unique characteristic of pet animal’s fish and dog. Define a base
called pet that describe any common house hold pet; two derived classes called
fish and dog with item specific to that type of animals. Write pure virtual
function in the base class for the operations that are common to both type of
animals. Write a program to test the usage of classes.
#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>
#include<string.h>
using namespace std;
class
license
{
int licenseNo;
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();
}
5)
#include<iostream>
using
namespace std;
class
word
{
char *name;
public:
word(int n)
{
name = new
char[n];
cout<<"Word
of length "<<n<<" is created";
}
~word()
{
delete name;
cout<<"\nThe
word is deleted";
}
};
int
main()
{
word obj(10);
return 0;
}
6)
#include<iostream>
#include<string.h>
using
namespace std;
class
pet
{
public:
char petname[20];
pet()
{
}
pet(char *name)
{
strcpy(petname,name);
virtual void
environment()=0;
};
class
dog:public pet
{
public:
dog(char *name)
{
strcpy(petname,name);
}
void environment()
{
cout<<"\nHi
I am "<<petname<<"and i like to live in my house";
}
};
class
fish:public pet
{
public:
fish(char *name)
{
strcpy(petname,name);
}
{
cout<<"\nHi
I am "<<petname<<" and i like to swim i water";
}
};
int
main()
{
pet *base1,*base2;
dog dog("Dog");
fish fish("Fish");
base1=&dog;
base2=&fish;
base1->environment();
base2->environment();
return 0;
}
No comments:
Post a Comment