A. add planet (prompt for a name, mass, diameter or radius, [type1for planet,2 f
ID: 3617846 • Letter: A
Question
A. add planet (prompt for a name, mass, diameter or radius, [type1for planet,2 for planetoids, 3 for other], calculate the surfacearea, density, g) B. Remove planet (prompt for a name) C. find planet (prompt for a name, mass, diameter or radius,calculate the surface area, density, g) D. list all (alphabetical order, assume they arespheres) E. list planets (alphabetical order, assume they arespheres) F. list planetoids (pluto) (alphabetical order, assumethey are spheres) G. list otherIt would be good if classess (private and public) will beincluded. Thanks
B. Remove planet (prompt for a name) C. find planet (prompt for a name, mass, diameter or radius,calculate the surface area, density, g) D. list all (alphabetical order, assume they arespheres) E. list planets (alphabetical order, assume they arespheres) F. list planetoids (pluto) (alphabetical order, assumethey are spheres) G. list other
It would be good if classess (private and public) will beincluded. Thanks
Explanation / Answer
I would start be making a structure (class) Planet with datamembers: private: enum Type (an enumeration of PLANET_TYPE, PLANETOID_TYPE, andOTHER_TYPE) double Mass double Radius string name //methods public: getName() getMass() getSufArea() getDensity() getGravity() getDiameter() getRadius() getType() //This was most of your header file.
With that class, make a list or vector of Planet. http://www.cplusplus.com/reference/stl/list/list/ http://www.cplusplus.com/reference/stl/vector/vector/
For your prompts, use a while(true){} loop with a series ofif-else and use gets or scanf for input.
To add/remove, just follow the examples for erase/insert fromthose links.
To find elements (planets in your list), use an iterator andcompare the values you wanted, then do the necessary action (print,add, remove). http://www.cplusplus.com/reference/stl/list/begin/
Tips: Always validate data. I mean check for null and otherproblems. If you make a mistake, it may show at the wrong time andthe wrong place and give you a seg fault.
Be careful when using delete. This can be a factor of segfaults. After deleting, set the pointers to 0 (null).
If you still have problems, test each module (class) andmethod (function) individually and workout by hand what you expectat each point. Then print all that to the screen or to a file toreview. fprintf() or printf()
Good luck http://www.cplusplus.com/reference/stl/vector/vector/
For your prompts, use a while(true){} loop with a series ofif-else and use gets or scanf for input.
To add/remove, just follow the examples for erase/insert fromthose links.
To find elements (planets in your list), use an iterator andcompare the values you wanted, then do the necessary action (print,add, remove). http://www.cplusplus.com/reference/stl/list/begin/
Tips: Always validate data. I mean check for null and otherproblems. If you make a mistake, it may show at the wrong time andthe wrong place and give you a seg fault.
Be careful when using delete. This can be a factor of segfaults. After deleting, set the pointers to 0 (null).
If you still have problems, test each module (class) andmethod (function) individually and workout by hand what you expectat each point. Then print all that to the screen or to a file toreview. fprintf() or printf()
Good luck
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.