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

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?
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
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.
Complete the following assignment in C programming language. Get the user’s first name and store it...
Complete the following assignment in C programming language. Get the user’s first name and store it to a char array Declare a character array to hold at least 20 characters. Ask for the user’s first name and store the name into your char array. Hint: Use %s for scanf. %s will only scan one word and cannot scan a name with spaces. Get 3 exam scores from the user: Declare an array of 3 integers Assume the scores are out...
c++ Programming For this assignment you will be building on your Fraction class. However, the changes...
c++ Programming For this assignment you will be building on your Fraction class. However, the changes will be significant, so I would recommend starting from scratch and using your previous version as a resource when appropriate. You'll continue working on your Fraction class for one more week, next week. For this week you are not required to provide documentation and not required to simplify Fractions. Please keep all of your code in one file for this week. We will separate...
Programming Language: C# Person Class Fields - password : string Properties + «C# property, setter private»...
Programming Language: C# Person Class Fields - password : string Properties + «C# property, setter private» IsAuthenticated : bool + «C# property, setter absent» SIN : string + «C# property, setter absent» Name : string Methods + «Constructor» Person(name : string, sin : string) + Login(password : string) : void + Logout() : void + ToString() : string Transaction Class Properties + «C# property, setter absent » AccountNumber : string + «C# property, setter absent» Amount : double + «C#...
15. Let r be a positive real number. The equation for a circle of radius r...
15. Let r be a positive real number. The equation for a circle of radius r whose center is the origin is (x^2)+(y^2)= r^2 . (a) Use implicit differentiation to determine dy/dx . (b) Let (a,b) be a point on the circle with a does not equal 0 and b does not equal 0. Determine the slope of the line tangent to the circle at the point (a,b). (c) Prove that the radius of the circle to the point (a,b)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT