Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- class VideoGame
- {
- private:
- string *name;
- double *rating;
- double *price;
- public:
- void setName(string n){
- name = new string;
- *name = n;
- }
- void setPrice(double p){
- price = new double;
- *price = p;
- }
- void setRating(double r){
- rating = new double;
- *rating = r;
- }
- string getName()
- {
- return *name;
- }
- double getRating()
- {
- return *rating;
- }
- double getPrice()
- {
- return *price;
- }
- void Show()
- {
- cout << "VIDEO GAME INFORMATION" << endl;
- cout << "______________________" << endl;
- cout << endl;
- cout << "Video Game Title : " << *name << endl;
- cout << "Retail Price : $" << fixed << setprecision(2) << *price << endl;
- cout << "Game Rating (out of 5) : " << fixed << setprecision(1) << *rating << endl;
- cout << endl;
- }
- VideoGame()
- {
- name = new string;
- *name = "";
- rating = new double;
- *rating = 0;
- price = new double;
- *price = 0;
- }
- VideoGame(string n, double r, double p)
- {
- name = new string;
- *name = n;
- rating = new double;
- *rating = r;
- price = new double;
- *price = p;
- }
- ~VideoGame(){
- delete name;
- delete rating;
- delete price;
- cout << "Destructor Called" << endl;
- }
- };
- #include <iostream>
- #include "VideoGame.h"
- using namespace std;
- int main(){
- VideoGame *vg = NULL;
- vg = new VideoGame;
- //Part One, testing get's and sets, printing on screen.
- cout << "PART ONE" << endl;
- cout << endl;
- vg->setName("Paper Mario Color Splash");
- vg->setPrice(59.99);
- vg->setRating(4.9);
- cout << "Game Name : " << (*vg).getName() << endl;
- cout << "Price : " << (*vg).getPrice() << endl;
- cout << "Rating : " << (*vg).getRating() << endl;
- cout << endl;
- delete vg;
- cout << "PART TWO" << endl;
- cout << endl;
- //Part Two, using arrays to set values.
- VideoGame *VideoArray = NULL;
- VideoArray = new VideoGame[100]; //Set to 100 elements.
- VideoArray[0] = { "Super Mario Brothers", 4.0, 39.99 };
- VideoArray[1] = { "Pac-Man", 5.0, 9.99 };
- int size = 2;
- //A for loop to display the multiple possible elements of the array
- for (int i = 0; i < size; i++)
- {
- VideoArray[i].Show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement