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

*in Java 1.Create a card class with two attributes, suit and rank. 2.In the card class,...
*in Java 1.Create a card class with two attributes, suit and rank. 2.In the card class, create several methods: a. createDeck – input what type of deck (bridge or pinochle) is to be created and output an array of either 52 or 48 cards. b.shuffleDeck – input an unshuffled deck array and return a shuffled one. + Create a swap method to help shuffle the deck c. countBridgePoints – inputs a 13-card bridge ‘hand’-array and returns the number of high-card...
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. Circle: Implement a Java class with the name Circle. It should be in the package...
1. Circle: Implement a Java class with the name Circle. It should be in the package edu.gcccd.csis. The class has two private instance variables: radius (of the type double) and color (of the type String). The class also has a private static variable: numOfCircles (of the type long) which at all times will keep track of the number of Circle objects that were instantiated. Construction: A constructor that constructs a circle with the given color and sets the radius to...
Problem 1: based on java.util.LinkedList class, create MyQueue class that should have the methods:enqueue(), dequeue(), peek(),...
Problem 1: based on java.util.LinkedList class, create MyQueue class that should have the methods:enqueue(), dequeue(), peek(), size(), isEmpty(). Problem 2: Create a new Java Application that test MyQueue by having the following methods in main class: A method to generate a number of element between two given values and save them in a queue A method to print a queue (10 elements per line). The original queue should remain as is after the print A method to exchange the first...
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...
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.
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...
Java program Create two classes based on the java code below. One class for the main...
Java program Create two classes based on the java code below. One class for the main method (named InvestmentTest) and the other is an Investment class. The InvestmentTest class has a main method and the Investment class consists of the necessary methods and fields for each investment as described below. 1.The Investment class has the following members: a. At least six private fields (instance variables) to store an Investment name, number of shares, buying price, selling price, and buying commission...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT