A Circle class has a data member called radius and the following functions: You
ID: 3859189 • Letter: A
Question
A Circle class has a data member called radius and the following functions:
You should write that same Circle class, but in separate interface (Circle.hpp) and implementation (Circle.cpp) file. Your .hpp file should contain the data members and prototypes, while your .cpp file should contain the function definitions. Your .cpp file will need to #include "Circle.hpp" (note that quotation marks are used for local files instead of the angle brackets you're used to). Also, when defining the functions in the .cpp class, you will need to add "Circle::" in front of the function name in the header for each function.
The #infndef, #define, and #endif directives in the Rectangle example are "include guards". They prevent a header file from being included more than once. For your .hpp file it will look the same as in the Rectangle example, except that you will change "RECTANGLE_H" to "CIRCLE_HPP".
Your main function will also go in a separate file, and it will also need to #include "Circle.hpp". You will compile your Circle class with your main function something like this: "g++ Circle.cpp circleMain.cpp -o circle". Note that you don't need to list the .hpp file in the compile command. You can use the following main function to test your Circle class:
int main Circle circl; Circle circ2(3.5); coutExplanation / Answer
interface AreaCal
{
void circle();
}
class AreaOfCircle implements AreaCal
{
double area;
public void circle(double r)
{
area= (22*r*r)/7;
}
public static void main(String args[])
{
AreaOfCircle x;
Scanner s= new Scanner(System.in);
System.out.println("Enter the radius:");
double rad= s.nextDouble();
x=new AreaOfCircle();
x.circle(rad);
System.out.println("Area of Circle is: " + x.area);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.