Question

Create a class called planet with private members name, percent02, temp. Create a constructor prototype and...

Create a class called planet with private members name, percent02, temp. Create a constructor prototype and implementation. In the main, create 2 objects of class planet, one with arguments and the other without. Create a function to change name, percent02 and temp after the object has been created and a function that displays the current values of the members. Implement the operations specified above in the main of your program. This is all in C++, please help.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:::::

#include <iostream>
#include <string>
using namespace std;
class Planet{
private:
   string name;
   float percentO2;
   int temp;
public:
   Planet(){
       name="";
       percentO2 = 0;
       temp = 0;
   }

   Planet(string n,float p,int t){
       name=n;
       percentO2 = p;
       temp = t;
   }

   string getName() const
   {
       return name;
   }

   float getPercentO2() const
   {
       return percentO2;
   }

   int getTemp() const
   {
       return temp;
   }

   void setName(string name)
   {
       this->name = name;
   }

   void setPercentO2(float percentO2)
   {
       this->percentO2 = percentO2;
   }

   void setTemp(int temp)
   {
       this->temp = temp;
   }

   void display(){
       cout<<"Name of the Planet : "<<name<<endl;
       cout<<"Percent of O2 of the Planet : "<<percentO2<<endl;
       cout<<"Temperature of the Planet : "<<temp<<endl;

   }

};


int main(){
   Planet p;
   Planet p2("Earth",68.32,24);
   cout<<"Printing Planet p : "<<endl;
   p.display();
   cout<<endl;
   cout<<"Printing Planet p2 : "<<endl;
   p2.display();

   cout<<"\nSetting value to Planet P"<<endl;
   p.setPercentO2(99.99);
   p.setName("Mars");
   p.setTemp(120);
   p.display();

   return 0;
}

output:

阻 ain.cppConsole <terminated> CPP_Workspace.exe [C/C++ Application] C\Users Mohamm th: printing Planet p: Name of the Planet

Add a comment
Know the answer?
Add Answer to:
Create a class called planet with private members name, percent02, temp. Create a constructor prototype and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please HELP!! I have been trying to get help for this problem forever! Create a class...

    please HELP!! I have been trying to get help for this problem forever! Create a class called planet with private members name, percent02, temp. Create a constructor prototype and implementation. In the main, create 2 objects of class planet, one with arguments and the other without. Create a function to change name, percent02 and temp after the object has been created and a function that displays the current values of the members. Implement the operations specified above in the main...

  • C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember...

    C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember class should have a constructor with no parameters, a constructor with a parameter, a mutator function and an accessor function. Also, include a function to display the name. Define a class called Athlete which is derived from FitnessMember. An Athlete record has the Athlete's name (defined in the FitnessMember class), ID number of type String and integer number of training days. Define a class...

  • Create a C++ project with 2 classes, Person and Birthdate. The description for each class is...

    Create a C++ project with 2 classes, Person and Birthdate. The description for each class is shown below: Birthdate class: private members: year, month and day public members: copy constructor, 3 arguments constructor, destructor, setters, getters and age (this function should return the age) Person class: private members: firstName, lastName, dateOfBirth, SSN public members: 4 arguments constructor (firstName, lastName, datOfBirth and SNN), destructor and printout Implementation: - use the separated files approach - implement all the methods for the 2...

  • Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment...

    Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of 100 accounts. Use an array of pointers to objects for this. However, your...

  • C++ program Create a Student class that contains three private data members of stududentID (int), lastName...

    C++ program Create a Student class that contains three private data members of stududentID (int), lastName (string), firstName(string) and a static data member studentCount(int). Create a constructor that will take three parameters of studentID, lastName and firstName, and assign them to the private data member. Then, increase the studentCount in the constructor. Create a static function getStudentCount() that returns the value of studentCount. studentCount is used to track the number of student object has been instantiated. Initialize it to 0...

  • PYTHON Task 1 Create a class called Window It has 2 public properties 1 private property...

    PYTHON Task 1 Create a class called Window It has 2 public properties 1 private property 1 constructor that takes 3 arguments pass each argument to the appropriate property Task 2 In a new file import the Window class Instantiate the Window object Output the two public properties Task 3 Alter the Window class in Task 1 Add an accessor and mutator (the ability to access and change) to the private property Task 4 Create a class named Instrument Give...

  • c++ program Implement a class called Person with the following members: 1a. ????, a private variable...

    c++ program Implement a class called Person with the following members: 1a. ????, a private variable of type ?????? 1b. ???, a private variable of type ??? 1c. Default constructor to set name to "" and age to 0 1d. Non-default constructor which accepts two parameters for name and age 1e. A copy constructor 1f. The post-increment operator 1g. The pre-decrement operator 1h. The insertion and extraction stream operators >>and <<

  • Using C++ create a class called person. A person can have a name, address, age. For...

    Using C++ create a class called person. A person can have a name, address, age. For this class create a default constructor and parameterized constructor. Show the main as int main() { } ----------------------------------------------------- Show how you will define the class and call it in the main. Only create two instances/objects in main using the two created constructors.

  • About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which...

    About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...

  • Create a class hierarchy to be used in a university setting. The classes are as follows:...

    Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last name...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT