Question

Utilize the code from last week Add a default, full, and copy constructor. Also add a...

Utilize the code from last week

Add a default, full, and copy constructor. Also add a constructor that allows you to specify only the name of the video game with no high score or times played specified. Adjust your code to demonstrate use of all 4 constructors and output of the resulting objects.

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;

class VideoGame {

private:

    string name;

    int highScore;

    int numOfPlays;

public:

    VideoGame() {

        name = "NA";

        highScore = 0;

        numOfPlays = 0;

    }

    VideoGame(string n, int score, int num) {

        name = n;

        highScore = score;

        numOfPlays = num;

    }

   

    void setName(string n) {

        name = n;

    }

    void setHighScore(int score) {

        highScore = score;

    }

    void setNumOfPlays(int num) {

        numOfPlays = num;

    }

    string getName() {

        return name;

    }

    int getHighScore() {

        return highScore;

    }

    int getNumOfPlays() {

        return numOfPlays;

    }

};

string inputName() {

    string n;

    cout << "Enter name of video game: ";

    getline(cin >> ws, n);

    return n;

}

int inputHighScore() {

    int score;

    cout << "Enter current high score of game: ";

    cin >> score;

    return score;

}

int inputNumOfPlays() {

    int num;

    cout << "Enter number of times game is played: ";

    cin >> num;

    return num;

}

void output(VideoGame game) {

   

    cout << game.getName() << endl

        << "Played " << game.getNumOfPlays() << " times (HIGH SCORE " << game.getHighScore() << ")" << endl;

}

int main() {

    VideoGame game1, game2;

    game1.setName(inputName());

    game1.setHighScore(inputHighScore());

    game1.setNumOfPlays(inputNumOfPlays());

   

  cout << "\nGame1" << endl;

    output(game1);

    cout << endl;

    game2.setName(inputName());

    game2.setHighScore(inputHighScore());

    game2.setNumOfPlays(inputNumOfPlays());

    cout << "\nGame2" << endl;

    output(game2);

    return 0;

}

Homework Answers

Answer #1

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;

class VideoGame {

private:

string name;

int highScore;

int numOfPlays;

public:

VideoGame() {

name = "NA";

highScore = 0;

numOfPlays = 0;

}

VideoGame(string n, int score, int num) {

name = n;

highScore = score;

numOfPlays = num;

}

VideoGame(string n) {

name = n;

highScore = 0;

numOfPlays = 0;

}

VideoGame(const VideoGame &p2)

{

name = p2.name;

highScore = p2.highScore;

numOfPlays = p2.numOfPlays;

}


void setName(string n) {

name = n;

}

void setHighScore(int score) {

highScore = score;

}

void setNumOfPlays(int num) {

numOfPlays = num;

}

string getName() {

return name;

}

int getHighScore() {

return highScore;

}

int getNumOfPlays() {

return numOfPlays;

}

};

string inputName() {

string n;

cout << "Enter name of video game: ";

getline(cin >> ws, n);

return n;

}

int inputHighScore() {

int score;

cout << "Enter current high score of game: ";

cin >> score;

return score;

}

int inputNumOfPlays() {

int num;

cout << "Enter number of times game is played: ";

cin >> num;

return num;

}

void output(VideoGame game) {


cout << game.getName() << endl

<< "Played " << game.getNumOfPlays() << " times (HIGH SCORE " << game.getHighScore() << ")" << endl;

}

int main() {

VideoGame game1, game2, game3("VideoGame 3");

game1.setName(inputName());

game1.setHighScore(inputHighScore());

game1.setNumOfPlays(inputNumOfPlays());


cout << "\nGame1" << endl;

output(game1);

cout << endl;

game2.setName(inputName());

game2.setHighScore(inputHighScore());

game2.setNumOfPlays(inputNumOfPlays());

cout << "\nGame2" << endl;

output(game2);

cout << "\nGame3" << endl;

output(game3);

VideoGame game4 = game2;

cout << "\nGame4" << endl;

output(game4);


return 0;

}

=============================================
SEE OUTPUT

====================================================

Thanks, let me know if you need more information. PLEASE COMMENT if there is any concern.

