### java to c++ conversion

Someone please help me with this code its in java and I only know c++ please convert this for me or suggest me a good java to c++ converter. Thanks in advance
// Exercise 9.10 Solution // Test.java // Driver for point, circle, cylinder program import javax.swing.*;

public class Test { public static void main( String args[] ) { Cylinder cylinder = new Cylinder( 10, 3.3, 10, 10 ); String result = "";

result += cylinder.getCPointName() + ": " + cylinder.getCPointString();

result += "\n" + cylinder.getCircleName() + ": " + cylinder.getCircleString();

result += "\n" + cylinder.getName() + ": " + cylinder.toString();

result += "\n" + cylinder.getCPointName() + ": " + cylinder.getCPointString();

result += "\n" + cylinder.getCircleName() + ": " + cylinder.getCircleString(); result += "\n" + "Area = " + cylinder.getCircleArea();

result += "\n" + cylinder.getName() + ": " + cylinder.toString(); result += "\n" + "Area = " + cylinder.area(); result += "\n" + "Volume = " + cylinder.volume();

JOptionPane.showMessageDialog( null, result, "Shapes", JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 ); } }

// Exercise 9.10 Solution // Point.java // Definition of class Point

public class Point { private double x, y; // coordinates of the Point

public Point( double a, double b ) { setPoint( a, b ); }

public void setPoint( double a, double b ) { x = a; y = b; }

public double getX() { return x; }

public double getY() { return y; }

public String toString() { return "[" + x + ", " + y + "]"; }

public String getName() { return "Point"; } }

// Exercise 9.10 Solution // Cylinder.java // Definition of class Cylinder

public class Cylinder { private double height; // height of Cylinder private Circle c; // composition

public Cylinder( double h, double r, double a, double b ) { c = new Circle( r, a, b ); setHeight( h ); }

public void setHeight( double h ) { height = ( h >= 0 ? h : 0 ); }

public double getHeight() { return height; }

public double area() { return 2 * c.area() + 2 * Math.PI * c.getRadius() * height; }

public double volume() { return c.area() * height; }

public String toString() { return c + "; Height = " + height; }

public String getName() { return "Cylinder"; }

public double getCircleArea() { return c.area(); }

public String getCircleName() { return c.getName(); }

public String getCircleString() { return c.toString(); }

public String getCPointString() { return c.getPointString(); }

public String getCPointName() { return c.getPointName(); } }

// Exercise 9.10 Solution // Circle.java // Definition of class Circle

public class Circle { private double radius; private Point p; // composition

public Circle() { this( 0.0, 0.0, 0.0 ); }

public Circle( double r, double a, double b ) { p = new Point( a, b ); // instantiate point object setRadius( r ); }

public void setRadius( double r ) { radius = ( r >= 0 ? r : 0 ); }

public double area() { return Math.PI * Math.pow( radius, 2 ); }

public String toString() { return "Center = " + p + "; Radius = " + radius; }

public String getName() { return "Circle"; }}

public String getPointName() { return p.getName(); }

public String getPointString() { return p.toString(); } }
This is trivial even if you've never dealed with Java.
You hardly need to change anything, so exactly what isn't clear to you? Did you even try?
Last edited on
Topic archived. No new replies allowed.