USE C++
Demonstrate how to write an interface for a VEHICLE class using C++. In your interface, demonstrate the following (use comments to explain or for demonstration):
-Interface implementation
-Multiple interface implementation for a single class
-Example of a Diamond Inheritance problem
-Polymorphism
Explain each term above clearly in the code example and discuss how it is being used
USE C++
/* Overall problem divided into to 3 section
First program is example of
1) Interface implementation
2) Polymorphism
1st program
*/
#include <iostream>
using namespace std;
// Base class
class Vehicle {
public:
// pure virtual function changeGear
providing interface framework.
virtual void changeGear(int g) =
0;
};
// Derived Bicycle classes that implement all pure virtual method
of class vehicle
class Bicycle: public Vehicle {
int gear;
public:
//override changeGear function
void changeGear(int g) {
gear=g;
cout<<"\n
Bicycle Now the Gear is: "<<gear;
}
};
// Derived Car classes that implement all pure virtual method of
class vehicle
class Car: public Vehicle {
int gear;
public:
//override changeGear function
void changeGear(int g) {
gear=g;
cout<<"\n
Car Now the Gear is: "<<gear;
}
};
int main(void) {
Bicycle Rect;//creat object
Rect.changeGear(1) ;//call override method
Car car;
car.changeGear(3) ;
return 0;
}
/*
output
Bicycle Now the Gear is: 1
Car Now the Gear is: 3
*/
/*
2nd Problem
Example of a Diamond Inheritance problem
The diamond problem occurs when two superclasses of a class have a common base class. For example, in the following diagram, the TA class gets two copies of all attributes of Person class, this causes ambiguities.
*/
#include <iostream>
using namespace std;
// Base class
class Vehicle {
public:
Vehicle(int n){
// only
because of diamond proble below function called twice
cout<<"\n Model No:"<<n;
}
};
// Derived Bicycle classes
class Bicycle: public Vehicle {
int gear;
public:
Bicycle(int n):Vehicle(n){
}
};
// Derived Car classes
class Car: public Vehicle {
int gear;
public:
Car(int n):Vehicle(n){
}
};
class Brand:public Car,public Bicycle{
public:
Brand(int n):Car(n),Bicycle(n){
}
};
int main(void) {
Brand brand(100);
return 0;
}
/*
output
Model No:100
Model No:100
*/
/*
problem 3
Multiple Inheritance in C++
Multiple Inheritance is a feature of C++ where a class can inherit from more than one classes.
here is program with vehicle. It generate conflict problem hence it is solved by specifying base class name before function call
*/
#include <iostream>
using namespace std;
class vehicle
{
public:
void someFunction( )
{ cout<<"\n Vehicle Function ";
}
};
class cycle
{
public:
void someFunction( )
{ cout<<"\n cycle Function ";}
};
class derived : public vehicle, public cycle
{
};
int main()
{
derived obj;
obj.vehicle::someFunction( ); //called function
from vehicle class
obj.cycle::someFunction(); // called
function from cycle class
}
/*
output
Vehicle Function
cycle Function
*/
USE C++ Demonstrate how to write an interface for a VEHICLE class using C++. In your...
I could really use the help. Problem Develop a script to demonstrate an understanding of the overload (overwrite) methods of using Python operators. This lesson will focus on the “+” operator and the “__add__” method. The program must have the following: Demonstration of an understanding of how to use the + operator for basic addition of two integer numbers Demonstration of an understanding of how to use the + operator for a concatenation of lists Demonstration of an understanding of...
What is Multiple Inheritance and explain it using a Class Diagram and Write a Code for it in C#. Use Set() and Get() as well.
Write ONE application program by using the following requirements: Using JAVA File input and output Exception handling Inheritance At least one superclass or abstract superclass: this class needs to have data members, accessor, mutator, and toString methods At least one subclass: this class also needs to have data members, accessor, mutator, and toString methods At least one interface: this interface needs to have at least two abstract methods At least one method overloading At least one method overriding At least...
Write a C++ program that does the following : Define a class myInt that has as its single attribute an integer variable and that contains member functions for determining the following information for an object of type myInt: A. Is it multiple of 7 , 11 , or 13. B. Is the sum of its digits odd or even. C. What is the square root value. D.Is it a prime number. E. Is it a perfect number ( The sum...
Q 4(b) 6 Marks] Write the code for a single Java class of your own choice that demonstrates the use of the following features in the Java language: Method overloadingg The use of super and this Identify clearly where in your code each of these points is being demonstrated Q 4(c) [6 Marks] Write an abstract Student class in Java which has a name, id_number, year and programme_code as member variables. Add a constructor to your class and a display()...
Need help extending and constructing this problem in JAVA using the given guidelines. public class gatorade { public void nutrition() { System.out.println("nutrition facts method"); System.out.println("90 Calories"); System.out.println("0 Grams Fat"); System.out.println("20 MG Sodium"); System.out.println("18 Grams Sugar"); System.out.println("0 Grams Protein"); } } //inheritance public class blueberry extends gatorade{ System.out.println("Color is blue"); public class orange extends gatorade{ System.out.println("Color is orange"); public class lemonlime extends gatorade{ System.out.println("Color is yellow"); public class fruitpunch extends gatorade{ System.out.println("Color is red"); ________________________________________________________ Write one application program by using...
C++ ONLY PLEASE Problem Description: Objective: Create Inheritance Hierarchy to Demonstrate Polymorphic Behavior Create a Rectangle Class Derive a Square Class from the Rectangle Class Derive a Right Triangle Class from the Rectangle Class Create a Circle Class Create a Sphere Class Create a Prism Class Define any other classes necessary to implement a solution Define a Program Driver Class for Demonstration a) Create a Container to hold objects of the types described above b) Create and Add two(2) objects...
Discuss why it is necessary to use repetitive statement, and use segment codes to demonstrate your understanding of repetitive statement. Explain why you are choosing one of the following three statements in your code. a) for/foreach statement b) while/until statement c) do while/do until statement. Provide examples. You are welcome to do your own research or/and give feedback on others' comments.
Can someone please help with this in JAVA? Write one application program by using the following requirements: 1) Exception handling 2) Inheritance a) At least one superclass or abstract superclass: this class needs to have data members, accessor, mutator, and toString methods b) At least one subclass: this class also needs to have data members, accessor, mutator, and toString methods c) At least one interface: this interface needs to have at least two abstract methods d) At least one method...
Programming Message Encoder - Write in Java and include comments Create an interface MessageEncoder that has a single abstract method encode(plainText), where plainText is the message to be encoded. The method will return the encoded message. Create a class SubstitutionCipher that implements the interface MessageEncoder, as described above. The constructor should have one parameter called shift. Define the method encode so that each letter is shifted by the value in shift. Defne the method encode so that each letter is...