Concept explainers
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, which is calculated as area = pi * radius * radius
• getDiameter—returns the diameter of the circle, which is calculated as diameter = radius * 2
• getCircumference—returns the circumference of the circle, which is calculated as circumference = 2 * pi * radius
Write a
Want to see the full answer?
Check out a sample textbook solutionChapter 13 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Additional Engineering Textbook Solutions
Modern Database Management (12th Edition)
Java How To Program (Early Objects)
Computer Systems: A Programmer's Perspective (3rd Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Software Engineering (10th Edition)
Concepts of Programming Languages (11th Edition)
- Double Bubble For this exercise you need to create a Bubble class and construct two instances of the Bubble object. You will then take the two Bubble objects and combine them to create a new, larger combined Bubble object. This will be done using functions that take in these Bubble objects as parameters. The Bubble class contains one data member, radius_, and the corresponding accessor and mutator methods for radius_, GetRadius and SetRadius. Create a member function called CalculateVolume that computes for the volume of a bubble (sphere). Use the value 3.1415 for PI. Your main function has some skeleton code that asks the user for the radius of two bubbles. You will use this to create the two Bubble objects. You will create a CombineBubbles function that receives two references (two Bubble objects) and returns a Bubble object. Combining bubbles simply means creating a new Bubble object whose radius is the sum of the two Bubble objects' radii. Take note that the CombineBubbles function…arrow_forwardsubject: Object oriented programming (OOP): DO TASK IN C++ Define a pure abstract base class called BasicShape . The BasicShape class should have the following members: Private Member Variable: area, type double used to hold the shape's area. Public Member Functions: setArea: assigns received argument to area variable. getArea. This function should return the value in the member variable area. calcArea. This function should be a pure virtual function. Next, define a class named Circle . It should be derived from the BasicShape class. It should have the following members: Private Member Variables: centerX, type integer used to hold the x coordinate of the circle’s center. centerY, type integer used to hold the y coordinate of the circle’s center. radius, type double used to hold the circle's radius. Public Member Functions: constructor—accepts values for centerX, centerY, and radius. Should also call the overridden calcArea function described below.…arrow_forwardStatic Data member and Friend Function Q#01: In this assignment you will be creating a class named Employee. Employee class has the following data members: Employee ID. Employee Name Department Employee Salary Static data member which will hold the value of total no. of employees Employee class must have the following member functions: Function Description Employee() Default constructor for Employee class, which will set employee id to 0, employee name to NULL, employee department to NULL and salary to 0.0 Employee(int, char *, char *, float); It will take employee id, employee name, department and salary as arguments and initialize their values using member initializer list Employee(Employee &); Copy constructor which will initialize one object with another object using deep copy Setter functions You have to define setter function for each data member which will take a value as an argument and set their values Getter functions You have…arrow_forward
- Define a Pet class that stores the pet’s name, age, and weight. Add appropriateconstructors, accessor functions, and mutator functions. Also define a functionnamed getLifespan that returns a string with the value “unknown lifespan.” Next, define a Dog class that is derived from Pet. The Dog class should have aprivate member variable named breed that stores the breed of the dog. Add mutator and accessor functions for the breed variable and appropriate constructors.Redefine the getLifespan function to return “Approximately 7 years” if the dog’sweight is over 100 pounds and “Approximately 13 years” if the dog’s weight isunder 100 pounds. Next, define a Rock class that is derived from Pet. Redefine the getLifespanfunction to return “Thousands of years.” Finally, write a test program that creates instances of pet rocks and pet dogs thatexercise the inherited and redefined functions. use c++arrow_forwardTrue/False: a member function in a class can access all of its class's member variables, but not if the variables are private. A) True B) Falsearrow_forwardAccount Class) Create an Account class that a bank might use to represent customers’ bank accounts. Include a data member of type intto represent the account balance. Provide a constructor that receives an initial balance and uses it to initialize the data member. Theconstructor should validate the initial balance to ensure that it’s greater than or equal to 0. If not, set the balance to 0 and display anerror message indicating that the initial balance was invalid. Provide three member functions. Member function credit should add anamount to the current balance. Member function debit should withdraw money from the Account and ensure that the debit amountdoes not exceed the Account’s balance. If it does, the balance should be left unchanged and the function should print a messageindicating "Debit amount exceeded account balance." Member function getBalance should return the current balance. Create a programthat creates two Account objects and tests the member functions…arrow_forward
- Write a class named Coin . The Coin class should have the followingmember variable:A string named sideUp . The sideUp member variable will holdeither “heads” or “tails” indicating the side of the coin that isfacing up.The Coin class should have the following member functions:A default constructor that randomly determines the side of thecoin that is facing up (“heads” or “tails”) and initializes the sideUpmember variable accordingly.A void member function named toss that simulates the tossingof the coin. When the toss member function is called, itrandomly determines the side of the coin that is facing up(“heads” or “tails”) and sets the sideUp member variableaccordingly.A member function named getSideUp that returns the value ofthe sideUp member variable.Write a program that demonstrates the Coin class. The programshould create an instance of the class and display the side that isinitially facing up. Then, use a loop to toss the coin 20 times. Eachtime the coin is tossed, display the…arrow_forwardA member function should be static if it does not access__________ class membersarrow_forwardDesign a class called Bird that includes three pieces of information as data members-name (type string), species (type string) and a sizeInInches (type int).Define virtual function getCageSize ().Your class should have a constructor that initializes the three data members. Provide setter and getter function for each data member.Overload the virtual function of inherited class. Write a main part which creates the Bird class and a derived class Vulture.arrow_forward
- C++ Friend function concepts Do not use operator overloading Create a class User with private member variables "id". In the class define a function increment_user_id() which will increment the id and return it as well. Create another method "void show_Id()" to show the id for a particular object. Create a constructor of User class where increment the Id by calling the increment_user_id() method for every new object . Finally create two objects of the class and print their corresponding id's on console.arrow_forwardTrue or FalseA base class reference variable can reference an object of any class that is derived from the base class.arrow_forward(C++) 23. True/False: function getGallons() is an inline member function 24. Design a class called Date. The class should store a date in three private integers: month, day, year. There should be a member function to print out the date in the month/day/year format, e.g. 12/25/2015, 4/1/1970 There should be a constructor which takes three parameters to initialize the date. It should not accept values for day greater than 31 or less than 1, or values for month greater than 12 or less than 1. If the constructor is called with these values an error message should be printed out and the field set to 0. Any value for year is acceptable. There do not need to be any other member functions. Provide the class declaration and also the implementation of the member function and constructor.arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT