AIM : TO create a program to show overriding Base class members in a Derived class. PROCEDURE : If we inherit a class into the derived class and provide a definition for one of the base class's function again inside the derived class, then that function is said to be overridden, and this mechanism is called Function Overriding. PROGRAM : #include using namespace std;
class Base { public: Base() : b(0) {} int get(); virtual void sayhello() { cout << "Hello from Base with b: " << b << endl; } private: int b; };
int Base::get() { sayhello(); return b; }
class Derived : public Base { public: Derived(double b_):b(b_){} void sayhello() { cout << "Hello from Derived with b: " << b << endl; } private: double b; };
int main() { Derived d(10.0); Base b = d;
cout << "Derived b: " << d.get() << endl; cout << "Base b: " << b.get() << endl; } Error : 0 Output : Hello from Derived with b: 10 Derived b: 0 Hello from Base with b: 0 Base b: 0 Result : I have successfully done my program.
AIM: To create a program using overriding base class in a derived PROCEDURE: In this program we inherit base class member function (void introduce) in a derived class .If we inherit base class into derived class then it is called overriding. PROGRAM: #include using namespace std; class person { public: void introduce() { cout<<"I am a person"<<endl; } }; class student:public person { public: void introduce() { cout<<"I am a student and i am awesome"<<endl; } }; int main() { student s; s.introduce(); return 0; } ERROR:0 OUTPUT: I am a student and i am awesome. RESULT: I have done my program successfully.
AIM: To create a program to show complexity and ambiguity in inheritance. PROCEDURE: In this c++ program there are two base class(one base class is teacher and another base class is student) and one derived class(person).Ambiguity arises in c++ when general rules leave the choice of more than one parent without a ambiguity criteria. PROGRAM: #include using namespace std; class teacher { protected: int x; public: void display() { cout<<"Enter the value of x:"; cin>>x; } }; class student { protected: int y; public: void display() { cout<<"Enter the value of y:"; cin>>y; } }; class person:public teacher,public student { public: void add() { cout<<"sum="<<x+y<<endl; } }; int main() { person obj; obj.student::display(); obj.teacher::display(); obj.add(); return 0; } ERROR:0 OUTPUT: Enter the value of x:22 Enter the value of y:12 Sum:34 RESULT:I have done my program successfully.
AIM: To create a program to show complexity and ambiguity in inheritance. PROCEDURE: Step 1 : Start the program. Step 2 : In this program, there are two base class i.e. sample and max. Step 3 : And one derived class i.e. derived. Step 4: when general rules leave the choice of more than one parent without a ambiguity criteria. Step 5 : End the program. PROGRAM: #include using namespace std; class sample { protected: int a; public: void getdata() { cout<<"Enter the value of a:"; cin>>a; } }; class max { protected: int b; public: void getdata() { cout<<"Enter the value of b:"; cin>>b; } }; class derived:public sample , public max { public: void product() { cout<<"product="<<a*b<<endl; } }; int main() { derived d; d.max::getdata(); d.sample::getdata(); d.product(); return 0; } ERROR : 0 OUTPUT : Enter the value of a:10 Enter the value of b:15 Product:150 RESULT:I have successfully done my program.
AIM:- To create a program to show overriding base class member in drived class. Procedure:- the both base class and derived class have a member function with same name and argument. If you create an object of the drive class and called member function which exist in both class(base,derived). PROGRAM:- #include using namespace std; class base { public: void show() { cout<<"it is a base class"<<endl; } }; Class derived :public base { public: void show() { cout<<"it is derived class and inherite the property of base class"<<endl; } }; int main() { derived prince; prince.show(); return 0; } ERROR:0 OUTPUT: it is a derived class and inherit the property of base class RESULT:I have successfully done my program.
AIM:- To create a program to show overriding base class member in drived class.
Procedure:- the both base class and derived class have a member function with same name and argument. If you create an object of the drive class and called member function which exist in both class(base,derived). PROGRAM:- #include using namespace std; class base { public: void show() { cout<<"it is a base class"<<endl; } }; Class derived :public base { public: void show() { cout<<"it is derived class and inherite the property of base class"<<endl; } }; int main() { derived prince; prince.show(); return 0; } ERROR:0 OUTPUT: it is a derived class and inherit the property of base class RESULT:I have successfully done my program.
AIM: Write a program to show complexity and ambugity in inheritance. Procedure: In this program we have used multilevel inheritance with same member function name and to solve the complexity faced by the compiler during run time we use scope resolution operator. PROGRAM: #include using namespace std; class grandpa { private: int height; public: void heightdata() { cout<<"grandpa is tall"<<endl;
public: void heightdata() { cout<<"Daddy is also tall"<<endl;
}
}; class me: public daddy {
public: void heightdata() { cout<<"But i am not so tall"<<endl; } void sports() { cout<<"I love sport"<<endl; } }; int main() { me obj; grandpa obj2; daddy obj3; obj2.petlove();
obj.grandpa::heightdata(); obj.daddy::heightdata(); obj.heightdata(); obj.sports(); } OUTPUT: grandpa is tall grandpa loves pet Daddy is also tall But i am not so tall I love sport ERROR: 0 RESULT: Executed program successfully
AIM : TO create a program to show overriding Base class members in a Derived class. Procedure: In this C++ program if we inherit a class into the derived class and provide a definition for one of the base class's function again inside the derived class, then that function is said to be overridden, and this mechanism is called Function Overriding. Program: #include using namespace std; class base { public: int a,b,c; void input() { cout<<"Enter two numbers"<>a>>b; } void calculation() { c=a+b; cout<<"Sum is: "<<c<<endl; } }; class derived: public base { public: void calculation() { c=a*b; cout<<"Product is: "<<c; } }; int main() { derived d; base b; d.input(); b.calculation(); //calling base class functions d.calculation(); //overriding the function return 0; } Error: 0 Output: Enter two numbers 45 45 Sum is: 4883904 Product is: 2025 Result: This program execute successfully
AIM: To create a program to show complexity and ambiguity in inheritance. Procedure: In this program we have used multilevel inheritance with same member function name and to solve the complexity faced by the compiler during run time we use scope resolution operator. PROGRAM: Program: #include using namespace std; class base1 { public: void display() { cout<<"Myself Zaira Zahid,"<<endl; } }; class base2 { public: void display() { cout<<"pursuing B-tech from NIMS University"<<endl; } }; class derived: public base1, public base2 { public: void show() { cout<<"Showing ambiguity is multiple inheritance"<<endl; } }; int main() { derived d; d.show(); d.base1::display(); d.base2::display(); return 0; } Error: No error found. Output: Showing ambiguity is multiple inheritance Myself Zaira Zahid, pursuing B-tech from NIMS University. Result: This program executed successfully.
INTRODUCTION Hadoop and Apache Spark both are big-data frameworks, but direct comparison of Hadoop and Spark is difficult because they do many of the same things, but are also non-overlapping in some areas. Hadoop is essentially a distributed data infrastructure, It distributes massive data collections across multiple nodes within a cluster of commodity servers, which means you don't need to buy and maintain expensive custom hardware. It also indexes and keeps track of that data, enabling big-data processing and analytics far more effectively than was possible previously. Spark, on the other hand, is a data-processing tool that operates on those distributed data collections; it doesn't do distributed storage Hadoop have many components of modules that work together to create the Hadoop framework. The primary Hadoop framework modules are: · Hadoop Common · ...
Operator overloading is an important concept in C++. It is a type of polymorphism in which an operator is overloaded to give user defined meaning to it. Overloaded operator is used to perform operation on user-defined data type. For example '+' operator can be overloaded to perform addition on various data types, like for Integer, String(concatenation) etc. Almost any operator can be overloaded in C++. However there are few operator which can not be overloaded. Operator that are not overloaded are follows scope operator - :: sizeof member selector - . member pointer selector - * ternary operator - ?: Operator Overloading Syntax Implementing Operator Overloading Operator overloading can be done by implementing a function which can be : Member Function Non-Member Function Friend Function Operator overloading function can be a member function if the Left operand is an Object of that class, but if the Left operand is different, then Operator ove...
Dear students, Here im uploading study materials chapter wise. Follow your material one by one and report me if you have any queries. Chapter 1: Introduction about System Programming Chapter 2: 1 pass and 2 Pass Assembler Assembler Chapter 3: Macro & Linker Chapter 4 Compiler
AIM : TO create a program to show overriding Base class members in a Derived class.
ReplyDeletePROCEDURE :
If we inherit a class into the derived class and provide a definition for one of the base class's function again inside the derived class, then that function is said to be overridden, and this mechanism is called Function Overriding.
PROGRAM :
#include
using namespace std;
class Base
{
public:
Base() : b(0) {}
int get();
virtual void sayhello()
{
cout << "Hello from Base with b: " << b << endl;
}
private:
int b;
};
int Base::get()
{
sayhello();
return b;
}
class Derived : public Base
{
public:
Derived(double b_):b(b_){}
void sayhello()
{
cout << "Hello from Derived with b: " << b << endl;
}
private:
double b;
};
int main()
{
Derived d(10.0);
Base b = d;
cout << "Derived b: " << d.get() << endl;
cout << "Base b: " << b.get() << endl;
}
Error : 0
Output :
Hello from Derived with b: 10
Derived b: 0
Hello from Base with b: 0
Base b: 0
Result :
I have successfully done my program.
AIM: To create a program using overriding base class in a derived
ReplyDeletePROCEDURE: In this program we inherit base class member function (void introduce) in a derived class .If we inherit base class into derived class then it is called overriding.
PROGRAM:
#include
using namespace std;
class person
{
public:
void introduce()
{
cout<<"I am a person"<<endl;
}
};
class student:public person
{
public:
void introduce()
{
cout<<"I am a student and i am awesome"<<endl;
}
};
int main()
{
student s;
s.introduce();
return 0;
}
ERROR:0
OUTPUT: I am a student and i am awesome.
RESULT: I have done my program successfully.
AIM: To create a program to show complexity and ambiguity in inheritance.
ReplyDeletePROCEDURE:
In this c++ program there are two base class(one base class is teacher and another base class is student) and one derived class(person).Ambiguity arises in c++ when general rules leave the choice of more than one parent without a ambiguity criteria.
PROGRAM:
#include
using namespace std;
class teacher
{
protected:
int x;
public:
void display()
{
cout<<"Enter the value of x:";
cin>>x;
}
};
class student
{
protected:
int y;
public:
void display()
{
cout<<"Enter the value of y:";
cin>>y;
}
};
class person:public teacher,public student
{
public:
void add()
{
cout<<"sum="<<x+y<<endl;
}
};
int main()
{
person obj;
obj.student::display();
obj.teacher::display();
obj.add();
return 0;
}
ERROR:0
OUTPUT:
Enter the value of x:22
Enter the value of y:12
Sum:34
RESULT:I have done my program successfully.
AIM: To create a program to show complexity and ambiguity in inheritance.
ReplyDeletePROCEDURE:
Step 1 : Start the program.
Step 2 : In this program, there are two base class i.e. sample and max.
Step 3 : And one derived class i.e. derived.
Step 4: when general rules leave the choice of more than one parent without a ambiguity criteria.
Step 5 : End the program.
PROGRAM:
#include
using namespace std;
class sample
{
protected:
int a;
public:
void getdata()
{
cout<<"Enter the value of a:";
cin>>a;
}
};
class max
{
protected:
int b;
public:
void getdata()
{
cout<<"Enter the value of b:";
cin>>b;
}
};
class derived:public sample , public max
{
public:
void product()
{
cout<<"product="<<a*b<<endl;
}
};
int main()
{
derived d;
d.max::getdata();
d.sample::getdata();
d.product();
return 0;
}
ERROR : 0
OUTPUT :
Enter the value of a:10
Enter the value of b:15
Product:150
RESULT:I have successfully done my program.
This comment has been removed by the author.
ReplyDeleteAIM:- To create a program to show overriding base class member in drived class.
ReplyDeleteProcedure:- the both base class and derived class have a member function with same name and argument.
If you create an object of the drive class and called member function which exist in both class(base,derived).
PROGRAM:-
#include
using namespace std;
class base
{
public:
void show()
{
cout<<"it is a base class"<<endl;
}
};
Class derived :public base
{
public:
void show()
{
cout<<"it is derived class and inherite the property of base class"<<endl;
}
};
int main()
{
derived prince;
prince.show();
return 0;
}
ERROR:0
OUTPUT: it is a derived class and inherit the property of base class
RESULT:I have successfully done my program.
AIM:- To create a program to show overriding base class member in drived class.
ReplyDeleteProcedure:-
the both base class and derived class have a member function with same name and argument.
If you create an object of the drive class and called member function which exist in both class(base,derived).
PROGRAM:-
#include
using namespace std;
class base
{
public:
void show()
{
cout<<"it is a base class"<<endl;
}
};
Class derived :public base
{
public:
void show()
{
cout<<"it is derived class and inherite the property of base class"<<endl;
}
};
int main()
{
derived prince;
prince.show();
return 0;
}
ERROR:0
OUTPUT: it is a derived class and inherit the property of base class
RESULT:I have successfully done my program.
AIM: Write a program to show complexity and ambugity in inheritance.
ReplyDeleteProcedure: In this program we have used multilevel inheritance with same member function name and to solve the complexity faced by the compiler during run time we use scope resolution operator.
PROGRAM:
#include
using namespace std;
class grandpa
{
private:
int height;
public:
void heightdata()
{
cout<<"grandpa is tall"<<endl;
}
public:
void petlove()
{
cout<<"grandpa loves pet"<<endl;
}
};
class daddy:public grandpa
{
public:
void heightdata()
{
cout<<"Daddy is also tall"<<endl;
}
};
class me: public daddy
{
public:
void heightdata()
{
cout<<"But i am not so tall"<<endl;
}
void sports()
{
cout<<"I love sport"<<endl;
}
};
int main()
{
me obj;
grandpa obj2;
daddy obj3;
obj2.petlove();
obj.grandpa::heightdata();
obj.daddy::heightdata();
obj.heightdata();
obj.sports();
}
OUTPUT:
grandpa is tall
grandpa loves pet
Daddy is also tall
But i am not so tall
I love sport
ERROR:
0
RESULT: Executed program successfully
AIM : TO create a program to show overriding Base class members in a Derived class.
ReplyDeleteProcedure: In this C++ program if we inherit a class into the derived class and provide a definition for one of the base class's function again inside the derived class, then that function is said to be overridden, and this mechanism is called Function Overriding.
Program:
#include
using namespace std;
class base
{
public:
int a,b,c;
void input()
{
cout<<"Enter two numbers"<>a>>b;
}
void calculation()
{
c=a+b;
cout<<"Sum is: "<<c<<endl;
}
};
class derived: public base
{
public:
void calculation()
{
c=a*b;
cout<<"Product is: "<<c;
}
};
int main()
{
derived d;
base b;
d.input();
b.calculation(); //calling base class functions
d.calculation(); //overriding the function
return 0;
}
Error: 0
Output: Enter two numbers
45
45
Sum is: 4883904
Product is: 2025
Result: This program execute successfully
AIM: To create a program to show complexity and ambiguity in inheritance.
ReplyDeleteProcedure: In this program we have used multilevel inheritance with same member function name and to solve the complexity faced by the compiler during run time we use scope resolution operator.
PROGRAM:
Program:
#include
using namespace std;
class base1
{
public:
void display()
{
cout<<"Myself Zaira Zahid,"<<endl;
}
};
class base2
{
public:
void display()
{
cout<<"pursuing B-tech from NIMS University"<<endl;
}
};
class derived: public base1, public base2
{
public:
void show()
{
cout<<"Showing ambiguity is multiple inheritance"<<endl;
}
};
int main()
{
derived d;
d.show();
d.base1::display();
d.base2::display();
return 0;
}
Error: No error found.
Output: Showing ambiguity is multiple inheritance
Myself Zaira Zahid,
pursuing B-tech from NIMS University.
Result: This program executed successfully.