//c++
#include<iostream>
#include <cmath>
using namespace std;
class ThreeDimensions
{
private:
int x,y,z;
public:
ThreeDimensions()
{
x=0;
y=3;
z=4;
}
ThreeDimensions(int x1,int y1,int z1)
{
x=x1;
y=y1;
z=z1;
}
ThreeDimensions(const ThreeDimensions &t)
{
x=t.x;
y=t.y;
z=t.z;
}
double length()
{
return sqrt(x*x+y*y+z*z);
}
};
int main()
{
ThreeDimensions t1;
ThreeDimensions t2(4,6,7);
ThreeDimensions t3=t2;
cout<<t1.length()<<endl;
cout<<t2.length()<<endl;
cout<<t3.length();
}
//java
import java.lang.Math;
class ThreeDimensions
{
private int x,y,z;
//8. default constructor that initializes the default
values
public ThreeDimensions()
{
this.x=0;
this.y=3;
this.z=4;
}
//10. parameterized constructor that initializes the private
data values to values of parameters
public ThreeDimensions(int x,int y,int z)
{
this.x=x;
this.y=y;
this.z=z;
}
//9. copy constructor that copies the object passed in
paramenter to local object
public ThreeDimensions(ThreeDimensions t)
{
this.x=t.x;
this.y=t.y;
this.z=t.z;
}
/// method that calculates the cquare root of
x2+y2+z2
public double length()
{
return Math.sqrt(x*x+y*y+z*z);
}
public static void main(String[] args)
{
ThreeDimensions t1 = new
ThreeDimensions();
ThreeDimensions t2 = new
ThreeDimensions(4,6,7);
ThreeDimensions t3 = new
ThreeDimensions(t2);
System.out.println(t1.length());
System.out.println(t2.length());
System.out.println(t3.length());
}
}
Memory(MB) 53.668 Time(sec) : 0.1 Output: Copy 5.0 10.04987562112089 10.04987562112089
public: /this makes the functions that are coded later public 8. Write a default constructor for...
1. Write a virtual member function named length , which specifies that the function is constant (that is does not modify the member data) and returns the square root of x squared plus y squared. 2.write the operator << function to have a member of the ostream class as its left hand operand and a member of the Two Dimensions class as its right hand operand. This function shall take the left hand operand by reference, This function shall return...
use C++ Based on the class declaration below, write out the declaration of its default constructor. class BankAccount { public: BankAccount(); // Sets balance to o BankAccount(double initial_balance); // Sets balance to initial_balance // Member functions omitted private: double balance;
Please write in dr java Here is the driver: import java.util.*; public class SquareDriver { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String input =""; System.out.println("Welcome to the easy square program"); while(true) { System.out.println("Enter the length of the side of a square or enter QUIT to quit"); try { input = keyboard.nextLine(); if(input.equalsIgnoreCase("quit")) break; int length = Integer.parseInt(input); Square s = new Square(); s.setLength(length); s.draw(); System.out.println("The area is "+s.getArea()); System.out.println("The perimeter is "+s.getPerimeter()); } catch(DimensionException e)...
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...
Language: C++ Create an abstract base class person. The person class must be an abstract base class where the following functions are abstracted (to be implemented in Salesman and Warehouse): • set Position • get Position • get TotalSalary .printDetails The person class shall store the following data as either private or protected (i.e., not public; need to be accessible to the derived classes): . a person's name: std::string . a person's age: int . a person's height: float The...
a. Write a constructor which initializes the canvas_frame, canvas, and title. The constructor receives a string parameter to initialize the title, a Rectangle object to pass to the Rectangle constructor when creating the canvas_frame object, and a Rectangle object to pass to the Rectangle constructor when creating the canvas object. b. Write a print method that prints the title and prints the perimeter of canvas_frame and the area of canvas - call the methods area and perimeter to get both...
1. Define a class Rectangle with two attributes: (This is for C++) -length, an integer (default value 1) -width, an integer (default value 1) Provide the following member functions: -default constructor -constructor that takes parameters used to initialize the data -get/set function for each attribute -a function perimeter that returns the perimeter of the rectangle -a function area that returns the area of the rectangle b. Write a program that uses the class Rectangle to create two rectangle objects with...
please use c++ Write a program that contains a class Rectangle with two private double precision members iLength and iWidth, public set and get member functions for these two members, a two argument constructor that sets the length and width to any two user specified values and a void function area() that computes the area and then prints this value by inserting it into the cout output stream. Write a main function that ereates a Rectangle with a length of...
public class Date { private int month; private int day; private int year; /** default constructor * sets month to 1, day to 1 and year to 2000 */ public Date( ) { setDate( 1, 1, 2000 ); } /** overloaded constructor * @param mm initial value for month * @param dd initial value for day * @param yyyy initial value for year * * passes parameters to setDate method */ public Date( int mm, int dd, int yyyy )...
Java code please. Please help * 95: Write a public class named TollInts with the following. * -A public constructor that takes 2 doubles as inputs. * -A public method named compute that takes no parameters and returns the the tangent of the * first constructor input subtracted by the the square root of the second constructor input * as a double. You will need to store the constructor input in instance variables to be able * to access them...