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...
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...
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.
1) A circle of radius r has area A = π r2. If a random circle...
1) A circle of radius r has area A = π r2. If a random circle has a radius that is evenly distributed in the interval (0, 1), what are the mean and variance of the area of ​​the circle? choose the correct answer A) 1/3 and 1/12 B) Pi/3 and 1/12 C) Pi/3 and 1/5 D) Pi/3 and (4/45)*Pi^2
Write c code program for the following Write a function, circle, which takes the radius of...
Write c code program for the following Write a function, circle, which takes the radius of a circle from the main function and assign the area of the circle to the variable, area, and the perimeter of the circle to the variable, perimeter. Hint: The function should have three variables as input. Since the contents of the variables are to be modified by a function, it is necessary to use pointers. Please type out the full usable program. Thank you.
C++ make a rational class that includes these members for rational -private member variables to hold...
C++ make a rational class that includes these members for rational -private member variables to hold the numerator and denominator values -a default constructor -an overloaded constructor that accepts 2 values for an initial fraction -member fractions add(), sub(), mul(), div(), less(), eq(), and neq() (less should not return true if the object is less than argument) -a member function that accepts an argument of type of ostream that writes the fraction to that open output stream do not let...
If a circle C with radius 1 rolls along the outside of the circle x2 +...
If a circle C with radius 1 rolls along the outside of the circle x2 + y2 = 36, a fixed point P on C traces out a curve called an epicycloid, with parametric equations x = 7 cos(t) − cos(7t), y = 7 sin(t) − sin(7t). Graph the epicycloid. Find the area it encloses.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT