Question

C++ Exercice

Topic Cover: Class and main implementation (50pts) 1, created the class circle.h file (10 pts) 2. Create the Circle. cpp (25pts) 3. Create the main function and use the class circle in your program (15Pst) (circle Class) Create a class called circle in other to performing the calculation of the area ,sectional area and circumference of any circle. Write a program to test your class. Circle Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it declared. The constructor should contain default values in case no initializers are provided. Provide public member functions that perform the following tasks: a. Create setters member functions to obtain and validated the radius of the circle between two values 0 to 25.5 cm, and also validated the angel oof the section between (0 to 360 or 0 to 6.28). Use the construct default value for 0 and o 360 21 or 6.28, if no angel is specify by the user. The construct must be like this circle rang), and the setters member functions must be like this set circle. radio(r)and set circle angle(ang). b: Create a member function to obtain the section area of the circle if a anle is enter by the user. set circle area section c. Create a member function that gets the area of the get circle. area() d. Create a member function that gets the circumference of the get circle.cricun() e. Create a member function to obtain the section area of the circle if a anle is enter by the user. get circle area section() To test your program use the following user input data r 2, o TT/4 or o 0.78539

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code for Circle.h:

class Circle
{
    double radius;
    double sectionAngle;
    public:
        Circle(double r = 0, double sA = 6.28);
        void set_circle_radius(double r);
        void set_circle_angle(double ang);
        double get_circle_area();
        double get_circle_area_section();
};

Code for Circle.cpp is:

#include "Circle.h"
Circle::Circle(double r, double sA)
    {
        radius = r;
        sectionAngle = sA;
    }
void Circle::set_circle_radius(double r)
    {
        radius = r;
   }
void Circle::set_circle_angle(double ang)
    {
        sectionAngle = ang;
    }
double Circle::get_circle_area()
    {
        return 3.14 * radius * radius;
    }
double Circle::get_circle_area_section()
    {
        return get_circle_area() * sectionAngle / 360;
    }

And the Demo.cpp code is:

#include <iostream>
#include "Circle.cpp"
using namespace std;
int main()
{
    Circle c (2, 0.78539);
    cout << "The area of the circle is: " << c.get_circle_area() << endl;
    cout << "The sectional area is: " << c.get_circle_area_section() << endl;
}

Finally the output screenshot is:

Terminal Shell Edit View Window Help < >し 令见 4)) 98% Eか Wed 10 May 08:31 ANANDA KUMAR THUMMAPUDI a。E Currently Open Docum...

Add a comment
Know the answer?
Add Answer to:
C++ Exercice Topic Cover: Class and main implementation 1. Created the class circle.h file 2. Create...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Note- can you rewrite the code in C++ if there is any existing code. Can you...

    Note- can you rewrite the code in C++ if there is any existing code. Can you not use arrow -> operator. Write a circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument . • setRadius. A mutator function...

  • Design and implement class Circle to represent a circle object. The class defines the following attributes...

    Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1.      A private variable of type double named radius to represent the radius. Set to 1. 2.      Constructor Methods: •        Python : An overloaded constructor method to create a default circle. •        C# & Java: Default Constructor with no arguments. •        C# & Java: Constructor method that creates a circle with user-specified radius. 3.      Method getRadius() that returns the radius. 4.     ...

  • 1. Define a class Rectangle with two attributes: (This is for C++) -length, an integer (default...

    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...

  • Part (A) Note: This class must be created in a separate cpp file Create a class...

    Part (A) Note: This class must be created in a separate cpp file Create a class Employee with the following attributes and operations: Attributes (Data members): i. An array to store the employee name. The length of this array is 256 bytes. ii. An array to store the company name. The length of this array is 256 bytes. iii. An array to store the department name. The length of this array is 256 bytes. iv. An unsigned integer to store...

  • Using separate files, write the definition for a class called Point and a class called Circle. Th...

    Using separate files, write the definition for a class called Point and a class called Circle. The class point has the data members x (double) and y (double) for the x and y coordinates. The class has the following member functions: a) void set_x(double) to set the x data member b) void set_y(double) to set the y data member c) double get_x() to return the the x data member d) double get_y() to return the the y data member e)...

  • Create a program that calculates the area of various shapes. Console Specifications Create an abstract class...

    Create a program that calculates the area of various shapes. Console Specifications Create an abstract class named Shape. This class should contain virtual member function named get_area() that returns a double type. Create a class named Circle that inherits the Shape class and contains these constructors and member functions: Circle(double radius) double get_radius() void set_radius(double radius) double get_area() Create a class named Square that inherits the Shape class and contains these constructors and member functions: Square(double width) double get_width() void...

  • 1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - a int variable named itemNumber - an int variable named quantity - a double variable named cost - a double variable named totalCost. Total cost is defined as quantity X cost. - updateTotalCost() which takes no arguments and sets the values of the variable totalCost. 1c. Add the following public functions: - Accessor and Mutators for...

  • Please use C++. Write a class named Circle that has a double data member named radius...

    Please use C++. Write a class named Circle that has a double data member named radius and a static double data member named maxRadius. It should have a default constructor that initializes the radius to 1.0. It should have a constructor that takes a double and uses it to initialize the radius. It should have a method called calcArea that returns the area of the Circle (use 3.14159 for pi). It should have a static set method for the maxRadius....

  • SOLVE IN PYTHON: Exercise #1: Design and implement class Circle to represent a circle object. The...

    SOLVE IN PYTHON: Exercise #1: Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: A private variable of type double named radius to represent the radius. Set to 1. Constructor Methods: Python : An overloaded constructor method to create a default circle. C# & Java: Default Constructor with no arguments. C# & Java: Constructor method that creates a circle with user-specified radius. Method getRadius() that returns the radius. Method setRadius()...

  • Implement the following class in interface and implementation files. A separate file (the main project file)...

    Implement the following class in interface and implementation files. A separate file (the main project file) shall have the main function that exercises this class. Create a class named Student that has three member variables: name - string that stores the name of the student numClasses - integer that tracks how many courses the student is currently enrolled in, this number must be between 1 and 100 ClassList - an array of strings of size 100 used to store the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT