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.
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...
Objective: Create an Inheritance Hierarchy to Demonstrate Polymorphic Behavior 1. Create a Rectangle 2. Class Derive...
Objective: Create an Inheritance Hierarchy to Demonstrate Polymorphic Behavior 1. Create a Rectangle 2. Class Derive a Square Class from the Rectangle Class 3. Derive a Right Triangle Class from the Rectangle Class 4. Create a Circle Class 5. Create a Sphere Class 6. Create a Prism Class 7. Define any other classes necessary to implement a solution 8. Define a Program Driver Class for Demonstration (Create a Container to hold objects of the types described above Create and Add...
1. Create a class Car with data: Name, Price, Production and properly methods. 2. Create another...
1. Create a class Car with data: Name, Price, Production and properly methods. 2. Create another class named GenericCar with a parameter of the T type. This class manages a collection of object T (may be LinkedList) named a. Implementing some methods for GenericCar: Add: add new item of T to a Display: display all items of a getSize: return the number item of a checkEmpty: check and return whether a is empty or not delete(int pos): remove the item...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in Java. Circle Circle Radius: double Circle() Circle(newRadius: double) getArea(): double setRadius(newRadius: double): void getRadius(): double After creating the Circle class, you should test this class from the main() method by passing objects of this class to a method “ public static void printAreas(Circle c, int times)” You should display the area of the circle object 5 times with different radii.
C++ * Program 2:      Create a date class and Person Class.   Compose the date class...
C++ * Program 2:      Create a date class and Person Class.   Compose the date class in the person class.    First, Create a date class.    Which has integer month, day and year    Each with getters and setters. Be sure that you validate the getter function inputs:     2 digit months - validate 1-12 for month     2 digit day - 1-3? max for day - be sure the min-max number of days is validate for specific month...
2. Program containing two modules: a. Create a class Code one programmer-written constructor Create several instance...
2. Program containing two modules: a. Create a class Code one programmer-written constructor Create several instance data attributes Create 3 methods which will each be invoked from the driver program - one method will not receive any parameters, but will return a value to driver program - one method will receive one parameter, and will also return a value to driver program - a display method will receive 2 parameters from driver program Define a constant properly; use the constant...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT