Question

In: Computer Science

(C++ programming) Assignment *Circle Class -Radius r (private) as an attribute variable -Member function -Get(): Function...

(C++ programming) Assignment

*Circle Class
-Radius r (private) as an attribute variable
-Member function
-Get(): Function that returns r value of property variable
-Put(int d): A function that stores d in attribute variable r

*Declare a one-dimensional array of type Circle and in each array element
Read and store integers from standard input device

*Declare the swap() function to swap two elements with each other

*Write a program that sorts the elements of a one-dimensional array of circle type
in ascending order according to the value of r. (Use the swap() function)

*Assume array size is 10

Solutions

Expert Solution

All the explanation is in the comments of the code itself.

Code--

#include<bits/stdc++.h>
using namespace std;
class Circle
{
private:
int radius;
  
public:
double Get()
{
return radius;
}
void Put(int d)
{
radius=d;
}
};
void swap(Circle &x,Circle &y)
{
Circle temp;
temp.Put(x.Get());
x.Put(y.Get());
y.Put(temp.Get());
}

int main()
{
//declare an one dimentional array of Circle
Circle cirArr[10];
int t;
  
//prompt the user to give the inputs
cout<<"Input:"<<endl;
for(int i=0;i<10;i++)
{
cin>>t;
cirArr[i].Put(t);
}
  
//sort the array
for(int i=0;i<9;i++)
{
for(int j=0;j<10-i-1;j++)
{
if(cirArr[j].Get()>cirArr[j+1].Get())
{
swap(cirArr[j],cirArr[j+1]);
}
}
}
  
//display the array after sorting
cout<<"Output after sorting:"<<endl;
for(int i=0;i<10;i++)
{
cout<<cirArr[i].Get()<<" ";
}
}

Output Screenshot--

Note--

Please upvote if you like the effort.


Related Solutions

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++ programming. Thank you. Money class has the following member variables and functions. -member variable...
Using C++ programming. Thank you. Money class has the following member variables and functions. -member variable : dollar, cent -member function : setMoney(int dollar, int cent), printMoney(), operator overloading(+) Program the Money class so that the following function can be performed. int main(){ Money a, b, c; A.setMoney(10, 60); B.setMoney(20, 70; (a+b).printMoney(); c = a + b; c.printMoney(); }
(JAVA): The Collection ADT 1. We have a Circle class that includes radius attribute of type...
(JAVA): The Collection ADT 1. We have a Circle class that includes radius attribute of type int, set by the constructor. Write a compareTo method for this class so that circle objects are ordered on the basis of their circumference (? = 2??). 2. We have a Person class that includes name and age attributes of type String and int respectively, both set by the constructor. Write a compareTo method for this class so that person objects are ordered on...
Write a Circle class that has the following member variables: radius as a double PI as...
Write a Circle class that has the following member variables: radius as a double PI as a double initialized with 3.14159 The class should have the following member functions: Default constructor Sets the radius as 0.0 and pi as 3.14159 Constructor Accepts the radius of the circles as an argument setRadius A mutator getRadius An accessor getArea Returns the area of the circle getDiameter Returns the diameter of the circle getCircumference Returns the circumference of the circle Write a program...
Write a Circle class that has the following member variables: • radius: a double • pi:...
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, which...
a- If the radius r of a circle is measured to be r  0.325 +\-...
a- If the radius r of a circle is measured to be r  0.325 +\- 0.001 m, then calculate the area of the circle A =  3.14r 2 , as well as the uncertainty in the area. b-Explain the difference between precision and accuracy. c-Do systematic errors affect precision or accuracy? Do random errors affect precision or accuracy?
1. If the radius r of a circle is measured to be r  0.325 +\-...
1. If the radius r of a circle is measured to be r  0.325 +\- 0.001 m, then calculate the area of the circle A =3.14 r^2, as well as the uncertainty in the area. 2. Explain the difference between precision and accuracy. 3. Do systematic errors affect precision or accuracy? Do random errors affect precision or accuracy?
A circle of radius r has area A = πr2. If a random circle has a...
A circle of radius r has area A = πr2. If a random circle has a radius that is uniformly distributed on the interval (0, 1), what are the mean and variance of the area of the circle? Change the distribution of the radius to an exponential distribution with paramter β = 2. Also find the probability that the area of the circle exceeds 3, if it is known that the area exceeds 2.
PHP programming language Circle Area, Circumference and ratio:  For a circle with a given radius, write a...
PHP programming language Circle Area, Circumference and ratio:  For a circle with a given radius, write a program to compute 1) area of the circle, 2) circumference of the circle and 3) the ratio of the circumference to its diameter.  You will use 3 different values of radius a) 10cm, b) 50 cm, and c) 100cm for your computations. The output should print or echo the following statements identifying the writer of the program and the computation for each value of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT