#include<iostream.h>
#include <string.h>
#include<stdlib.h>
using namespace std;
//----------------defining user class----------------------------
class user{
//data member of user class
char * ID;
char * Name;
char * Address;
protected:
char * Status;
//public interface of user class
public:
// Default and overloaded constructors
user();
user(char * ID,char * Name,char * Address,char * Status);
// Setter and Getter fucntions
void set_Name();
const char * get_Name() const;
void set_add();
void verify_user();
// Destructor
~user();
// end of user class
};
// Implementation of overloaded constructor
user::user(char * id,char * aname,char * address,char * astatus){
ID=new char[strlen(id)+1];
strcpy(ID,id);
Name = new char[strlen(aname)+1];
strcpy(Name,aname);
Address = new char[strlen(address)+1];
strcpy(Address,address);
Status = new char[strlen(astatus)+1];
strcpy(Status,astatus);
}
// Implementation of set_Name() method
void user::set_Name(){
char name[50];
cout<<"\nEnter user name:"<<"\n";
cin.getline(name,50);
Name = new char[strlen(name)+1];
strcpy(Name,name);
}
// Implementation of get_Name() method
const char * user::get_Name() const{
if(Name != NULL){
return Name;
}
}
// Implementation of set_add() method to set the value of Address
void user::set_add(){
char add[300];
cout<<"\nEnter address:"<<"\n";
cin.getline(add,300);
Address = new char[strlen(add)+1];
strcpy(Address,add);
}
// Implementation of Verify_user() method, to varify a user
void user::verify_user() {
cout<<"\n\n -------------User Verification---------\n\n";
//----set_Name function call---------
set_Name();
//--------set_address call---------
set_add();
//------set status as verified----------
char stat[20]="verified";
Status = new char[strlen(stat)+1];
strcpy(Status,stat);
cout<<"\n\nUser\t"<<Status<<"\n\n";
}
// Implementation of destructor
user::~user(){
delete []ID;
delete []Name;
delete []Address;
delete [] Status;
}
//----------------defining Member class----------------------------
// Inheritance relationship between Member and user classes
class Member:public user{
// Data members of Member class
char * Password;
//public interface for the Member class
public:
//Overloaded constructor
Member(char * ID,char * Name,char * Address,char * Status,char * Password);
// Setter and getter fucntions
void passw();
const char * get_password() const;
void verify_user();
void add_mem();
void delete_mem();
~Member();
};
// Implementation of overloaded constructor
Member::Member(char * id,char * an,char * add,char * stat,char * pass):user(id, an, add, stat){
Password = new char[strlen(pass)+1];
strcpy(Password,pass);
}
// Implementation of passw() method, to verify password
void Member::passw(){
char pass[40];
cout<<"\nEnter password:"<<"\n";
cin.getline(pass,40);
Password = new char[strlen(pass)+1];
strcpy(Password,pass);
}
// Implementation of getter function
const char * Member::get_password() const{
if(Password != NULL){
return Password;
}
}
// Overriding the verify_user() method in Member class
void Member::verify_user() {
cout<<"\n\n -------------Member User Verification---------\n\n";
//----------assigning password to user---------
passw();
//------set status as Member user----------
char stat[20]="Member";
Status = new char[strlen(stat)+1];
strcpy(Status,stat);
cout<<"\n\nUser is "<<Status<<"\n\n";
}
// ------------Add Member-------------------
void Member::add_mem(){
cout<<"a member has been added";
}
//-------------------delete Member----------
void Member::delete_mem(){
cout<<"a member has been deleted";
}
//-----------Destructor Implementation---------------
Member::~Member(){
delete [] Password;
}
//----------------defining Admin class----------------------------
class Admin:public user{ //Making User class as base class
//Private data members of Admin class
char * Password;
//public interface of Admin class
public:
//Overloaded constructor
Admin(char * ID,char * Name,char * Address,char * Status,char * Password);
//Setter and getter fucntions
void passw();
const char * get_password() const;
void verify_user();
void add_admin();
void delete_admin();
// Admin class Destructor
~Admin();
// end of Admin class
};
// Implementation of overloaded constructor
Admin::Admin(char * id,char * an,char * add,char * stat,char * pass):user(id, an, add, stat){
Password = new char[strlen(pass)+1];
strcpy(Password,pass);
}
// Implementation of passw() method for
void Admin::passw(){
char pass[40];
cout<<"\nEnter password:"<<"\n";
cin.getline(pass,40);
Password = new char[strlen(pass)+1];
strcpy(Password,pass);
}
// Implementation of get_password() method
const char * Admin::get_password() const{
if(Password != NULL){
return Password;
}
}
// Overriding the verify_user() method in Admin class
void Admin::verify_user() {
cout<<"\n\n -------------Administrator User Verification---------\n\n";
//----------assigning password to user---------
passw();
//------set status as Admini user----------
char stat[20]="Administrator";
Status = new char[strlen(stat)+1];
strcpy(Status,stat);
cout<<"\n\nUser is "<<Status<<"\n\n";
}
// ------------Add Admin-------------------
void Admin::add_admin(){
cout<<"admin has been added";
}
// ------------Delete Admin-------------------
void Admin::delete_admin(){
cout<<"admin has been deleted";
}
//-----------Destructor Implementation---------------
Admin::~Admin(){
delete []Password;
}
int main(){
//user object
user user1("","","",""); // user class overloaded constructor is called
// callilng verify-user() method by user object
user1.verify_user();
// Member object
Member memb("","","","","");// Member class overloaded constructor is called
// callilng verify-user() method by Member object
memb.verify_user();
//Admin object
Admin adm("","","","","");// Member class overloaded constructor is called
// callilng verify-user() method by Admin object
adm.verify_user();
system("pause");
}
/*
In the given scenario, it is not possible to achieve polymorphism in the 2nd level, because "cards" is an abstract class.
To achieved the desired results, we must make the "cards" class as a concrete class.
*/
#include<iostream.h>
#include<conio.h>
class cards{
// Protected data members
protected:
int id;
char * name;
public:
// Making displayCards() as a pure virtual function, as a result the cards class becomes an abstract class
virtual void displayCards()=0;
};
class MarriageCards:public cards { // Inheritance relationship b/w MarriageCards and cards
// public interface of MarriageCards class
public:
MarriageCards(){ // User defined default class
id=0;
name=NULL;
}
MarriageCards::MarriageCards(int _id, char * _name){// Overload constructor
id=_id;
name=new char[strlen(_name)+1];
strcpy(name,_name);
}
// Overriding the displayCards() method
virtual void displayCards(){
cout<<"You are now going to see the Marriage Cards"<<endl;
}
// Setters fucntions
void setId(int _id){
id=_id;
}
void setName(char * _name){
name=new char[strlen(_name)+1];
strcpy(name,_name);
}
// Getters fucntions
int getid(){
return id;
}
char * getName(){
return name;
}
~MarriageCards(){// destructor of MarriageCards
delete []name;
}
};
class BirthCards: public cards{ // Derived BithCards from cards
public:
BirthCards::BirthCards(){ // user defined default constructor
id=0;
name=NULL;
}
// overriding displayCards() method
virtual void displayCards(){
cout<<"You are now going to see the Birth Cards"<<endl;
}
// Setters fucntions
void setId(int _id){
id=_id;
}
void setName(char * _name){
name=new char[strlen(_name)+1];
strcpy(name,_name);
}
// Getters fucntions
int getid(){
return id;
}
char * getName(){
return name;
}
// Destructor of BirthCards() class
~BirthCards(){
delete []name;
}
};
// FriendshipCards inherit from Cards class
class FriendshipCards: public cards{
public:
// Overriding the displayCards() method
virtual void displayCards(){
cout<<"you are now going to see the Friendship Cards"<<endl;
}
// Setters fucntions
void setId(int _id){
id=_id;
}
void setName(char * _name){
name=new char[strlen(_name)+1];
strcpy(name,_name);
}
// Getters fucntions
int getid(){
return id;
}
char * getName(){
return name;
}
// Destructor
~FriendshipCards(){
delete []name;
}
};
// Inheriting Mehindicards from MarriageCards
class MehindiCards: public MarriageCards{
public:
MehindiCards(){ // default user defined constructor
id=0;
name=NULL;
}
MehindiCards(int _id, char * _name){ // overloaded constructor
id=_id;
name=new char[strlen(_name)+1];
strcpy(name,_name);
cout<<"ID:"<<id<<endl<<"Name of Card:"<<name<<endl;
}
//Overriding displayCards() method
virtual void displayCards(){
cout<<"You are now going to see the Mehindi Cards"<<endl;
}
//Setters fucntions
void setId(int _id){
id=_id;
}
void setName(char * _name){
name=new char[strlen(_name)+1];
strcpy(name,_name);
}
// Getters fucntions
int getid(){
return id;
}
char * getName(){
return name;
}
// Destructor
~MehindiCards(){
delete []name;
}
};
// Inheriting BaraatCards from MarriageCards
class BaraatCards: public MarriageCards{
public:
BaraatCards(){// user defined default constructor
id=0;
name=NULL;
}
BaraatCards(int _id, char * _name){// overloaded constructor
id=_id;
name=new char[strlen(_name)+1];
strcpy(name,_name);
cout<<"ID:"<<id<<endl<<"Name of Card:"<<name<<endl;
}
//overriding displayCards() method
virtual void displayCards(){
cout<<"You are now going to see the Baraat Cards"<<endl;
}
//Setters fucntions
void setId(int _id){
id=_id;
}
void setName(char * _name){
name=new char[strlen(_name)+1];
strcpy(name,_name);
}
// Getters fucntions
int getid(){
return id;
}
char * getName(){
return name;
}
// Destructor
~BaraatCards(){
delete []name;
}
};
// Inheriting WalimaCards from MarriageCards
class WalimaCards: public MarriageCards{
public:
WalimaCards(){ // user defined default constructor
id=0;
name=NULL;
}
WalimaCards(int _id, char * _name){ // overloaded constructor
id=_id;
name=new char[strlen(_name)+1];
strcpy(name,_name);
cout<<"ID:"<<id<<endl<<"Name of Card:"<<name<<endl;
}
// ovrriding displayCards() method
virtual void displayCards(){
cout<<"You are now going to see the Walima Cards"<<endl;
}
// Setters fucntions
void setId(int _id){
id=_id;
}
void setName(char * _name){
name=new char[strlen(_name)+1];
strcpy(name,_name);
}
// Getters fucntions
int getid(){
return id;
}
char * getName(){
return name;
}
// Destructor
~WalimaCards(){
delete []name;
}
};
int main(){
BirthCards birthcards; // object of BirthCards class
MarriageCards marcards; // object of MarriageCards class
FriendshipCards frcards;// object of FriendshipCards class
birthcards.displayCards();// calling BirthCards displayCards() method
marcards.displayCards();// calling MarriageCards displayCards() method
frcards.displayCards();// calling FriendshipCards displayCards() method
cout<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<" Now calling by Ploymorphicaly"<<endl;
cout<<endl<<endl<<endl<<endl<<endl<<endl;
MarriageCards* mcards=new MehindiCards(1,"ABC");// Creating reference of MarriageCards class
// and calling the overloaded constructor of MehindiCards class
mcards->displayCards();// call the mehindiCards displayCards() methodthrogh the reference of MarriageCards
MarriageCards* bcards= new BaraatCards(2,"XYZ");// Creating reference of MarriageCards class
// and calling the overloaded constructor of BaraatCards class
bcards->displayCards();// call the BaraatCards displayCards() methodthrogh the reference of MarriageCards
MarriageCards* wcards= new WalimaCards(3,"PQR");// Creating reference of MarriageCards class
// and calling the overloaded constructor of WalimaCards class
wcards->displayCards();// call the WalimaCards displayCards() methodthrogh the reference of MarriageCards
system("pause");
}
yeh len two files dekh len correct hain ya nahe --
Join us at facebook: https://www.facebook.com/VU.Study.Corner
Group Link: http://groups.google.com/group/VU-Study-Corner?hl=en
Group Rules: http://groups.google.com/group/VU-Study-Corner/web/group-rules
Unsubscribe: VU-Study-Corner+unsubscribe@googlegroups.com
Adult contents, Spamming, Immoral & Rudish talk, Cell number, Websites & Groups links specially in paper days are strictly prohibited and banned in group.
No comments:
Post a Comment