Question

In: Computer Science

1: Create a class Circle 2: Create two instances of the Circle class 1: Based on...

1: Create a class Circle

2: Create two instances of the Circle class


1: Based on Program 13-1 (see attachment Pr13-1.cpp) in the textbook, create a class name “Circle” with the following declarations (hint: you can use PI=3.14):


//Circle class declaration
class Circle
{
private:
double radius;
public:
void setRadius(double);
double getRadius() const;
double getArea() const;
double getPerimeter() const;
};
2: Based on Program 13-2 (see attachment Pr13-2.cpp) in the textbook, create two instances of the Circle class, pizza1 and pizza2, which can have different size (radius). Calculate and show the areas of each pizza, also the total area of both pizzas combined. You should put your answers for Q1 and Q2 into one program.

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

//completed program

#include<iostream>

using namespace std;

//Circle class

class Circle

{

private:

double radius;

public:

void setRadius(double);

double getRadius() const;

double getArea() const;

double getPerimeter() const;

};

//implementation of all methods in Circle class

void Circle::setRadius(double rad){

                //setting radius to rad

                radius=rad;

}

double Circle::getRadius() const{

                //returns the radius

                return radius;

}

double Circle::getArea() const{

                //area=PI*r*r

                double area=3.14*radius*radius;

                return area;

}

double Circle::getPerimeter() const{

                //perimeter=2*PI*r

                double peri=2*3.14*radius;

                return peri;

}

int main(){

                //creating two Circle objects

                Circle pizza1;

                Circle pizza2;

                //setting different radii to each circle

                pizza1.setRadius(50);

                pizza2.setRadius(20);

                //displaying area of pizza1, pizza2 and pizza 1 & 2 combined

                cout<<"Area of Pizza 1: "<<pizza1.getArea()<<endl;

                cout<<"Area of Pizza 2: "<<pizza2.getArea()<<endl;

                cout<<"Area of Pizza 1 and 2 combined: "<<(pizza1.getArea()+pizza2.getArea())<<endl;

                return 0;

}

/*OUTPUT*/

Area of Pizza 1: 7850

Area of Pizza 2: 1256

Area of Pizza 1 and 2 combined: 9106


Related Solutions

Language: Java Question:Using your Circle class (or the one provided below), create a Circle array of...
Language: Java Question:Using your Circle class (or the one provided below), create a Circle array of size 4 in a driver class using the following statement: Circle circleArr[] = new Circle[4]; Populate the array with four different radiuses and then, using a for loop from 0 to one less then the length of the array, print the area and the diameter of each of the four circles Circle Class: import java.text.DecimalFormat; public class Circle {    DecimalFormat dec = new...
1. Based on the hormones we have discussed in class, create a list of hormones that...
1. Based on the hormones we have discussed in class, create a list of hormones that play a role in the following areas: increased CHO utilization, increased PRO synthesis, increased lipid breakdown/FFA utilization. 2. Explain the two ways in which plasma volume and osmolality are regulated during exercise. Be sure to define all key terms.
Circle Class Write a Circle class that has the following member variables: • radius: a double...
Circle Class 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 for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the...
Circle Class Write a Circle class that has the following member variables: • radius: a double...
Circle Class 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 for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the...
Using C# Create the “TestQuestion” class. It will have two class variables: 1) a question and...
Using C# Create the “TestQuestion” class. It will have two class variables: 1) a question and 2) the answer to that question. Please create an accessor and mutator method for both of those variables, without which we would not be able to see or change the question or the answer. There should be a constructor method. We will also have a “ToString” or “__str__” method, which will print the question followed by its answer. The constructor method has two parameters...
A class variable is visible to and shared by all instances of a class. How would...
A class variable is visible to and shared by all instances of a class. How would such a variable be used in an application? Describe the difference between abstract classes and concrete classes, giving an example of each. Explain how data are encapsulated and information is hidden in Java? Explain the difference between a class and an interface in Java, using at least one example.
C++ please #include <iostream> using namespace std; /** * defining class circle */ class Circle {...
C++ please #include <iostream> using namespace std; /** * defining class circle */ class Circle { //defining public variables public: double pi; double radius; public: //default constructor to initialise variables Circle(){ pi = 3.14159; radius = 0; } Circle(double r){ pi = 3.14159; radius = r; } // defining getter and setters void setRadius(double r){ radius = r; } double getRadius(){ return radius; } // method to get Area double getArea(){ return pi*radius*radius; } }; //main method int main() {...
(JAVA) 1.) Create a class called Rabbit that with 2 attributes: 1) speed and 2) color....
(JAVA) 1.) Create a class called Rabbit that with 2 attributes: 1) speed and 2) color. Then, create a constructor that has no parameters, setting the default speed to 0 and the color to “white”; this is called a default constructor. Next, create a second constructor that takes in two parameters. The second constructor should assign those parameters to the attributes. Then, in main, create two Rabbit objects. For the first Rabbit object, call the first constructor. For the second...
1. Create a new Java project called L2 and a class named L2 2. Create a...
1. Create a new Java project called L2 and a class named L2 2. Create a second class called ArrayExaminer. 3. In the ArrayExaminer class declare the following instance variables: a. String named textFileName b. Array of 20 integers named numArray (Only do the 1st half of the declaration here: int [] numArray; ) c. Integer variable named largest d. Integer value named largestIndex 4. Add the following methods to this class: a. A constructor with one String parameter that...
1. create a class called ArrayStack that is a generic class. Create a main program to...
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class. 2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need a) remove the capacity parameter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT