Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This programming project implements a circle class and another class that uses t

ID: 3839470 • Letter: T

Question

This programming project implements a circle class and another class that uses the circle class.

PROBLEM Write a C++ class called circle which can be used to set circle radius, calculate area of a circle, calculate circumference of the circle, and return the respective information. The data members should be an integer identifier, a floating-point radius, a string units, and name of circle. Write another class that has a dynamic array of pointers to circles. This class should also have an integer variable to keep a count of the circles in the array.

INPUT Information describing circles to fill the array of circles. OUTPUT When “4. Display all circles” is selected, display tabulated results (with area and circumfrence calculated):

Example of output:

CIRCLES INFORMATION

NAME DIAMETER AREA CIRCUMFERENCE

U.S. Quarter 0.955 inches 99999999.999 9999999.999

Soccer center circle 18.3 meters 99999999.999 9999999.999

Basketball rim 18 inches 99999999.999 9999999.999

Saturn ring 270,000 km 99999999.999 9999999.999

PROCESSING Your main function should have a circle that displays a menu that offers the following options:

1. Input a circle 2. Find a circle 3. Delete a circle 4. Display all circles 5. Exit

Your program should allow the user to enter a menu selection. A member function of the class to process the dynamic array should be called accordingly for options 1 - 4. Program run should end with a message indicating termination when option 5 is selected.

STYLE Your program should be in three parts stored in three different files as follows: (a) Class declarations: circle.h (b) Class member function definitions: circle.cpp (c) Driver program: circle_driver.cpp

Explanation / Answer

PROGRAM CODE:

circle.h

#include <iostream>
#include <iomanip>
using namespace std;

class Circle
{
   public:
   int identifier;
   float radius;
   string units;
   string name;
  
   Circle(int id, float rad, string unit, string c_name)
   {
       identifier = id;
       radius = rad;
       units = unit;
       name = c_name;
   }
  
   float getArea()
   {
       return 3.14 * radius * radius;
   }
  
   float getCircumfenerce()
   {
       return 2*3.14*radius;
   }
  
   float getDiameter()
   {
       return 2*radius;
   }
  
   void print()
   {
       cout<<name<<" "<<getDiameter()<<" "<<units<<" "<<getArea()<<" "<<getCircumfenerce()<<endl;
   }
};

circle_driver.cpp

#include <iostream>
#include <iomanip>
#include <circle.h>
using namespace std;

int main() {
   int option;
   string name, unit;
   float radius;
   int counter = 0, id;
   Circle *circles[20];
   while(true)
   {
       cout<<" MENU 1. Input a circle 2. Find a circle 3. Delete a circle 4. Display all circles 5. Exit";
       cout<<" Enter your choice: ";
       cin>>option;
       Circle *c1;
       switch(option)
       {
           case 1: cout<<" Enter the name: ";
                   cin>>name;
                   cout<<" Enter the units: ";
                   cin>>unit;
                   cout<<" Enter the radius: ";
                   cin>>radius;
                   c1 = new Circle(counter, radius, unit, name);
                   circles[counter++] = c1;
                   break;
           case 2: cout<<" Enter the id to find: ";
                   cin>>id;
                   for(int i=0; i<counter; i++)
                   {
                       if(circles[i]->identifier == id)
                       {
                           circles[i]->print();
                           break;
                       }
                   }
                   break;
           case 3: cout<<" Enter the id to remove: ";
                   cin>>id;
                   for(int i=0; i<counter; i++)
                   {
                       if(circles[i]->identifier == id)
                       {
                           circles[i] = NULL;
                           break;
                       }
                   }
                   break;
           case 4: cout<<endl<<"NAME"<<" "<<"DIAMETER"<<" "<<"AREA"<<" "<<"CIRCUMFERENCE"<<endl;
                   for(int i=0; i<counter; i++)
                   {
                       if(circles[i] != NULL)
                           circles[i]->print();
                   }
                   break;
           case 5: cout<<"Goodbye"; exit(0);
       }
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote