Question

In: Computer Science

(C++ program) Write and Design a Star Class definition. Attribute of a Star are : -...

(C++ program)

Write and Design a Star Class definition.

Attribute of a Star are :
- radius
- age
- coordinates in space: x,y.z
Behaviors of a Star are:
- calculateVolume()
- calculateSurfaceArea()
- calculateCircumference()
- DisplayCoordinates()
- DisplayStar()

be sure to supply constructor() method(s) and all your set() and get() methods. The above is only a generic description of the class Star. You will need to design the datatypes, method return values, method parameters, etc...

Sphere Formulas in terms of radius r:

  • Volume of a sphere:
    • V = (4/3)πr3
  • Circumference of a sphere:
    • C = 2πr
  • Surface area of a sphere:
    • A = 4πr2

Solutions

Expert Solution

Program Code Screenshot :

Sample Output :

Program Code to Copy

#include <iostream>
#include <cmath>

using namespace std;

class Star{
private:
double radius;
int age;
  
public:
Star(double r, int a){
radius = r;
age = a;
}
  
public double getRadius(){
return radius;
}
  
public void setRadius(double r){
radius = r;
}
  
public double getAge(){
return age;
}
  
public void setAge(int a){
age = a;
}
  
//calculate the volume
double calculateVolume(){
return (4.0/3)*M_PI*radius*radius*radius;
}
  
//Calculate the surface area
double calculateSurfaceArea(){
return 4*M_PI*radius*radius;
}
  
//Calculate the Circumference
double calculateCircumference(){
return 2*M_PI*radius;
}
  
void DisplayCoordinates(){
//Description not given
}
  
//Display the star attributes
void DisplayStar(){
cout<<"Star, radius : "<<radius<<", Age : "<<age<<endl;
}
};

int main()
{
Star s(5.4,1000000);
s.DisplayStar();
cout<<"Circumference "<<s.calculateCircumference()<<endl;
cout<<"Area "<<s.calculateSurfaceArea()<<endl;
cout<<"Volume "<<s.calculateVolume()<<endl;

return 0;
}


Related Solutions

Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the data fields private): a) An int data field named id for the account. b) A double data field named balance for the account. c) A double data field named annualInterestRate that stores the current interest rate. d) A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. e) The accessor and mutator functions for id, balance, and annualInterestRate....
C++ PROGRAM 1) Create a "CashOut" currency class with two integer attributes and one string attribute,...
C++ PROGRAM 1) Create a "CashOut" currency class with two integer attributes and one string attribute, all of which are non-public. The int attributes will represent the whole part (or currency note value) and fractional part (or currency coin value) such that 100 fractional parts equal 1 whole part. The string attribute will represent the currency name. 2) Create a "MoreCash" derived/inherited class with one additional non-public double attribute to represent the conversion factor from/to US Dollar. The value of...
Please write this program in C++ Write a program that           - a user-defined class Cuboid...
Please write this program in C++ Write a program that           - a user-defined class Cuboid which has the following elements:                    - default constructor (has no parameters)                    - constructor that has 3 parameters (height, length, width)                    - data members                              - height, length, width                    - member functions                              - to set the value of each of the data members - 3 functions                              - to get the value of each of the data members - 3...
. (a) Write a C++ program to find Fibonacci numbers. (For the definition of Fibonacci numbers...
. (a) Write a C++ program to find Fibonacci numbers. (For the definition of Fibonacci numbers and the recursive formula please refer to problem 5 of Chapter 2 at page 81 in the text-book.) The program asks the user to input an integer and outputs the corresponding Fibonacci number. For example, if the user inputs 4, the program outputs the fifth Fibonacci number, which is 3. Introduce two local variables in the recursion function (suppose we call it fib(n)), one...
********************C# C# C#******************** Part A: Create a project with a Program class and write the following...
********************C# C# C#******************** Part A: Create a project with a Program class and write the following two methods(headers provided) as described below: 1. A Method, public static int InputValue(int min, int max), to input an integer number that is between (inclusive) the range of a lower bound and an upper bound. The method should accept the lower bound and the upper bound as two parameters and allow users to re-enter the number if the number is not in the range...
in C++ Write a definition for a class ‘point’ to describe a point with coordinates (X,Y)...
in C++ Write a definition for a class ‘point’ to describe a point with coordinates (X,Y) in 2-D space. The private data members are the coordinates X and Y of type ‘double’. The public member functions are: A default constructor (no parameters) to initialize X and Y to zero. An explicit value constructor with two parameters to initialize the values of X and Y. Two functions, one to set the X value and the other to set the Y value...
C++ Using an appropriate definition of ListNode, design a simple linked list class with only two...
C++ Using an appropriate definition of ListNode, design a simple linked list class with only two member functions and a default constructor: void add(double x); boolean isMember(double x); LinkedList( ); The add function adds a new node containing x to the front (head) of the list, while the isMember function tests to see if the list contains a node with the value x. Test your linked list class by adding various numbers to the list and then testing for membership....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT