Concept explainers
/*
Interface File: Movie.h
Declaration of Movie Class
(Variables - "Data Members" or "Attributes"
AND Functions - "Member Functions" or "Methods")
*/
#ifndef MOVIE_H // Include Guard or Header Guard -If already defined ignore rest of code
#define MOVIE_H // Otherwise, define MOVIE_H
#include<string>
// Note: Not "using namespace std;" or even "using std::string"
class Movie
{
private:
std::string title = ""; // Explict scope used --> std::string
int year = 0;
public:
Movie(std::string title = "", int year = 1888); // Declaring a Default Constructor
~Movie(); // A Destructor used for freeing up resources
void set_title(std::string title_param);
std::string get_title() const; // "const" safeguards class variable changes within function
std::string get_title_upper() const;
void set_year(int year_param);
int get_year() const;
}; // NOTICE: Class declaration ends with semicolon!
#endif // MOVIE_H
/*
Implementation file: Movie.cpp
Implements the functions declared in the interface file (Movie.h)
*/
#include <string>
#include "Movie.h"
// This code only needs "using" to enable the use of "string". Other programs would have a longer list here!
using std::string;
Movie::Movie(string title, int year) // Constructor definition
{
set_title(title);
set_year(year);
}
~Movie::Movie() // Destructor definition
{
CODE FOR FREEING UP RESOURCES
}
void Movie::set_title(string title_param)
{
title = title_param;
}
string Movie::get_title() const
{
return title;
}
string Movie::get_title_upper() const
{
string title_upper;
for (char c : title) {
title_upper.push_back(toupper(c));
}
return title_upper;
}
void Movie::set_year(int year_param)
{
year = year_param;
}
int Movie::get_year() const
{
return year;
}
/*
Main file: Movie_List.cpp
Utilizes Class Movie
*/
#include <iostream>
#include <iomanip>
#include <string>
#include <
#include "Movie.h"
// You need to replace "using namespace std;" with "using" declarations (see Movie.cpp as an example)
using namespace std; // Replace this with "using std::cout", etc.
int main()
{
cout << "The Movie List program\n\n"
<< "Enter a movie...\n\n";
// get vector of Movie objects
vector<Movie> movies;
char another = 'y';
while (tolower(another) == 'y')
{
Movie movie; // movie is initialized with the Default Constructor values
string title;
cout << "Title: ";
getline(cin, title);
movie.set_title(title);
int year;
cout << "Year: ";
cin >> year;
movie.set_year(year);
movies.push_back(movie);
cout << "\nEnter another movie? (y/n): ";
cin >> another;
cin.ignore();
cout << endl;
}
// display the movies
const int w = 10;
cout << left
<< setw(w * 3) << "TITLE"
<< setw(w) << "YEAR" << endl;
for (Movie movie : movies)
{
cout << setw(w * 3) << movie.get_title()
<< setw(w) << movie.get_year() << endl;
}
cout << endl;
// Output with titles in ALL CAPS
for (Movie movie : movies)
{
cout << setw(w * 3) << movie.get_title_upper()
<< setw(w) << movie.get_year() << endl;
}
cout << endl;
return 0;
}
Modify the code above to create a "Favorite Video Game List" program that is contained in three files:
- Game.h
- Game.cpp
- Game_List.cpp
You will need do to these things as you modify the code and put it into the three files:
- Create a class called "Game" (instead of "Movie") that contains 3 private variables ("title", "year", and "rating")
- The "year" is when the game first came out.
- The "rating" should be from 1 to 5 (5 being the best).
- Add the appropriate member functions of the class (setters and getters).
- Continue to use the get_title_upper() function as part of the class, Game, and in the output within the main file, Game_List.cpp.
-
- Add the Default Constructor and Destructor for the class with the member functions of the class.
- Don't forget to add the "include guard" to the .h file
- Use the scope resolution operator correctly for each file.
- Don't use the "using namespace std;" for the main file, Game_List.cpp.
- Instead, use the "using" declaration
- using std::cout;
- using std::endl;
- using std::string;
- etc.
- Instead, use the "using" declaration
Step by stepSolved in 4 steps with 6 images
- C++ complete magic Square #include <iostream> using namespace std; /*int f( int x, int y, int* p, int* q ){if ( y == 0 ){p = 0, q = 0;return 404; // status: Error 404}*p = x * y; // product*q = x / y; // quotient return 200; // status: OK 200} int main(){int p, q;int status = f(10, 2, &p, &q);if ( status == 404 ){cout << "[ERR] / by zero!" << endl;return 0;}cout << p << endl;cout << q << endl; return 0;}*/ /*struct F_Return{int p;int q;int status;}; F_Return f( int x, int y ){F_Return r;if ( y == 0 ){r.p = 0, r.q = 0;r.status = 404;return r;}r.p = x * y;r.q = x / y;r.status = 200;return r;} int main(){F_Return r = f(10, 0);if ( r.status == 404 ){cout << "[ERR] / by zero" << endl;return 0;}cout << r.p << endl;cout << r.q << endl;return 0;}*/ int sumByRow(int *m, int nrow, int ncol, int row){ int total = 0;for ( int j = 0; j < ncol; j++ ){total += m[row * ncol + j]; //m[row][j];}return total; } /*…arrow_forwardC++ This program does not compile! Spot the error and give the line number. Presume that the header file is error free and // Implementation file for the Rectangle class.1. #include "Rectangle.h" // Needed for the Rectangle class2. #include <iostream> // Needed for cout3. #include <cstdlib> // Needed for the exit function4. using namespace std; //***********************************************************// setWidth sets the value of the member variable width. *//*********************************************************** 5. void Rectangle::setWidth(double w){6. if (w >= 0)7. width = w;8. else{9. cout << "Invalid width\n";10. exit(EXIT_FAILURE);}} //***********************************************************// setLength sets the value of the member variable length. *//*********************************************************** 11. void Rectangle::setLength(double len){12. if (len >= 0)13. length = len;14. else{15. cout << "Invalid length\n";16.…arrow_forwardC++ Find the errors in the code for Date Class and Source.cpp program and fix them. source.cpp include <iostream>#include "Date.h" // include definition of class Date from Date.h using namespace std; // function main begins program executionint main(){Date date(); // create a Date object for May 6, 1981 // display the values of the three Date data members cout << "Month: " << date.getMonth() << endl;cout « "Day: " << date.getDay() << endl;cout << "Year: " << date.getYear(2017) << endl; cout << "\nOriginal date:" << endl;date = displayDate(); // output the Date// modify the Date setMonth(13);setDay(1);setYear(2005); cout "\nNew date:" << endl;date.displayDate(); // output the modified date } // end main Date.h // class Data definition#include <iostream>using namespace std; //Data constructor that initializes the three data members;class Date{publicdate(m, d, y){setMonth();setDay();setYear();};// set monthvoid…arrow_forward
- C++ Visual Studio 2019 NumDays, TimeOff, and Personnel Report Complete #4, 5 & 6 . Please submit just one file for the classes and main to test the classes. Just create the classes before main and submit only one cpp file. Do not create separate header files. See below code for NumDays class for you to use as a base. #include <iostream> using namespace std; class NumDays{private: double hours; double days;public: NumDays(double h = 0) { hours = h; days = h / 8; } void setHours(double h) { hours = h; days = h / 8; } void setDays(double d) { days = d; hours = d *8; } double getHours()const { return hours; } double getDays()const { return days; } //overloaded + operator NumDays operator+(NumDays& right) { NumDays temp; temp.setHours(hours + right.getHours()); return temp; } //overloaded - operator NumDays operator -(NumDays&…arrow_forwardC++ Coding Help (Operators: new delete) Assign pointer myGas with a new Gas object. Call myGas's Read() to read the object's fields. Then, call myGas's Print() to output the values of the fields. Finally, delete myGas. Ex: If the input is 14 45, then the output is: Gas's volume: 14 Gas's temperature: 45 Gas with volume 14 and temperature 45 is deallocated. #include <iostream>using namespace std; class Gas { public: Gas(); void Read(); void Print(); ~Gas(); private: int volume; int temperature;};Gas::Gas() { volume = 0; temperature = 0;}void Gas::Read() { cin >> volume; cin >> temperature;} void Gas::Print() { cout << "Gas's volume: " << volume << endl; cout << "Gas's temperature: " << temperature << endl;} Gas::~Gas() { // Covered in section on Destructors. cout << "Gas with volume " << volume << " and temperature " << temperature << " is deallocated."…arrow_forward#ifndef INT_SET_H#define INT_SET_H #include <iostream> class IntSet{public: static const int DEFAULT_CAPACITY = 1; IntSet(int initial_capacity = DEFAULT_CAPACITY); IntSet(const IntSet& src); ~IntSet(); IntSet& operator=(const IntSet& rhs); int size() const; bool isEmpty() const; bool contains(int anInt) const; bool isSubsetOf(const IntSet& otherIntSet) const; void DumpData(std::ostream& out) const; IntSet unionWith(const IntSet& otherIntSet) const; IntSet intersect(const IntSet& otherIntSet) const; IntSet subtract(const IntSet& otherIntSet) const; void reset(); bool add(int anInt); bool remove(int anInt); private: int* data; int capacity; int used; void resize(int new_capacity);}; bool operator==(const IntSet& is1, const IntSet& is2); #endifarrow_forward
- 10. When using a std::vector, what values do we expect to get from the size and empty member functions after calling the clear member function? Complete the table below with the expected values. member function value after donations.clear() donations.size() donations.empty()arrow_forwardC++ Define an "Expression" class that manages expression info: operand1 (integer), operand2 (integer), and the expression operator (char). It must provide at least the following method:- toString() to return a string containing all the expression info such as 50 + 50 = 100 Write a command-driven program named "ListExpressions" that will accept the following commands:add, listall, listbyoperator, listsummary, exit "add" command will read the expression and save it away in the list "listall" command will display all the expressions "listbyoperator" command will read in the operator and display only expressions with that given operator "listsummary" command will display the total number of expressions, the number of expressions for each operator, the largest and smallest expression values "exit" command will exit the program Requirements:- It must be using the array of pointers (not vector) to Expression objects to manage the list of Expression…arrow_forwardstruct gameType { string title; int numPlayers; bool online; }; gameType Awesome[50]; Write the C++ statements that print out all gameType fields from Awesome whose numPlayers is > 1.arrow_forward
- C++ Define an "Expression" class that manages expression info: operand1 (integer), operand2 (integer), and the expression operator (char). It must provide at least the following method:- toString() to return a string containing all the expression info such as 50 + 50 = 100 Write a command-driven program named "ListExpressions" that will accept the following commands:add, listall, listbyoperator, listsummary, exit "add" command will read in the expression and save it away in the list "listall" command will display all the expressions "listbyoperator" command will read in the operator and display only expressions with that given operator "listsummary" command will display the total number of expressions, the number of expressions for each operator, the largest and smallest expression values "exit" command will exit the program Requirements:- It must be using the vector object to manage the list of Expression objects. - There should be no global…arrow_forward#include <iostream>using namespace std; struct Person{ int weight ; int height;}; int main(){ Person fred; Person* ptr = &fred; fred.weight=190; fred.height=70; return 0;} What is a correct way to subtract 5 from fred's weight using the pointer variable 'ptr'?arrow_forwardPLEASE CODE IN PYTHON PLEASE USE NESTED CLASS FUNCTION Design a Point Class with attributes X and Y coordinates. The Class should have following functions: a) change the coordinates, b) return a 2 element list [x,y] c) print a Point object. d) return distance from this instance to a given [x,y] Also design a Line Class which has 2 Point attributes. The Line class should have functions for following behaviours: a) Return the length of the line. b) Print the equation of the line c) Find if this instance is equal in length to another line.arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY