The Galactic Federation of Planets (GFP) maintains records on
all planets that are applying to become members of the GFP. A
planet may make an application to become a member of the Galactic
Federation of Planets when their technology has led them to develop
Star Gate technology enabling them to travel to other planets in
the galaxy outside their own solar system. Your assignment is to
create a class that can be used to hold the basic information about
a planet when it has made application
2.1 This software system shall define a class called Planet (file names shall be Planet.h andPlanet.cpp) which contains all information to on a planet applying for membership in the Galactic Federation of Planets.
2.1.1 The Planet class shall contain private variables as described below:
2.1.1.1 A character array, called m_sPlanetName capable of holding strings of up to 31 characters, i.e. 32 chars in length.
2.1.1.2 A char variable called m_cStarType which will hold the single character designating the planet's star type (O, B, A, F, G, K, M). | ||||
2.1.1.3 An array of three doubles called m_dGalacticCoords giving the planet's sun's location in the galaxy along the GFP defined galactic X, Y, and Z coordinates. This number will be given in light years from the galactic center. | ||||
2.1.1.4 A double called m_dStarGateTechSD giving the standard Galactic Star Date when the planet achieved Star Gate technology. | ||||
2.1.1.5 A double called m_dGFPApplySD giving the standard Galactic Star Date when the planet applied for admission to the Galactic Federation of Planets. | ||||
2.1.2 The Planet class shall contain public functions as described below: | ||||
2.1.2.1 Planet(), ~Planet() A default constructor and destructor. | ||||
2.1.2.2 Planet(const char *pName, char sType, double galX, double galY, double galZ, double sdTech, double sdApply) A parameterized constructor which shall take as arguments a character array giving the planet name, a character designating the star type, three doubles defining the galactic X,Y,Z coordinates, a double giving the date for achieving Star Gate technology, and a double giving the date for application for admission into the GFP. | ||||
2.1.2.3 Get/Set functions There will be a getVariable() and a setVaraible() function designed to return the value stored in or set the value stored in a planet's data. Specifically these functions shall be prototyped as: | ||||
2.1.2.3.1 void setPlanetName(const char *pName) and void getPlanetName(char *pName);- Get and set the planet name. In the set function a char array with the name is passed in to be copied into m_sPlanetName using strcpy. In the get function a char array is passed in into which you copy m_sPlanetName, again using strcpy. Remember the equals operator (=) has not been overloaded for use with char array strings so you CANNOT say m_sPlanetName = pName. | ||||
2.1.2.3.2 void setStarType(char st) and char getStarType() - Get and set the planet's sun's type. | ||||
2.1.2.3.3 void setGalacticCoords(double X, double Y, double Z) and void getGalacticCoords(double *X, double *Y, double *Z) - Get and set the planet's galactic coordinates. The get function shall be a pointer function. | ||||
2.1.2.3.4 void setStarGateTechStarDate(double date) and double getStarGateTechStarDate() - Get and set the Star Date when Star Gate technology was achieved. | ||||
2.1.2.3.5 void setApplicationStarDate(double date) and void getApplicationStarDate(double& date) - Get and set the Star Date when application was made to enter the Galactic Federation of Planets. The get function shall be a reference function. | ||||
2.1.2.3.6 void printPlanetInfo() - Print all information on this Planet. This includes name, star type, galactic coordinates, and the two star dates. | ||||
2.2 The class file and its' associated header file must be capable of being compiled and linked in with the instructor's driver program (which will contain main()) for testing. Do not turn in your source file containing main(). It will not be used for testing. Do not include main() in your Planet.cpp file. |
Planet.h
#include<bits/stdc++.h>
using namespace std;
class Planet{
private:
char m_sPlanetName[32];
char m_cStarType;
double m_dGalacticCoords[3];
double
m_dStarGateTechSD,m_dGFPApplySD;
public:
Planet(){}
~Planet(){}
Planet(const char *pName, char
sType, double galX, double galY, double galZ, double sdTech, double
sdApply);
void setPlanetName(const char
*pName);
void getPlanetName(char
*pName);
void setStarType(char st);
char getStarType();
void setGalacticCoords(double X,
double Y, double Z);
void getGalacticCoords(double *X,
double *Y, double *Z);
void setStarGateTechStarDate(double
date);
double
getStarGateTechStarDate();
void setApplicationStarDate(double
date);
void
getApplicationStarDate(double& date);
void printPlanetInfo();
};
Planet.cpp
#include<bits/stdc++.h>
#include "Planet.h"
using namespace std;
Planet::Planet(const char *pName, char sType, double galX,
double galY, double galZ, double sdTech, double sdApply){
strcpy(m_sPlanetName,pName);
m_cStarType=sType;
m_dGalacticCoords[0]=galX;
m_dGalacticCoords[1]=galY;
m_dGalacticCoords[2]=galZ;
m_dStarGateTechSD=sdTech;
m_dGFPApplySD=sdApply;
}
void Planet::setPlanetName(const char *pName){
strcpy(m_sPlanetName,pName);
}
void Planet::getPlanetName(char *pName){
strcpy(pName,m_sPlanetName);
}
void Planet::setStarType(char st){
m_cStarType=st;
}
char Planet::getStarType(){
return m_cStarType;
}
void Planet::setGalacticCoords(double X, double Y, double Z){
m_dGalacticCoords[0]=X;
m_dGalacticCoords[1]=Y;
m_dGalacticCoords[2]=Z;
}
void Planet::getGalacticCoords(double *X, double *Y, double
*Z){
*X=m_dGalacticCoords[0];
*Y=m_dGalacticCoords[1];
*Z=m_dGalacticCoords[2];
}
void Planet::setStarGateTechStarDate(double date){
m_dStarGateTechSD=date;
}
double Planet::getStarGateTechStarDate(){
return m_dStarGateTechSD;
}
void Planet::setApplicationStarDate(double date){
m_dGFPApplySD=date;
}
void Planet::getApplicationStarDate(double& date){
date=m_dGFPApplySD;
}
void Planet::printPlanetInfo(){
cout<<"Planet Name:
"<<m_sPlanetName<<endl;
cout<<"Star Type:
"<<m_cStarType<<endl;
cout<<"Galactic Coords (In Light Years) ==>
"<<"X: "<<m_dGalacticCoords[0]<<" Y:
"<<m_dGalacticCoords[1]<<" Z:
"<<m_dGalacticCoords[2]<<endl;
cout<<"StarGateTechStarDate:
"<<m_dStarGateTechSD<<endl;
cout<<"ApplicationStarDate:
"<<m_dGFPApplySD<<endl;
}
I tested the above code with my driver code
driver.cpp
#include<bits/stdc++.h>
#include "Planet.cpp"
using namespace std;
int main(){
Planet p("earth",'O',1,2,3,12,10);
p.printPlanetInfo();
char pName[32];
p.getPlanetName(pName);
cout<<"name: "<<pName<<endl;
p.setStarType('B');
cout<<"New Star Name:
"<<p.getStarType()<<endl;
p.setGalacticCoords(3.4,2.4,5.6);
p.printPlanetInfo();
double date;
p.getApplicationStarDate(date);
cout<<date<<endl;
double x,y,z;
p.getGalacticCoords(&x,&y,&z);
cout<<"new coords: "<<x<<"
"<<y<<" "<<z<<endl;
}
Output:
Planet Name: earth
Star Type: O
Galactic Coords (In Light Years) ==> X: 1 Y: 2 Z: 3
StarGateTechStarDate: 12
ApplicationStarDate: 10
name: earth
New Star Name: B
Planet Name: earth
Star Type: B
Galactic Coords (In Light Years) ==> X: 3.4 Y: 2.4 Z: 5.6
StarGateTechStarDate: 12
ApplicationStarDate: 10
10
new coords: 3.4 2.4 5.6
I am providing screenshots of the code for indentation purpose
Get Answers For Free
Most questions answered within 1 hours.