6. define a C++ class having the following members: (1) 2 instance methods the prototype of the first method is double funA(int r). The parameter r represents the radius of a circle. The funA will calculate the area of a circle and the value of its radius is from the parameter r. It will return the area of the circle. the prototype of the second method is double funB(int w, int h). The parameters w and h represent the width and height of a rectangle. The funB will calculate the area of the rectangle and return the area of the rectangle. (2) 1 static method the prototype of the static method is static int funC(int a1, int a2). The funC will calculate the sum of the parameters a1 and a2, and return the sum. (3) 1 static variable representing PI - the main method - in this method, it calls a default constructor to create an instance of this class. Then, call each instance method above. Finally, call the static method in the main method.
Program Plan: As per the question, i created Demo class which contains all the instance methods funA and funB also a static method funC. the static methods are independent from class object,they can execute before the class object created. the static method or variable can be accessed by using Scope resolution operator(::). in the class there is a static variable PI, which value is 3.1419.
Program:
#include<iostream.h>
#include<conio.h>
//Demo calss definition
class Demo
{ //private section where static variable declared
private:
static double PI;
//public section where member functions defined
public:
//constructor
Demo()
{
}
//funA returns area of the Circle
double funA(int r)
{
return(PI*r*r);
}
//funB returns the area of the rectangle
double funB(int w,int h)
{
return(w*h);
}
//return the sun of the parameters
static int funC(int a1,int a2)
{
return(a1+a2);
}
};
//End of Demo class
//Assigning the value to static variable
double Demo::PI = 3.1419;
//main method definition
void main()
{
Demo d;
int r,i,j,w,h;
clrscr();
cout<<"Enter radius of the circle:";
cin>>r;
cout<<"\nArea of the circle:"<<d.funA(r);
cout<<"\nenter height and Width: ";A
cin>>h>>w;
cout<<"\nArea of the Rectangle:" <<d.funB(w,h);
cout<<"\nEnter values for i and j:";
cin>>i>>j;
//static method calling.static method need not be called with class
object.
//so class name can be used to call the function
cout<<"\nstatic method call:"<<Demo::funC(i,j);
getch();
}
Sample Output:

6. define a C++ class having the following members: (1) 2 instance methods the prototype...
Java code for the following inheritance hierarchy figure..
1. Create class Point, with two private
instance variables x and y that represented for the coordinates for
a point.
Provide constructor for initialising two instance variables.
Provide set and get methods
for each instance variable,
Provide toString method to return formatted
string for a point coordinates.
2. Create class Circle, its inheritance from
Point.
Provide a integer private
radius instance variable.
Provide constructor to
initialise the center coordinates and radius for...
1- Create the base class Book that has the following instance variables, constructor, and methods title ( String) isbn ( String) authors (String) publisher (String) edition ( int) published_year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method // that return sting representation of Book object. 2- Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title ( String) isbn...
C# programming
50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...
Define an interface named Shape with a single method named area that calculates the area of the geometric shape: public double area(); Next, define a class named Circle that implements Shape. The Circle class should have an instance variable for the radius, a constructor that sets the radius, an accessor and a mutator method for the radius, and an implementation of the area method. Define another class named Rectangle that implements Shape. The Rectangle class should have instance variables...
Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function. Define a class called Circle. It should be a derived class of the BasicShape class. This...
Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default constructor -- that calls the default super class constructor and sets the default height to 0- Overloaded constructor with three parameters (length, width and height) – that calls the two parameterized super class constructor passing in length and width passed and sets the height to passed height.- setDimension method with three parameters (length, width, height) – call the super class setDimension and pass in...
Create a class Circle with one instance variable of type double called radius. Then define an appropriate constructor that takes an initial value for the radius, get and set methods for the radius, and methods getArea and getPerimeter. Create a class RightTriangle with three instance variables of type double called base, height, and hypotenuse. Then define an appropriate constructor that takes initial values for the base and height and calculates the hypotenuse, a single set method which takes new values...
My assignment is to create a rectangle class in java. •Create a MyRectangleClass •There are two private instance variables, length l and width w with double data type. •There is a constructor with two parameter •There are 4 public methods which are circumference, area, getWidth, and getLength. •circumference method will return circumference to the caller.(the formula for circumference is 2 *l + 2*w ) •Area method Return the area to the caller(:l*w) •getLength method will return length to the caller....
In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...
A general shape class is shown below. Shape has a dimension. It also defines constructors, getters, setters and a toString method. class Shape{ int dimension; public Shape(){} public Shape(int newDimension){ dimension = newDimension; } public int getDimension(){ return dimension; } public void setDimension(int newDimension){ dimension = newDimension; } public String toString(){ return "Shape has dimension "+dimension; } } a. Define classes Circle and Square, which inherit from Shape class. b. Both classes must have two constructors similar to Shape class....