Know the answer?
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
Similar Questions
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
No matter what I do I cannot get this code to compile. I am using Visual...
No matter what I do I cannot get this code to compile. I am using Visual Studio 2015. Please help me because I must be doing something wrong. Here is the code just get it to compile please. Please provide a screenshot of the compiled code because I keep getting responses with just code and it still has errors when I copy it into VS 2015: #include <iostream> #include <conio.h> #include <stdio.h> #include <vector> using namespace std; class addressbook {...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath>...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath> using namespace std; void divisors(int num); int main () {    char repeat;    int num;       while (repeat !='n')    {        cout << "Enter a number: ";        cin >> num;        divisors(num);        cout << "Continue? (y or n): ";        cin >> repeat;    }    return 0; } void divisors(int num) {   ...
my code has several functions; delete and backward functions are not working, rewrite the code for...
my code has several functions; delete and backward functions are not working, rewrite the code for both functions and check them in the main: #include<iostream> #include<cassert> using namespace std; struct nodeType {    int info;    nodeType *link; }; class linkedList { public:    void initializeList();    bool isEmptyList();    void print();    int length();    void destroyList();    void insertFirst(int newItem);    void insertLast(int newItem);    int front();    linkedList();    void copyList(const linkedList otherList);    void insertNewValue(int value);...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any type dynamic arrays (replace string by the template in all instances below). • The class should have: – A private member variable called dynamicArray that references a dynamic array of type string. – A private member variable called size that holds the number of entries in the array. – A default constructor that sets the dynamic array to NULL and sets size to 0....
How to stop the program from exiting after display detail. When there is food detail, it...
How to stop the program from exiting after display detail. When there is food detail, it will display and exit the program. What can i do to make it not exit the program and back to main menu. #include <iostream> #include <iomanip> #include<string.h> using namespace std; struct food{ int order_id; string food_code,flavor,customer_id; string address,name; int weight,unit_price,qty,contact_number; struct food *next; };    class Foodsystem{ food *head,*temp,*temp2,*end; static int id;    public: Foodsystem(){ head=NULL;end=NULL;} void Place_Order(); void View_food_details(); void Modify_food_details(); void Delete_food_details();...
USING C++ Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1 Create your objects in the stack...
USING C++ Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1 Create your objects in the stack (not on the heap). Add a friend function, kilotopound, which will convert kilograms to pounds. Change your weight mutator to ask whether weight is input in kilograms or pounds. If it is kilograms, call the friend function kilotopound to convert it to pounds and return pounds. There are 2.2 pounds in one kilogram. Create an object on the stack with the following information:     ...
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double...
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double secondQuizz; double midTerm; double finalTerm; string name; }; int main() { int n; cout<<"enter the number of students"<<endl; cin>>n; struct student students[n]; int i; struct student istudent; for(i=0;i<n;i++) {    cout<<"Student name?"; cin >> istudent.name; cout<<"enter marks in first quizz , second quizz , mid term , final term of student "<<i+1<<endl; cin>>students[i].firstQuizz>>students[i].secondQuizz>>students[i].midTerm>>students[i].finalTerm; } for(i=0;i<n;i++) { double marks=0; double score=students[i].firstQuizz+students[i].secondQuizz+students[i].midTerm+students[i].finalTerm; marks=(students[i].firstQuizz*0.25)+(students[i].secondQuizz*0.25)+(students[i].midTerm*0.25)+(students[i].finalTerm*0.50); double totalArrgegateMarks =...
Complete the missing code for the constructors as indicated in the comments in all three header...
Complete the missing code for the constructors as indicated in the comments in all three header files. C++ mainDriver.cpp #include <string> #include "Address.h" #include "Date.h" #include "Person.h" using namespace std; int main() {    Person p1;    Person p2("Smith", "Bobby", "[email protected]", 111, "Main St", "Clemson",            "SC", 29630, 1, 31, 1998);    cout << endl << endl;    p1.printInfo();    p2.printInfo();    return 0; } Person.h #ifndef PERSON_H #define PERSON_H #include <iostream> #include <string> using namespace std; class...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT