SlideShare a Scribd company logo
1 of 33
GSP 125 Final Exam Guide
For more classes visit
www.snaptutorial.com
Question 1. 1. In addition to grouping functions together, a class also
groups (Points : 3)
libraries.
math operations.
print statements.
variables.
Question 2. 2. Hiding data in a class is also called (Points : 3)
encapsulation.
accessibility inversion.
confusion culling.
redirection.
Question 3. 3. The public members of a class (Points : 3)
can be changed after compiling, even functions.
must be accessed from an object of that class.
need a special interface to accessed from an object.
can only be accessed within member functions of that class.
Question 4. 4. Constructors are called (Points : 3)
whenever an object is created.
whenever a new line of code is typed.
only after math operations.
only after a work contract is defined.
Question 5. 5. Unions are (Points : 3)
defined just like structs, though their memory behaves differently.
a place to store multiple data types simultaneously.
a concept from the C language that is uncommon in C++.
All of the above
Question 6. 6. When objects contain other objects, it is called (Points : 3)
composition.
data blending.
subobjecting.
enclosures.
Question 7. 7. Using the sizeof operator, the compiler will provide the
size in bytes of a (Points : 3)
class or data type.
statically allocated array.
variable instance or object.
All of the above
Question 8. 8. When de-allocating arrays dynamically allocated with
new, _____ should be used to ensure proper de-allocation. (Points : 3)
destructor.
delete.
delete [].
free().
Question 9. 9. A pointer stores a(n) (Points : 3)
address.
variable.
value.
None of the above
Question 10. 10. The most common operator used when accessing
members of an object through a pointer is this. (Points : 3)
&
->
.
::
Question 11. 11. The following can be used to determine the number of
elements in a statically allocated array in C or C++. (Points : 3)
sizeof(arrayname)/sizeof(arrayname[0])
elementsof<arrayname>
arrayname.length()
None of the above
Question 12. 12. When returning by reference, (Points : 3)
the method can be used as an l-value.
other functions cannot use the result as a parameter.
C-style code must be capitalized, as per standard convention.
There is no such thing as returning by reference.
Question 13. 13. Overloaded methods in a class must use (Points : 3)
the exact same argument types, but different return types.
the exact same name.
default arguments.
None of the above
Question 14. 14. The copy constructor takes (Points : 3)
no arguments.
a single argument by reference.
a single argument by value.
any number of arguments.
Question 15. 15. A shallow copy is dangerous because (Points : 3)
it has a knife and is very clumsy.
it may cause bad de-allocation in a properly written destructor in a
class that allocates memory.
it prevents recursive methods from being called by using significant
amounts of stack space.
None of the above
Question 16. 16. When using inheritance, the class that is doing the
inheriting is called a (Points : 3)
subclass.
child class.
derived class.
All of the above
Question 17. 17. A UML class diagram is commonly used to (Points : 3)
exactly describe code before writing it.
help programmers explain design to other programmers.
define code standards (for syntax) for programming teams.
All of the above
Question 18. 18. Downcasting is considered safe because (Points : 3)
the compiler is very smart about types.
it is safe to assume a parent can do everything a child can do.
downcasting can only be done on upcasted objects.
downcasting is not considered safe.
Question 19. 19. If unsure whether to use inheritance or composition,
use (Points : 3)
inheritance, because it saves the most typing.
inheritance, because C++ supports multiple inheritance.
composition, because it gives programmers the most options.
composition, because it is more efficient than inheritance.
Question 20. 20. Creating classes in separate .h and .cpp files is good
because (Points : 3)
moving code to separate files is good design (separation of
concerns).
separating declaration from definition allows decoupling of
dependencies.
many smaller files are easier to maintain by teams of programmers.
All of the above
Question 21. 21. When using the virtual keyword, C++ can detect the
type of an object by using (Points : 3)
Compile Time Type Information.
dynamic_cast.
a "constructor inference" pattern.
C++ does not support any kind of reflection.
Question 22. 22. Passing pointers by reference (e.g., "(int * & arg)") is
possible but limited, because (Points : 3)
NULL cannot be passed as a valid pointer by reference.
a raw address (&variable) cannot be passed as a valid pointer by
reference.
r-values cannot be passed as pointers by reference.
All of the above
Question 23. 23. Stack memory is where (Points : 3)
global variables and raw machine code are stored.
local variables and execution of instructions are kept track of.
dynamic memory is allocated to.
None of the above
Question 24. 24. A compiler will put sentinel values into memory to
(Points : 3)
help detect array out-of-bound errors.
keep track of how many times a function recurses.
stop bad functions from being executed.
prevent memory leaks.
Question 25. 25. Virtual functions have a cost when compared to normal
(statically bound) functions; specifically, they are (Points : 3)
slower and less optimizable.
less dynamic.
unusable with polymorphism.
more difficult to read than extern or static functions.
Question 26. 26. In C++, the diamond problem that results from multiple
inheritance can be solved by (Points : 3)
extern inheritance.
static inheritance.
virtual inheritance.
inline inheritance.
Question 27. 27. Test-driven development is (Points : 3)
writing software after finishing multiple choice exams about
software quality.
writing many small tests that initially fail, and working on each test
until all succeed.
another name for object-oriented programming.
All of the above
Question 28. 28. Which piece of the C/C++ compile tool chain arranges
compiled code into the final executable? (Points : 3)
Preprocessor
Compiler
Linker
Debugger
Question 29. 29. For C-style error codes to be used effectively, a
programmer should (Points : 3)
always do logic on function returns to test success.
check errno after potentially failed operations to see if any errors
occurred.
read documentation to make sense of error codes.
All of the above
Question 30. 30. A class template allows (Points : 3)
a class to be re-defined with different types but the same code.
the compiler to ignore unused methods of the templated class.
the templated type to be any type, including another templated type.
All of the above
Question 31. 31. Write a “Hello World” program in C++. (Points : 2)
Question 32. 32. Write code for a struct called “Coin.” The Coin class
should have a floating-point member for radius and thickness and
weight, a c-string member for name, and an integer member for color.
(Points : 7)
Question 33. 33. Write code for a class called "Double." The Double
class should have a single double member, value. Create accessors and
mutators for value. The default constructor of Double should set value to
zero. (Points : 7)
Question 34. 34. Write a class named Person and create another class
called Teacher, which inherits from Person (Person is the parent class
and Teacher is the child class). (Points : 7)
Question 35. 35. Write code that instantiates an integer and prints out its
address. (Points : 7)
Question 36. 36. Write the body of thfollowing function so that it returns
the square of the number pointed at by the pointer argument.
float square(float * valuePtr)
{
} (Points : 7)
Question 37. 37. Consider the following class.
class ManagedArray {
public:
float * data;
int size;
ManagedArray():data(0),size(0){}
void setSize(int a_size){ size = a_size; data = new float[size]; }
};
Write a destructor for this class to de-allocate any memory it may have
allocated. (Points : 7)
Question 38. 38. Write code that dynamically allocates a two-
dimensional array of integers called map, 5 high, and 7 wide. Then, de-
allocate the two-dimensional array. (Points : 7)
Question 39. 39. Write code that allocates an integer on the stack and
allocates another integer array on the heap. (Points : 7)
Question 40.
40. Write an abstract base class called LivingThing that has the
following methods: breathe and eat. (Points : 7)
********************************************************
GSP 125 Midterm Exam
For more classes visit
www.snaptutorial.com
1. Accidentally inheriting from the same class twice causes terrible
ambiguity, and is known as (Points : 2)
inheritance overload.
the dreaded diamond of death.
Von Neumann bottleneck.
There is nothing wrong with inheriting the same class more than
once.
Question 2. 2. Creating classes in separate .h and .cpp files is good
because (Points : 2)
moving code to separate files is good design (separation of
concerns).
separating declaration from definition allows de-coupling of
dependencies.
many smaller files are easier to maintain by teams of programmers.
All of the above
Question 3. 3. Virtual methods are resolved at runtime by using a (Points
: 2)
dynamic list.
virtual table.
vector.
haystack.
Question 4. 4. Allowing many different types to be treated in the same
way is called (Points : 2)
polymorphism.
multitypecasting.
deep-copy.
virtual.
Question 5. 5. Heap memory is where (Points : 2)
global variables and raw machine code are stored.
local variables and execution of instructions is kept track of.
dynamic memory is allocated to.
None of the above
Question 6. 6. Memory leaks in a computer program are (Points : 2)
not a big deal because operating systems clean up all program
memory.
easy to find and debug in C and C++.
difficult and important to manage in C and C++.
a problem in every programming language.
Question 7. 7. Virtual functions have a cost when compared to normal
(statically bound) functions; specifically, they are (Points : 2)
slower and less optimizable.
less dynamic.
unusable with polymorphism.
more difficult to read than extern or static functions.
Question 8. 8. The explicit keyword (Points : 2)
labels data as being volatile.
prevents constructors from automatically being called by implicit
typecasting.
marks a method as an override of a polymorphic base.
identifies a variable that can be referenced but is defined in another
compilation unit.
Question 9. 9. Preprocessor macros (Points : 2)
should be avoided if other langauge features will work just as well.
can easily confuse other progammers not familiar with your macro.
should be undefined after use to avoid polluting the global
namespace.
All of the above
Question 10.10. Which piece of the C/C++ compile tool chain arranges
compiled code into the final executable? (Points : 2)
Preprocessor
Compiler
Linker
Debugger
********************************************************
GSP 125 Week 1 iLab Simple game
For more classes visit
www.snaptutorial.com
GSP 125 GSP125 GSP 125 Week 1 iLab
//
//
// INSTRUCTIONS
-----------Compile this code. You should see a happy-face character on a
field of
periods. You can move the character with the 'w', 'a', 's', and 'd' keys.
Read through this code! Try to understand it before starting the
assignment.
Comment confusing lines with what you think code is doing, and
experiment
with existing code to test your understanding.
Once you feel comfortable with this code, accomplish each of the
following,
and make sure your code compiles and runs after each step is completed.
1) Object Oriented Refactoring
a) Write a class called Entity to store two public integers named x and y,
and a char named icon (the player data).
b) Remove x, y, and icon (the player data) from main(), create an
instance
of the Entity class (named whatever you like) in main(), and use its
members as replacements for the x, y, and icon variables that were
removed.
c) Write a parameterized constructor for the Entity class that sets x, y,
and icon, and use it when creating the instance.
d) Make x, y, and icon private variables of Entity, and create Accessor
and Mutator (or Getter and Setter) functions to use them in main().
(hint: &quot;player.x++&quot; could be
&quot;player.setX(player.getX()+1);&quot; )
e) Write a struct called Vector2, which has two int variables, x and y.
f) Write a default constructor for Vector2, which sets x and y to 0.
g) Write a parameterized constructor for Vector2, which sets x and y.
h) Remove x, and y from Entity, add an instance of the Vector2 structure
named &quot;pos&quot; to the Entity class, and use pos's members as
replacements
for the x, and y variables that were removed.
i) Remove height and width (in the game data) from main(), create an
instance of the Vector2 structure named &quot;size&quot;, and use
size's x member
as a replacement for width, and size's y member as a replacement for
height.
j) Write a method in Vector2 with the signature
&quot;bool is(int a_x, int a_y)&quot;. &quot;is&quot; should return true
if a_x is equal to
that instance's x, and a_y is equal that instance's y.
k) Instantiate a new object of class Vector2 called
&quot;winPosition&quot;, and set
it's x, y value to size.x/2, size.y/2.
2) Add Game Logic
a) Add code to the while-loop so that when the player reaches
&quot;winPosition&quot;, which should be determined by using the
&quot;is&quot; method, the
&quot;state&quot; variable should be set to WIN, ending the game.
b) Add code to the while-loop so that the state variable is set to to LOST
if the player leaves the play field (ending the game).
3) Using enums
a) Create an enum called &quot;GameState&quot; with the possible
values &quot;RUNNING&quot;,
&quot;WIN&quot;, &quot;LOST&quot;, and
&quot;USER_QUIT&quot;.
b) Replace the state variable with an isntance of the GameState enum. //
lab1: simplegame_OOP
// &lt;insert your name here&gt;
// read main.cpp, and follow the instructions at the bottom of main.cpp
#include &lt;iostream&gt; // std::cout using namespace std;
#include &lt;windows.h&gt;
#include &lt;conio.h&gt; //
SetConsoleCursorPosition(HANDLE,COORD)
// _getch() struct Vector2 {
int x;
int y;
Vector2() :
x(0), y(0) {
}
Vector2(int x, int y) {
x = x;
y = y;
}
bool is(int a_x, int a_y) {
if (a_x == x &amp;&amp; a_y == y) {
return true;
}
} return false; };
class Entity {
public:
Entity(int x, int y, char i) {
pos.x = x;
pos.y = y;
icon = i;
}
void setX(int x) {
pos.x = x;
}
int getX() {
pos.x;
}
void setY(int y) {
pos.y = y;
} int getY() {
pos.y;
}
void setIcon(char i) {
icon = i;
}
char getIcon() {
icon;
}
private:
Vector2 pos;
char icon;
};
enum GameState {
RUNNING, WIN, LOST, USER_QUIT
}; /**
* moves the console cursor to the given x/y coordinate
* @param x
* @param y
*/
void moveCursor(int x, int y)
{
COORD c = { x,y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),
c);
}
int main()
{
// player data
Entity e(3, 4, 1); // game data
GameState state = RUNNING;
int input;
Vector2 size(20, 15);
Vector2 winPosition(size.x / 2, size.y / 2);
do
{ // draw the game world
moveCursor(0, 0);
for (int row = 0; row &lt; size.x; row++)
{
for (int col = 0; col &lt; size.y; col++)
{
cout &lt;&lt; '.';
} cout &lt;&lt; 'n';
}
// draw the player
moveCursor(e.getX(), e.getY());
cout &lt;&lt; e.getIcon();
// get input from the user (wait for one key press)
input = _getch();
// process input from the user
switch (input)
{
case 'w':
e.setY(e.getY() - 1);
break; // move up
case 'a':
e.setX(e.getX() - 1); break; // move left
case 's':
e.setY(e.getY() + 1); break; // move down
case 'd':
e.setX(e.getX() + 1); break; // move right
case 27:
state = USER_QUIT; break; // quit
}
// show the game state message
moveCursor(0, size.y + 1);
switch (state)
{
case WIN:
cout &lt;&lt; &quot;You WON! Congratulations!n&quot;;
break;
case LOST:
cout &lt;&lt; &quot;You lost...n&quot;;
break;
}
if (winPosition.is(e.getX(), e.getY()))
{
state = WIN;
}
else
{
state = LOST;
}
} while (state == RUNNING); }; // user must press ESCAPE before
closing the program
cout &lt;&lt; &quot;press ESCAPE to quitn&quot;;
while (_getch() != 27);
return 0;
********************************************************
GSP 125 Week 2 ILab Rectangles
For more classes visit
www.snaptutorial.com
/ lab2: rectangles
// &lt;insert your name here&gt;
// read main.cpp, and follow the instructions at the bottom of main.cpp
#define NOMINMAX // prevent Windows API from conflicting with
&quot;min&quot; and &quot;max&quot;
#include &lt;stdio.h&gt; // C-style output. printf(char*,...), putchar(int)
#include &lt;windows.h&gt; //
SetConsoleCursorPosition(HANDLE,COORD)
#include &lt;conio.h&gt; // _getch()
/**
* moves the console cursor to the given x/y coordinate
* 0, 0 is the upper-left hand coordinate. Standard consoles are 80x24.
* @param x
* @param y
*/
void moveCursor(int x, int y)
{
COORD c = {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),
c);
}
struct Vec2
{
short x, y;
Vec2() : x(0), y(0) { }
Vec2(int x, int y) : x(x), y(y) { }
void add(Vec2 v)
{
x += v.x;
y += v.y;
}
};
class Rect
{
Vec2 min, max;
public:
Rect(int minx, int miny, int maxx, int maxy)
:min(minx,miny),max(maxx,maxy)
{}
Rect(){}
void draw(const char letter) const
{
for(int row = min.y; row &lt; max.y; row++)
{
for(int col = min.x; col &lt; max.x; col++)
{
if(row &gt;= 0 &amp;&amp; col &gt;= 0)
{
moveCursor(col, row);
putchar(letter);
}
}
}
}
bool isOverlapping(Rect const &amp; r) const
{ return !( min.x &gt;= r.max.x || max.x &lt;= r.min.x
|| min.y &gt;= r.max.y || max.y &lt;= r.min.y); }; }
void translate(Vec2 const &amp; delta)
{
min.add(delta);
max.add(delta);
} int main()
{
// initialization
Rect userRect(7, 5, 10, 9);
Rect rect0(10, 2, 14, 4);
Rect rect1(1, 6, 5, 15);
int userInput;
do
{
// draw
rect0.draw('0');
rect1.draw('1');
moveCursor(0, 0);
// re-print instructions
printf(&quot;move with 'w', 'a', 's', and 'd'&quot;);
userRect.draw('#');
// user input
userInput = _getch();
// update
Vec2 move;
switch(userInput)
{
case 'w':
move = Vec2( 0,-1); break;
case 'a':
********************************************************
GSP 125 Week 3 iLab List of Numbers
For more classes visit
www.snaptutorial.com
GSP 125 GSP/125 GSP 125 Week 3 iLab
// lab3: listofnumbers
// &lt;insert your name here&gt;
// read main.cpp, and follow the instructions at the bottom of main.cpp
#include &lt;iostream&gt;
using namespace std;
int main()
{
int numberOfElements = 0;
float * elements = NULL;
float userInput;
bool addingNumbersToTheList;
cout &lt;&lt; &quot;Keep entering numbers. Enter a non-number to
stop.&quot; &lt;&lt; endl;
do
{
cin &gt;&gt; userInput;
addingNumbersToTheList = !std::cin.fail();
if(addingNumbersToTheList) {
// make a bigger array to replace the old one
float * biggerArray = new float[numberOfElements+1];
if(elements != NULL)
{
// copy the old elements into the biggerArray
for(int i = 0; i &lt; numberOfElements; i++)
{
biggerArray[i] = elements[i];
}
// the old array is not needed anymore, we have a better copy
delete elements;
}
// point at the new array
elements = biggerArray;
numberOfElements = numberOfElements+1;
// put the new number into the last element of the array
elements[numberOfElements-1] = userInput; }
}
while(addingNumbersToTheList); // fix cin after intentionally breaking
it above.
if(std::cin.fail())
{
std::cin.clear();
while(std::cin.get() != 'n');
}
bool hasNumbers = numberOfElements &gt; 0;
if(hasNumbers) {
// print the stored numbers
cout &lt;&lt; &quot;Entered numbers: &quot; &lt;&lt; endl;
cout &lt;&lt; &quot;{&quot;;
for(int i = 0; i &lt; numberOfElements; ++i)
{
if(i &gt; 0)
{
cout &lt;&lt; &quot;, &quot;;
}
cout &lt;&lt; elements[i]; }
cout &lt;&lt; &quot;}&quot; &lt;&lt; endl; }
else
{ } float sum = 0;
for(int i = 0; i &lt; numberOfElements; ++i)
{
sum += elements[i];
}
cout &lt;&lt; &quot;total: &quot; &lt;&lt; sum &lt;&lt; endl;
cout &lt;&lt; &quot;average: &quot; &lt;&lt; (sum /
numberOfElements) &lt;&lt; endl; cout &lt;&lt; &quot;no numbers
entered.&quot; &lt;&lt; endl;
}
return 0; // INSTRUCTIONS //
//
//
// -----------Compile this code. You should be able to enter any number
of numbers into
the console, but as soon as you enter a non-number, a list of every
number
you typed should display.
Read through this code! Try to understand it before starting the
assignment.
Comment confusing lines with what you think code is doing, and
experiment
with existing code to test your understanding.
Once you feel comfortable with this code, accomplish each of the
following,
and make sure your code compiles and runs after each step is completed.
1) The ManagedArray class
a) Create a new class called ManagedArray. It should have a float
pointer
named &quot;elements&quot; to reference an array of floats, and an
integer named
&quot;numberOfElements&quot; to keep track of how many floats are
in the array.
b) Create a default constructor, which sets &quot;elements&quot; to
NULL, and
&quot;numberOfElements&quot; to 0.
c) Create an accessor for the ManagedArray class called
&quot;int ManagedArray::size()&quot;, which returns the number of
elements
d) Create an accessor for the ManagedArray class called
&quot;float ManagedArray::get(int index)&quot;, which returns the
value, in
&quot;elements&quot;, at the given index.
e) Create a member function for ManagedArray called
&quot;void ManagedArray::add(float value)&quot;, which allocates a
larger array
than &quot;elements&quot;, and replaces &quot;elements&quot; with it,
adding 'value' to the
end of it. This method should also increase
&quot;numberOfElements&quot;. See the
code within the &quot;if(addingNumbersToTheList) {&quot; block.
2) Use ManagedArray
a) Remove the &quot;elements&quot; and
&quot;numberOfElements&quot; variables in main, and use
a ManagedArray object to get the same functionality that was in main.
3) Destructor and Copy Constructor
a) Create a destructor (named
&quot;ManagedArray::~ManagedArray()&quot;), which
deletes (with &quot;delete &quot;) the &quot;elements&quot; array.
b) Create a copy-constructor (named
&quot;ManagedArray::ManagedArray(ManagedArray &amp;
ma)&quot;), which copies the
&quot;numberOfElements&quot; variable from &quot;ma&quot;, and
allocates an &quot;elements&quot;
array the same size, with data copied from &quot;ma&quot;.
4) Print Function
a) Create a new function called &quot;void print(ManagedArray
ma)&quot;, which
prints the given array, just like the code within the
&quot;if(hasNumbers) {&quot; block.
b) Use the print function to print out a ManagedArray at the end of your
program.
c) Use the print function to print out a ManagedArray a second time.
This
will crash your program if you wrote your destructor correctly but
*did not* write your copy constructor correctly. If the program does
not crash, comment out your copy constructor, recompile and try again,
********************************************************
GSP 125 Week 4 iLab Simple Game inheritance
For more classes visit
www.snaptutorial.com
GSP 125 GSP/125 GSP 125 Week 4 iLab
//
//
//
//
//
//
// INSTRUCTIONS
-----------Compile this code. You should see a rectangular play field of
periods, with
3 Entity objects visible on it. The happy-face Entity moves with the
&quot;wasd&quot;
keys, and the club Entity moves with the &quot;ijkl&quot; keys. If the
happy-face
reaches the diamond Entity, the player wins. If the happy-face reaches
the
club, the player loses.
Read through this code! Try to understand it before starting the
assignment.
Comment confusing lines with what you think code is doing, and
experiment
with existing code to test your understanding.
Once you feel comfortable with this code, accomplish each of the
following,
and make sure your code compiles and runs after each step is completed.
1) Getting comfortable with the game code
a) Implement initialization lists in Vector2, Entity, and Game (setting
object values after a ':', between the constructor signature and body).
Have initialization lists set initial values for each member variable.
b) Add another Entity to the game that isn't the same location as an
existing Entity. Use a heart icon (ASCII code 3). It should display in
the game.
c) Add logic that makes the club (PLAYER2) win the game if that
player
reaches the heart Entity. You may want to make new constants, like
GOAL2, and WIN2, to follow the existing code convention.
d) Make a new private function called &quot;void
Game::handleUserInput()&quot;, move
the user input handling logic from Game::update() into this new
function, and call Game::handleUserInput from Game::update.
e) Add whitespace to the handleUserInput logic, and comment each line
with
what you understand it is doing. If you don't understand what the code
is doing, experiment with it until you do! Do things like printing
variables you are unsure about, and guess what output will look like.
f) Implement the prototyped overloaded operators for Vector2. Once
they
are finished you should be able to use the alternate code for setting
up PLAYER2 in Game::Game() in &quot;game.cpp&quot;.
2) A &quot;BlinkEntity&quot; class
a) Create 2 new files in your project: &quot;blinkentity.h&quot;, and
&quot;blinkentity.cpp&quot;
b) Make a BlinkEntity class that extends Entity. Declare the class in
&quot;blinkentity.h&quot; and define it's methods in
&quot;blinkentity.cpp&quot;. Your
&quot;blinkentity.h&quot; file should look something like:
#pragma once
#include &quot;entity.h&quot;
class BlinkEntity : public Entity {
};
c) Instead of using an Entity for the Entity marked GOAL1 in the Game
constructor, use a BlinkEntity. You will need to create a public
BlinkEntity constructor.
d) Give BlinkEntity another member variable called
&quot;alternateIcon&quot;. When
BlinkEntity calls it's update function, swap the values of
&quot;icon&quot; and
&quot;alternateIcon&quot;. You won't notice a change during runtime
until you add
the virtual modifier to Entity::update().
3) A &quot;WanderingEntity&quot; class
a) Create 2 new files in your project: &quot;wanderingentity.h&quot;,
and
&quot;wanderingentity.cpp&quot;
b) Make a WanderingEntity class that extends Entity. Declare the class
in
&quot;wanderingentity.h&quot; and define it's methods in
&quot;wanderingentity.cpp&quot;. //
Your &quot;wanderingentity.h&quot; file should look something like:
//
#pragma once
//
//
#include &quot;entity.h&quot;
//
//
class WanderingEntity : public Entity {
//
};
// c) Instead of using an Entity for the Entity marked PLAYER2 in the
Game
//
constructor, use a WanderingEntity. You will need to create a public
//
WanderingEntity constructor.
// d) Create a new update method for WanderingEntity. Declare it in
//
&quot;wanderingentity.h&quot;, and define it in
&quot;wanderingentity.cpp&quot;. In the
//
WanderingEntity::update() method, set the
&quot;howToMoveNext&quot; variable
//
to a random number from 0 to 3. You can use &quot;rand() % 4&quot;
to do this in
//
&quot;wanderingentity.cpp&quot; if you #include &lt;cstdlib&gt; or
&lt;stdlib.h&gt;. After
//
setting the &quot;howToMoveNext&quot; variable in update, call the
parent class's
//
updated with &quot;Entity::update()&quot;.
// e) Add at least 2 more WanderingEntity objects in the Game. Add
game logic
//
will cause the player to lose if the player shares a location with any
//
WanderingEntity object.
********************************************************
GSP 125 Week 5 iLab Shapes
For more classes visit
www.snaptutorial.com
GSP 125 GSP/125 GSP 125 Week 5 iLab
// INSTRUCTIONS
// ------------
// Compile this code. After pressing any key to clear the instructions,
You
// should see three rectangles labeled '#', 'b', and 'c'. You should also see
// two triangles, labeled 'd' and 'e'. Pressing '>' and '<' will change which
// shape is labeled '#'. Pressing 'w', 'a', 's', and 'd' will move the shape
// labeled '#'. Pressing 'space' will randomize the selected shape.
//
// Read through this code! Try to understand it before starting the
assignment.
// Comment confusing lines with what you think code is doing, and
experiment
// with existing code to test your understanding.
// Once you feel comfortable with this code, accomplish each of the
following,
// and make sure your code compiles and runs after each step is
completed.
//
// 1. Getting comfortable with the code
// a) Create a "makeRandom" method in both the Rect and Tri classes,
based
// on the "makeRandomRect" and "makeRandomTri" functions in
// "application.cpp". The makeRandom function should take no
parameters,
// and instead make itself random. Removing the old
"makeRandomRect"
// and "makeRandomTri" functions as well. Be sure to consider what to
do
// about "screenMin" and "screenMax".
// b) Create a print method for the Tri class, similar to the print method
// for the Rect class. This method may come in very handy when
debugging.
// 2. Create Shape base class
// a) Create a header file (without a .cpp file) for a Shape class.
// b) Create the Shape class, which should have no member variables.
// c) Make the Shape class an interface for the Rect and Tri classes.
Shape
// should have pure-virtual methods for each method that Rect and Tri
have
// in common.
// d) Make sure Shape has a virtual destructor with an empty body.
// 3. Make Rect and Triangle extend Shape
// 4. Change selected
// a) Change the type of "Application::selected" from "void *" to "Shape
*".
// b) Every piece of code that typecasts "selected" (and the logic around
it)
// can be removed now. Simply call functions using the "Shape"
interface.
// c) Remove the "selectedType" variable from Application. Logic that
needs
// some form of RunTime Type Information should use dynamic_cast
instead.
// 5. Merge all Shape objects into a single array
// a) Create an array of Shape pointers in the Application called
"shapes".
// b) Making a complementary NUM_SHAPES variable would make
sense.
// b) Remove "rectangles" and "triangles" arrays.
// c) Put each Tri and Rect object managed by the Application class into
// the "shapes" array. This will require re-factoring in multiple files.
// While removing references to "rectangles" and "triangles" arrays, it
// may make sense to replace pairs of for-loops using each of the old
// arrays with a single for-loop using just "shapes".
// 6. Make "shapes" dynamic
// a) Give Application::init() 2 parameters: int numRect, int numTri
// b) Make "shapes" a pointer of type "Shape **", and allocate it to be
// "numShapes" big, where "numShapes" is an int member of
Application
// equal to (numRect + numTri), defined in Application::init().
// c) When calling "app.init()" in main, pass valid arguments for
numRect
// and numTri.
// d) De-allocate the "shapes" array in Application::Release().
// 7. Clean up old variables
// a) Remove the TYPE_RECT and TYPE_TRI variables from
Application.
// b) Remove NUM_TRI and NUM_RECT, and any NUM_SHAPES
variable as well. Use
// numShapes where needed.
// 8. Add Circle class
// a) Create a header file AND a source file for a Circle class.
// b) Use Rect and Tri as examples to create the Circle class with.
// c) A Circle class should have at least a 2 dimensional position, and a
// radius.
// d) A simple algorithm for drawing a Circle will be similar to drawing
a
// Rect or Tri, thought it might include the following code:
// float dx = center.x - col, dy = center.y - row;
// if( dx*dx + dy*dy <= radius * radius ) {
// moveCursor(col, row);
// putchar(letter);
// }
// e) Add an additional parameter to Application::init(), "int
numCircles".
// Implement init to generate Circle objects along with Rect and Tri
// objects.
// 9. Implement add/remove for the shapes array
// a) Add code that increases the size of the shapes array, adding a
random
// shape, whenever the '=' or '+' key is pressed. Take a look at the week
// 5 lecture showing explicit constructors for help with this algorithm.
// a) Add code that decreases the size of the shapes array, removing the
last
// shape, whenever the '-' or '_' key is pressed. End the program when the
// last shape is removed. Removing a shape, like adding a shape, can be
// done by allocating an array of a different size (smaller this time).
********************************************************
GSP 125 Week 7 iLab GSP 124 Week 7 iLab
win32game
For more classes visit
www.snaptutorial.com
GSP 125 GSP/125 GSP 125 Week 7 iLab
Looking for help with C++ lab, please see attached zip, inside main.cpp
are directions:
// 1) Replace Vector2 and Coordinate
// a) Create a new Vec2 class as a replacement for both Vector2 and
// Coordinate. Vec2 must be a templated class, so that it stores and
// manipulates X and Y values of a templated type. It may be helpful to
// start with the Vector2 class, add "template" to the
// header, and replace (Ctrl+H) each instance of "float" with "TYPE",
and
// "Vector2" with "Vec2".
// b) Remember, a templated class must have all method definitions in
the
// same file as the templated class declaration. Also remember that
method
// definitions outside of a templated class' declaration need a
// "template" header, and a "" appended to the class
// name with the scope resolution operator (e.g.:
// "void Vec2::limitMagnitude(TYPE max) {/* method body */}").
// c) Replace the use of Vector2 with Vec2.
// d) Replace the use of Coordinate with Vec2.
// 2) More Game Goals
// a) Instead of having a single goal for the player, create at least 3
// randomly placed goals for the player. Use a "std::vector"
// object (from the Standard Template Library) named "goals" to store
the
// goals.
// c) Whenever the user clicks in the game window, the game should
create
// another goal object for the player to get, and add it to the
// "std::vector goals" object.
// d) Each retrieved goal should be removed from the game after being
// retrieved by the player. A "You Win!" message should display when
the
// player retrieves all goals.
********************************************************

More Related Content

What's hot

GSP 125 Entire Course NEW
GSP 125 Entire Course NEWGSP 125 Entire Course NEW
GSP 125 Entire Course NEWshyamuopten
 
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12chinthala Vijaya Kumar
 
GVKCV Computer Science(083) Pre board sample paper 2 Class 12 (20-21) with so...
GVKCV Computer Science(083) Pre board sample paper 2 Class 12 (20-21) with so...GVKCV Computer Science(083) Pre board sample paper 2 Class 12 (20-21) with so...
GVKCV Computer Science(083) Pre board sample paper 2 Class 12 (20-21) with so...chinthala Vijaya Kumar
 
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21chinthala Vijaya Kumar
 
DAC CCAT GUESS PAPER Jun-Jul 2013
DAC CCAT GUESS PAPER Jun-Jul 2013 DAC CCAT GUESS PAPER Jun-Jul 2013
DAC CCAT GUESS PAPER Jun-Jul 2013 prabhatjon
 
Extension methods, nulls, namespaces and precedence in c#
Extension methods, nulls, namespaces and precedence in c#Extension methods, nulls, namespaces and precedence in c#
Extension methods, nulls, namespaces and precedence in c#Paul Houle
 
Extension methods, nulls, namespaces and precedence in c#
Extension methods, nulls, namespaces and precedence in c#Extension methods, nulls, namespaces and precedence in c#
Extension methods, nulls, namespaces and precedence in c#Paul Houle
 

What's hot (9)

GSP 125 Entire Course NEW
GSP 125 Entire Course NEWGSP 125 Entire Course NEW
GSP 125 Entire Course NEW
 
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
 
GVKCV Computer Science(083) Pre board sample paper 2 Class 12 (20-21) with so...
GVKCV Computer Science(083) Pre board sample paper 2 Class 12 (20-21) with so...GVKCV Computer Science(083) Pre board sample paper 2 Class 12 (20-21) with so...
GVKCV Computer Science(083) Pre board sample paper 2 Class 12 (20-21) with so...
 
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
 
Java execise
Java execiseJava execise
Java execise
 
DAC CCAT GUESS PAPER Jun-Jul 2013
DAC CCAT GUESS PAPER Jun-Jul 2013 DAC CCAT GUESS PAPER Jun-Jul 2013
DAC CCAT GUESS PAPER Jun-Jul 2013
 
Extension methods, nulls, namespaces and precedence in c#
Extension methods, nulls, namespaces and precedence in c#Extension methods, nulls, namespaces and precedence in c#
Extension methods, nulls, namespaces and precedence in c#
 
Oops Paper
Oops PaperOops Paper
Oops Paper
 
Extension methods, nulls, namespaces and precedence in c#
Extension methods, nulls, namespaces and precedence in c#Extension methods, nulls, namespaces and precedence in c#
Extension methods, nulls, namespaces and precedence in c#
 

Similar to Gsp 125 Enthusiastic Study / snaptutorial.com

GSP 125 Perfect Education/newtonhelp.com
GSP 125 Perfect Education/newtonhelp.comGSP 125 Perfect Education/newtonhelp.com
GSP 125 Perfect Education/newtonhelp.combellflower169
 
GSP 125 Become Exceptional/newtonhelp.com
GSP 125 Become Exceptional/newtonhelp.comGSP 125 Become Exceptional/newtonhelp.com
GSP 125 Become Exceptional/newtonhelp.combellflower148
 
GSP 125 Doing by learn/newtonhelp.com
GSP 125 Doing by learn/newtonhelp.comGSP 125 Doing by learn/newtonhelp.com
GSP 125 Doing by learn/newtonhelp.combellflower126
 
Uop gsp 125 final exam guide new
Uop gsp 125 final exam guide newUop gsp 125 final exam guide new
Uop gsp 125 final exam guide newElijahEthaan
 
SE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUSSE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUSnikshaikh786
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guidekrtioplal
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docxrosemarybdodson23141
 
Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#Umar Farooq
 
Devry CIS 247 Full Course Latest
Devry CIS 247 Full Course LatestDevry CIS 247 Full Course Latest
Devry CIS 247 Full Course LatestAtifkhilji
 
C# (This keyword, Properties, Inheritance, Base Keyword)
C# (This keyword, Properties, Inheritance, Base Keyword)C# (This keyword, Properties, Inheritance, Base Keyword)
C# (This keyword, Properties, Inheritance, Base Keyword)Umar Farooq
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritanceharshaltambe
 
17432 object oriented programming
17432   object oriented programming17432   object oriented programming
17432 object oriented programmingsoni_nits
 
Getting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingGetting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingHock Leng PUAH
 
SPF Getting Started - Console Program
SPF Getting Started - Console ProgramSPF Getting Started - Console Program
SPF Getting Started - Console ProgramHock Leng PUAH
 

Similar to Gsp 125 Enthusiastic Study / snaptutorial.com (20)

GSP 125 Perfect Education/newtonhelp.com
GSP 125 Perfect Education/newtonhelp.comGSP 125 Perfect Education/newtonhelp.com
GSP 125 Perfect Education/newtonhelp.com
 
GSP 125 Become Exceptional/newtonhelp.com
GSP 125 Become Exceptional/newtonhelp.comGSP 125 Become Exceptional/newtonhelp.com
GSP 125 Become Exceptional/newtonhelp.com
 
GSP 125 Doing by learn/newtonhelp.com
GSP 125 Doing by learn/newtonhelp.comGSP 125 Doing by learn/newtonhelp.com
GSP 125 Doing by learn/newtonhelp.com
 
Uop gsp 125 final exam guide new
Uop gsp 125 final exam guide newUop gsp 125 final exam guide new
Uop gsp 125 final exam guide new
 
SE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUSSE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUS
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guide
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
 
Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#
 
Devry CIS 247 Full Course Latest
Devry CIS 247 Full Course LatestDevry CIS 247 Full Course Latest
Devry CIS 247 Full Course Latest
 
Oop december 2018
Oop december 2018Oop december 2018
Oop december 2018
 
1
11
1
 
C# (This keyword, Properties, Inheritance, Base Keyword)
C# (This keyword, Properties, Inheritance, Base Keyword)C# (This keyword, Properties, Inheritance, Base Keyword)
C# (This keyword, Properties, Inheritance, Base Keyword)
 
Vectors Intro.ppt
Vectors Intro.pptVectors Intro.ppt
Vectors Intro.ppt
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritance
 
Ch03
Ch03Ch03
Ch03
 
Ch03
Ch03Ch03
Ch03
 
3rd Semester Computer Science and Engineering (ACU) Question papers
3rd Semester Computer Science and Engineering  (ACU) Question papers3rd Semester Computer Science and Engineering  (ACU) Question papers
3rd Semester Computer Science and Engineering (ACU) Question papers
 
17432 object oriented programming
17432   object oriented programming17432   object oriented programming
17432 object oriented programming
 
Getting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingGetting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem Solving
 
SPF Getting Started - Console Program
SPF Getting Started - Console ProgramSPF Getting Started - Console Program
SPF Getting Started - Console Program
 

Recently uploaded

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 

Recently uploaded (20)

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 

Gsp 125 Enthusiastic Study / snaptutorial.com

  • 1. GSP 125 Final Exam Guide For more classes visit www.snaptutorial.com Question 1. 1. In addition to grouping functions together, a class also groups (Points : 3) libraries. math operations. print statements. variables. Question 2. 2. Hiding data in a class is also called (Points : 3) encapsulation. accessibility inversion. confusion culling. redirection. Question 3. 3. The public members of a class (Points : 3) can be changed after compiling, even functions. must be accessed from an object of that class. need a special interface to accessed from an object. can only be accessed within member functions of that class. Question 4. 4. Constructors are called (Points : 3) whenever an object is created. whenever a new line of code is typed. only after math operations. only after a work contract is defined.
  • 2. Question 5. 5. Unions are (Points : 3) defined just like structs, though their memory behaves differently. a place to store multiple data types simultaneously. a concept from the C language that is uncommon in C++. All of the above Question 6. 6. When objects contain other objects, it is called (Points : 3) composition. data blending. subobjecting. enclosures. Question 7. 7. Using the sizeof operator, the compiler will provide the size in bytes of a (Points : 3) class or data type. statically allocated array. variable instance or object. All of the above Question 8. 8. When de-allocating arrays dynamically allocated with new, _____ should be used to ensure proper de-allocation. (Points : 3) destructor. delete. delete []. free(). Question 9. 9. A pointer stores a(n) (Points : 3) address. variable. value. None of the above Question 10. 10. The most common operator used when accessing members of an object through a pointer is this. (Points : 3)
  • 3. & -> . :: Question 11. 11. The following can be used to determine the number of elements in a statically allocated array in C or C++. (Points : 3) sizeof(arrayname)/sizeof(arrayname[0]) elementsof<arrayname> arrayname.length() None of the above Question 12. 12. When returning by reference, (Points : 3) the method can be used as an l-value. other functions cannot use the result as a parameter. C-style code must be capitalized, as per standard convention. There is no such thing as returning by reference. Question 13. 13. Overloaded methods in a class must use (Points : 3) the exact same argument types, but different return types. the exact same name. default arguments. None of the above Question 14. 14. The copy constructor takes (Points : 3) no arguments. a single argument by reference. a single argument by value. any number of arguments. Question 15. 15. A shallow copy is dangerous because (Points : 3) it has a knife and is very clumsy. it may cause bad de-allocation in a properly written destructor in a class that allocates memory.
  • 4. it prevents recursive methods from being called by using significant amounts of stack space. None of the above Question 16. 16. When using inheritance, the class that is doing the inheriting is called a (Points : 3) subclass. child class. derived class. All of the above Question 17. 17. A UML class diagram is commonly used to (Points : 3) exactly describe code before writing it. help programmers explain design to other programmers. define code standards (for syntax) for programming teams. All of the above Question 18. 18. Downcasting is considered safe because (Points : 3) the compiler is very smart about types. it is safe to assume a parent can do everything a child can do. downcasting can only be done on upcasted objects. downcasting is not considered safe. Question 19. 19. If unsure whether to use inheritance or composition, use (Points : 3) inheritance, because it saves the most typing. inheritance, because C++ supports multiple inheritance. composition, because it gives programmers the most options. composition, because it is more efficient than inheritance. Question 20. 20. Creating classes in separate .h and .cpp files is good because (Points : 3) moving code to separate files is good design (separation of concerns).
  • 5. separating declaration from definition allows decoupling of dependencies. many smaller files are easier to maintain by teams of programmers. All of the above Question 21. 21. When using the virtual keyword, C++ can detect the type of an object by using (Points : 3) Compile Time Type Information. dynamic_cast. a "constructor inference" pattern. C++ does not support any kind of reflection. Question 22. 22. Passing pointers by reference (e.g., "(int * & arg)") is possible but limited, because (Points : 3) NULL cannot be passed as a valid pointer by reference. a raw address (&variable) cannot be passed as a valid pointer by reference. r-values cannot be passed as pointers by reference. All of the above Question 23. 23. Stack memory is where (Points : 3) global variables and raw machine code are stored. local variables and execution of instructions are kept track of. dynamic memory is allocated to. None of the above Question 24. 24. A compiler will put sentinel values into memory to (Points : 3) help detect array out-of-bound errors. keep track of how many times a function recurses. stop bad functions from being executed. prevent memory leaks. Question 25. 25. Virtual functions have a cost when compared to normal (statically bound) functions; specifically, they are (Points : 3)
  • 6. slower and less optimizable. less dynamic. unusable with polymorphism. more difficult to read than extern or static functions. Question 26. 26. In C++, the diamond problem that results from multiple inheritance can be solved by (Points : 3) extern inheritance. static inheritance. virtual inheritance. inline inheritance. Question 27. 27. Test-driven development is (Points : 3) writing software after finishing multiple choice exams about software quality. writing many small tests that initially fail, and working on each test until all succeed. another name for object-oriented programming. All of the above Question 28. 28. Which piece of the C/C++ compile tool chain arranges compiled code into the final executable? (Points : 3) Preprocessor Compiler Linker Debugger Question 29. 29. For C-style error codes to be used effectively, a programmer should (Points : 3) always do logic on function returns to test success. check errno after potentially failed operations to see if any errors occurred. read documentation to make sense of error codes. All of the above
  • 7. Question 30. 30. A class template allows (Points : 3) a class to be re-defined with different types but the same code. the compiler to ignore unused methods of the templated class. the templated type to be any type, including another templated type. All of the above Question 31. 31. Write a “Hello World” program in C++. (Points : 2) Question 32. 32. Write code for a struct called “Coin.” The Coin class should have a floating-point member for radius and thickness and weight, a c-string member for name, and an integer member for color. (Points : 7) Question 33. 33. Write code for a class called "Double." The Double class should have a single double member, value. Create accessors and mutators for value. The default constructor of Double should set value to zero. (Points : 7) Question 34. 34. Write a class named Person and create another class called Teacher, which inherits from Person (Person is the parent class and Teacher is the child class). (Points : 7) Question 35. 35. Write code that instantiates an integer and prints out its address. (Points : 7)
  • 8. Question 36. 36. Write the body of thfollowing function so that it returns the square of the number pointed at by the pointer argument. float square(float * valuePtr) { } (Points : 7) Question 37. 37. Consider the following class. class ManagedArray { public: float * data; int size; ManagedArray():data(0),size(0){} void setSize(int a_size){ size = a_size; data = new float[size]; } }; Write a destructor for this class to de-allocate any memory it may have allocated. (Points : 7) Question 38. 38. Write code that dynamically allocates a two- dimensional array of integers called map, 5 high, and 7 wide. Then, de- allocate the two-dimensional array. (Points : 7) Question 39. 39. Write code that allocates an integer on the stack and allocates another integer array on the heap. (Points : 7)
  • 9. Question 40. 40. Write an abstract base class called LivingThing that has the following methods: breathe and eat. (Points : 7) ******************************************************** GSP 125 Midterm Exam For more classes visit www.snaptutorial.com 1. Accidentally inheriting from the same class twice causes terrible ambiguity, and is known as (Points : 2) inheritance overload. the dreaded diamond of death. Von Neumann bottleneck. There is nothing wrong with inheriting the same class more than once. Question 2. 2. Creating classes in separate .h and .cpp files is good because (Points : 2) moving code to separate files is good design (separation of concerns). separating declaration from definition allows de-coupling of dependencies. many smaller files are easier to maintain by teams of programmers. All of the above
  • 10. Question 3. 3. Virtual methods are resolved at runtime by using a (Points : 2) dynamic list. virtual table. vector. haystack. Question 4. 4. Allowing many different types to be treated in the same way is called (Points : 2) polymorphism. multitypecasting. deep-copy. virtual. Question 5. 5. Heap memory is where (Points : 2) global variables and raw machine code are stored. local variables and execution of instructions is kept track of. dynamic memory is allocated to. None of the above Question 6. 6. Memory leaks in a computer program are (Points : 2) not a big deal because operating systems clean up all program memory. easy to find and debug in C and C++. difficult and important to manage in C and C++. a problem in every programming language. Question 7. 7. Virtual functions have a cost when compared to normal (statically bound) functions; specifically, they are (Points : 2) slower and less optimizable. less dynamic. unusable with polymorphism. more difficult to read than extern or static functions. Question 8. 8. The explicit keyword (Points : 2)
  • 11. labels data as being volatile. prevents constructors from automatically being called by implicit typecasting. marks a method as an override of a polymorphic base. identifies a variable that can be referenced but is defined in another compilation unit. Question 9. 9. Preprocessor macros (Points : 2) should be avoided if other langauge features will work just as well. can easily confuse other progammers not familiar with your macro. should be undefined after use to avoid polluting the global namespace. All of the above Question 10.10. Which piece of the C/C++ compile tool chain arranges compiled code into the final executable? (Points : 2) Preprocessor Compiler Linker Debugger ******************************************************** GSP 125 Week 1 iLab Simple game For more classes visit www.snaptutorial.com
  • 12. GSP 125 GSP125 GSP 125 Week 1 iLab // // // INSTRUCTIONS -----------Compile this code. You should see a happy-face character on a field of periods. You can move the character with the 'w', 'a', 's', and 'd' keys. Read through this code! Try to understand it before starting the assignment. Comment confusing lines with what you think code is doing, and experiment with existing code to test your understanding. Once you feel comfortable with this code, accomplish each of the following, and make sure your code compiles and runs after each step is completed. 1) Object Oriented Refactoring a) Write a class called Entity to store two public integers named x and y, and a char named icon (the player data). b) Remove x, y, and icon (the player data) from main(), create an instance of the Entity class (named whatever you like) in main(), and use its members as replacements for the x, y, and icon variables that were removed. c) Write a parameterized constructor for the Entity class that sets x, y, and icon, and use it when creating the instance. d) Make x, y, and icon private variables of Entity, and create Accessor and Mutator (or Getter and Setter) functions to use them in main(). (hint: &quot;player.x++&quot; could be &quot;player.setX(player.getX()+1);&quot; ) e) Write a struct called Vector2, which has two int variables, x and y. f) Write a default constructor for Vector2, which sets x and y to 0. g) Write a parameterized constructor for Vector2, which sets x and y. h) Remove x, and y from Entity, add an instance of the Vector2 structure
  • 13. named &quot;pos&quot; to the Entity class, and use pos's members as replacements for the x, and y variables that were removed. i) Remove height and width (in the game data) from main(), create an instance of the Vector2 structure named &quot;size&quot;, and use size's x member as a replacement for width, and size's y member as a replacement for height. j) Write a method in Vector2 with the signature &quot;bool is(int a_x, int a_y)&quot;. &quot;is&quot; should return true if a_x is equal to that instance's x, and a_y is equal that instance's y. k) Instantiate a new object of class Vector2 called &quot;winPosition&quot;, and set it's x, y value to size.x/2, size.y/2. 2) Add Game Logic a) Add code to the while-loop so that when the player reaches &quot;winPosition&quot;, which should be determined by using the &quot;is&quot; method, the &quot;state&quot; variable should be set to WIN, ending the game. b) Add code to the while-loop so that the state variable is set to to LOST if the player leaves the play field (ending the game). 3) Using enums a) Create an enum called &quot;GameState&quot; with the possible values &quot;RUNNING&quot;, &quot;WIN&quot;, &quot;LOST&quot;, and &quot;USER_QUIT&quot;. b) Replace the state variable with an isntance of the GameState enum. // lab1: simplegame_OOP // &lt;insert your name here&gt; // read main.cpp, and follow the instructions at the bottom of main.cpp #include &lt;iostream&gt; // std::cout using namespace std; #include &lt;windows.h&gt; #include &lt;conio.h&gt; // SetConsoleCursorPosition(HANDLE,COORD)
  • 14. // _getch() struct Vector2 { int x; int y; Vector2() : x(0), y(0) { } Vector2(int x, int y) { x = x; y = y; } bool is(int a_x, int a_y) { if (a_x == x &amp;&amp; a_y == y) { return true; } } return false; }; class Entity { public: Entity(int x, int y, char i) { pos.x = x; pos.y = y; icon = i; } void setX(int x) { pos.x = x; } int getX() { pos.x; } void setY(int y) { pos.y = y; } int getY() { pos.y; } void setIcon(char i) { icon = i;
  • 15. } char getIcon() { icon; } private: Vector2 pos; char icon; }; enum GameState { RUNNING, WIN, LOST, USER_QUIT }; /** * moves the console cursor to the given x/y coordinate * @param x * @param y */ void moveCursor(int x, int y) { COORD c = { x,y }; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c); } int main() { // player data Entity e(3, 4, 1); // game data GameState state = RUNNING; int input; Vector2 size(20, 15); Vector2 winPosition(size.x / 2, size.y / 2); do { // draw the game world moveCursor(0, 0); for (int row = 0; row &lt; size.x; row++) { for (int col = 0; col &lt; size.y; col++)
  • 16. { cout &lt;&lt; '.'; } cout &lt;&lt; 'n'; } // draw the player moveCursor(e.getX(), e.getY()); cout &lt;&lt; e.getIcon(); // get input from the user (wait for one key press) input = _getch(); // process input from the user switch (input) { case 'w': e.setY(e.getY() - 1); break; // move up case 'a': e.setX(e.getX() - 1); break; // move left case 's': e.setY(e.getY() + 1); break; // move down case 'd': e.setX(e.getX() + 1); break; // move right case 27: state = USER_QUIT; break; // quit } // show the game state message moveCursor(0, size.y + 1); switch (state) { case WIN: cout &lt;&lt; &quot;You WON! Congratulations!n&quot;; break; case LOST: cout &lt;&lt; &quot;You lost...n&quot;; break; }
  • 17. if (winPosition.is(e.getX(), e.getY())) { state = WIN; } else { state = LOST; } } while (state == RUNNING); }; // user must press ESCAPE before closing the program cout &lt;&lt; &quot;press ESCAPE to quitn&quot;; while (_getch() != 27); return 0; ******************************************************** GSP 125 Week 2 ILab Rectangles For more classes visit www.snaptutorial.com / lab2: rectangles // &lt;insert your name here&gt; // read main.cpp, and follow the instructions at the bottom of main.cpp #define NOMINMAX // prevent Windows API from conflicting with &quot;min&quot; and &quot;max&quot; #include &lt;stdio.h&gt; // C-style output. printf(char*,...), putchar(int)
  • 18. #include &lt;windows.h&gt; // SetConsoleCursorPosition(HANDLE,COORD) #include &lt;conio.h&gt; // _getch() /** * moves the console cursor to the given x/y coordinate * 0, 0 is the upper-left hand coordinate. Standard consoles are 80x24. * @param x * @param y */ void moveCursor(int x, int y) { COORD c = {x,y}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c); } struct Vec2 { short x, y; Vec2() : x(0), y(0) { } Vec2(int x, int y) : x(x), y(y) { } void add(Vec2 v) { x += v.x; y += v.y; } }; class Rect { Vec2 min, max; public: Rect(int minx, int miny, int maxx, int maxy) :min(minx,miny),max(maxx,maxy) {} Rect(){} void draw(const char letter) const
  • 19. { for(int row = min.y; row &lt; max.y; row++) { for(int col = min.x; col &lt; max.x; col++) { if(row &gt;= 0 &amp;&amp; col &gt;= 0) { moveCursor(col, row); putchar(letter); } } } } bool isOverlapping(Rect const &amp; r) const { return !( min.x &gt;= r.max.x || max.x &lt;= r.min.x || min.y &gt;= r.max.y || max.y &lt;= r.min.y); }; } void translate(Vec2 const &amp; delta) { min.add(delta); max.add(delta); } int main() { // initialization Rect userRect(7, 5, 10, 9); Rect rect0(10, 2, 14, 4); Rect rect1(1, 6, 5, 15); int userInput; do { // draw rect0.draw('0'); rect1.draw('1'); moveCursor(0, 0); // re-print instructions printf(&quot;move with 'w', 'a', 's', and 'd'&quot;);
  • 20. userRect.draw('#'); // user input userInput = _getch(); // update Vec2 move; switch(userInput) { case 'w': move = Vec2( 0,-1); break; case 'a': ******************************************************** GSP 125 Week 3 iLab List of Numbers For more classes visit www.snaptutorial.com GSP 125 GSP/125 GSP 125 Week 3 iLab // lab3: listofnumbers // &lt;insert your name here&gt; // read main.cpp, and follow the instructions at the bottom of main.cpp #include &lt;iostream&gt; using namespace std; int main() {
  • 21. int numberOfElements = 0; float * elements = NULL; float userInput; bool addingNumbersToTheList; cout &lt;&lt; &quot;Keep entering numbers. Enter a non-number to stop.&quot; &lt;&lt; endl; do { cin &gt;&gt; userInput; addingNumbersToTheList = !std::cin.fail(); if(addingNumbersToTheList) { // make a bigger array to replace the old one float * biggerArray = new float[numberOfElements+1]; if(elements != NULL) { // copy the old elements into the biggerArray for(int i = 0; i &lt; numberOfElements; i++) { biggerArray[i] = elements[i]; } // the old array is not needed anymore, we have a better copy delete elements; } // point at the new array elements = biggerArray; numberOfElements = numberOfElements+1; // put the new number into the last element of the array elements[numberOfElements-1] = userInput; } } while(addingNumbersToTheList); // fix cin after intentionally breaking it above. if(std::cin.fail()) { std::cin.clear(); while(std::cin.get() != 'n');
  • 22. } bool hasNumbers = numberOfElements &gt; 0; if(hasNumbers) { // print the stored numbers cout &lt;&lt; &quot;Entered numbers: &quot; &lt;&lt; endl; cout &lt;&lt; &quot;{&quot;; for(int i = 0; i &lt; numberOfElements; ++i) { if(i &gt; 0) { cout &lt;&lt; &quot;, &quot;; } cout &lt;&lt; elements[i]; } cout &lt;&lt; &quot;}&quot; &lt;&lt; endl; } else { } float sum = 0; for(int i = 0; i &lt; numberOfElements; ++i) { sum += elements[i]; } cout &lt;&lt; &quot;total: &quot; &lt;&lt; sum &lt;&lt; endl; cout &lt;&lt; &quot;average: &quot; &lt;&lt; (sum / numberOfElements) &lt;&lt; endl; cout &lt;&lt; &quot;no numbers entered.&quot; &lt;&lt; endl; } return 0; // INSTRUCTIONS // // // // -----------Compile this code. You should be able to enter any number of numbers into the console, but as soon as you enter a non-number, a list of every number you typed should display.
  • 23. Read through this code! Try to understand it before starting the assignment. Comment confusing lines with what you think code is doing, and experiment with existing code to test your understanding. Once you feel comfortable with this code, accomplish each of the following, and make sure your code compiles and runs after each step is completed. 1) The ManagedArray class a) Create a new class called ManagedArray. It should have a float pointer named &quot;elements&quot; to reference an array of floats, and an integer named &quot;numberOfElements&quot; to keep track of how many floats are in the array. b) Create a default constructor, which sets &quot;elements&quot; to NULL, and &quot;numberOfElements&quot; to 0. c) Create an accessor for the ManagedArray class called &quot;int ManagedArray::size()&quot;, which returns the number of elements d) Create an accessor for the ManagedArray class called &quot;float ManagedArray::get(int index)&quot;, which returns the value, in &quot;elements&quot;, at the given index. e) Create a member function for ManagedArray called &quot;void ManagedArray::add(float value)&quot;, which allocates a larger array than &quot;elements&quot;, and replaces &quot;elements&quot; with it, adding 'value' to the end of it. This method should also increase &quot;numberOfElements&quot;. See the code within the &quot;if(addingNumbersToTheList) {&quot; block. 2) Use ManagedArray
  • 24. a) Remove the &quot;elements&quot; and &quot;numberOfElements&quot; variables in main, and use a ManagedArray object to get the same functionality that was in main. 3) Destructor and Copy Constructor a) Create a destructor (named &quot;ManagedArray::~ManagedArray()&quot;), which deletes (with &quot;delete &quot;) the &quot;elements&quot; array. b) Create a copy-constructor (named &quot;ManagedArray::ManagedArray(ManagedArray &amp; ma)&quot;), which copies the &quot;numberOfElements&quot; variable from &quot;ma&quot;, and allocates an &quot;elements&quot; array the same size, with data copied from &quot;ma&quot;. 4) Print Function a) Create a new function called &quot;void print(ManagedArray ma)&quot;, which prints the given array, just like the code within the &quot;if(hasNumbers) {&quot; block. b) Use the print function to print out a ManagedArray at the end of your program. c) Use the print function to print out a ManagedArray a second time. This will crash your program if you wrote your destructor correctly but *did not* write your copy constructor correctly. If the program does not crash, comment out your copy constructor, recompile and try again, ******************************************************** GSP 125 Week 4 iLab Simple Game inheritance For more classes visit
  • 25. www.snaptutorial.com GSP 125 GSP/125 GSP 125 Week 4 iLab // // // // // // // INSTRUCTIONS -----------Compile this code. You should see a rectangular play field of periods, with 3 Entity objects visible on it. The happy-face Entity moves with the &quot;wasd&quot; keys, and the club Entity moves with the &quot;ijkl&quot; keys. If the happy-face reaches the diamond Entity, the player wins. If the happy-face reaches the club, the player loses. Read through this code! Try to understand it before starting the assignment. Comment confusing lines with what you think code is doing, and experiment with existing code to test your understanding. Once you feel comfortable with this code, accomplish each of the following, and make sure your code compiles and runs after each step is completed. 1) Getting comfortable with the game code a) Implement initialization lists in Vector2, Entity, and Game (setting object values after a ':', between the constructor signature and body). Have initialization lists set initial values for each member variable.
  • 26. b) Add another Entity to the game that isn't the same location as an existing Entity. Use a heart icon (ASCII code 3). It should display in the game. c) Add logic that makes the club (PLAYER2) win the game if that player reaches the heart Entity. You may want to make new constants, like GOAL2, and WIN2, to follow the existing code convention. d) Make a new private function called &quot;void Game::handleUserInput()&quot;, move the user input handling logic from Game::update() into this new function, and call Game::handleUserInput from Game::update. e) Add whitespace to the handleUserInput logic, and comment each line with what you understand it is doing. If you don't understand what the code is doing, experiment with it until you do! Do things like printing variables you are unsure about, and guess what output will look like. f) Implement the prototyped overloaded operators for Vector2. Once they are finished you should be able to use the alternate code for setting up PLAYER2 in Game::Game() in &quot;game.cpp&quot;. 2) A &quot;BlinkEntity&quot; class a) Create 2 new files in your project: &quot;blinkentity.h&quot;, and &quot;blinkentity.cpp&quot; b) Make a BlinkEntity class that extends Entity. Declare the class in &quot;blinkentity.h&quot; and define it's methods in &quot;blinkentity.cpp&quot;. Your &quot;blinkentity.h&quot; file should look something like: #pragma once #include &quot;entity.h&quot; class BlinkEntity : public Entity { }; c) Instead of using an Entity for the Entity marked GOAL1 in the Game constructor, use a BlinkEntity. You will need to create a public BlinkEntity constructor.
  • 27. d) Give BlinkEntity another member variable called &quot;alternateIcon&quot;. When BlinkEntity calls it's update function, swap the values of &quot;icon&quot; and &quot;alternateIcon&quot;. You won't notice a change during runtime until you add the virtual modifier to Entity::update(). 3) A &quot;WanderingEntity&quot; class a) Create 2 new files in your project: &quot;wanderingentity.h&quot;, and &quot;wanderingentity.cpp&quot; b) Make a WanderingEntity class that extends Entity. Declare the class in &quot;wanderingentity.h&quot; and define it's methods in &quot;wanderingentity.cpp&quot;. // Your &quot;wanderingentity.h&quot; file should look something like: // #pragma once // // #include &quot;entity.h&quot; // // class WanderingEntity : public Entity { // }; // c) Instead of using an Entity for the Entity marked PLAYER2 in the Game // constructor, use a WanderingEntity. You will need to create a public // WanderingEntity constructor. // d) Create a new update method for WanderingEntity. Declare it in //
  • 28. &quot;wanderingentity.h&quot;, and define it in &quot;wanderingentity.cpp&quot;. In the // WanderingEntity::update() method, set the &quot;howToMoveNext&quot; variable // to a random number from 0 to 3. You can use &quot;rand() % 4&quot; to do this in // &quot;wanderingentity.cpp&quot; if you #include &lt;cstdlib&gt; or &lt;stdlib.h&gt;. After // setting the &quot;howToMoveNext&quot; variable in update, call the parent class's // updated with &quot;Entity::update()&quot;. // e) Add at least 2 more WanderingEntity objects in the Game. Add game logic // will cause the player to lose if the player shares a location with any // WanderingEntity object. ******************************************************** GSP 125 Week 5 iLab Shapes For more classes visit www.snaptutorial.com
  • 29. GSP 125 GSP/125 GSP 125 Week 5 iLab // INSTRUCTIONS // ------------ // Compile this code. After pressing any key to clear the instructions, You // should see three rectangles labeled '#', 'b', and 'c'. You should also see // two triangles, labeled 'd' and 'e'. Pressing '>' and '<' will change which // shape is labeled '#'. Pressing 'w', 'a', 's', and 'd' will move the shape // labeled '#'. Pressing 'space' will randomize the selected shape. // // Read through this code! Try to understand it before starting the assignment. // Comment confusing lines with what you think code is doing, and experiment // with existing code to test your understanding. // Once you feel comfortable with this code, accomplish each of the following, // and make sure your code compiles and runs after each step is completed. // // 1. Getting comfortable with the code // a) Create a "makeRandom" method in both the Rect and Tri classes, based // on the "makeRandomRect" and "makeRandomTri" functions in // "application.cpp". The makeRandom function should take no parameters, // and instead make itself random. Removing the old "makeRandomRect" // and "makeRandomTri" functions as well. Be sure to consider what to do // about "screenMin" and "screenMax". // b) Create a print method for the Tri class, similar to the print method
  • 30. // for the Rect class. This method may come in very handy when debugging. // 2. Create Shape base class // a) Create a header file (without a .cpp file) for a Shape class. // b) Create the Shape class, which should have no member variables. // c) Make the Shape class an interface for the Rect and Tri classes. Shape // should have pure-virtual methods for each method that Rect and Tri have // in common. // d) Make sure Shape has a virtual destructor with an empty body. // 3. Make Rect and Triangle extend Shape // 4. Change selected // a) Change the type of "Application::selected" from "void *" to "Shape *". // b) Every piece of code that typecasts "selected" (and the logic around it) // can be removed now. Simply call functions using the "Shape" interface. // c) Remove the "selectedType" variable from Application. Logic that needs // some form of RunTime Type Information should use dynamic_cast instead. // 5. Merge all Shape objects into a single array // a) Create an array of Shape pointers in the Application called "shapes". // b) Making a complementary NUM_SHAPES variable would make sense. // b) Remove "rectangles" and "triangles" arrays. // c) Put each Tri and Rect object managed by the Application class into // the "shapes" array. This will require re-factoring in multiple files. // While removing references to "rectangles" and "triangles" arrays, it // may make sense to replace pairs of for-loops using each of the old // arrays with a single for-loop using just "shapes". // 6. Make "shapes" dynamic
  • 31. // a) Give Application::init() 2 parameters: int numRect, int numTri // b) Make "shapes" a pointer of type "Shape **", and allocate it to be // "numShapes" big, where "numShapes" is an int member of Application // equal to (numRect + numTri), defined in Application::init(). // c) When calling "app.init()" in main, pass valid arguments for numRect // and numTri. // d) De-allocate the "shapes" array in Application::Release(). // 7. Clean up old variables // a) Remove the TYPE_RECT and TYPE_TRI variables from Application. // b) Remove NUM_TRI and NUM_RECT, and any NUM_SHAPES variable as well. Use // numShapes where needed. // 8. Add Circle class // a) Create a header file AND a source file for a Circle class. // b) Use Rect and Tri as examples to create the Circle class with. // c) A Circle class should have at least a 2 dimensional position, and a // radius. // d) A simple algorithm for drawing a Circle will be similar to drawing a // Rect or Tri, thought it might include the following code: // float dx = center.x - col, dy = center.y - row; // if( dx*dx + dy*dy <= radius * radius ) { // moveCursor(col, row); // putchar(letter); // } // e) Add an additional parameter to Application::init(), "int numCircles". // Implement init to generate Circle objects along with Rect and Tri // objects. // 9. Implement add/remove for the shapes array // a) Add code that increases the size of the shapes array, adding a random
  • 32. // shape, whenever the '=' or '+' key is pressed. Take a look at the week // 5 lecture showing explicit constructors for help with this algorithm. // a) Add code that decreases the size of the shapes array, removing the last // shape, whenever the '-' or '_' key is pressed. End the program when the // last shape is removed. Removing a shape, like adding a shape, can be // done by allocating an array of a different size (smaller this time). ******************************************************** GSP 125 Week 7 iLab GSP 124 Week 7 iLab win32game For more classes visit www.snaptutorial.com GSP 125 GSP/125 GSP 125 Week 7 iLab Looking for help with C++ lab, please see attached zip, inside main.cpp are directions: // 1) Replace Vector2 and Coordinate // a) Create a new Vec2 class as a replacement for both Vector2 and // Coordinate. Vec2 must be a templated class, so that it stores and // manipulates X and Y values of a templated type. It may be helpful to // start with the Vector2 class, add "template" to the // header, and replace (Ctrl+H) each instance of "float" with "TYPE", and
  • 33. // "Vector2" with "Vec2". // b) Remember, a templated class must have all method definitions in the // same file as the templated class declaration. Also remember that method // definitions outside of a templated class' declaration need a // "template" header, and a "" appended to the class // name with the scope resolution operator (e.g.: // "void Vec2::limitMagnitude(TYPE max) {/* method body */}"). // c) Replace the use of Vector2 with Vec2. // d) Replace the use of Coordinate with Vec2. // 2) More Game Goals // a) Instead of having a single goal for the player, create at least 3 // randomly placed goals for the player. Use a "std::vector" // object (from the Standard Template Library) named "goals" to store the // goals. // c) Whenever the user clicks in the game window, the game should create // another goal object for the player to get, and add it to the // "std::vector goals" object. // d) Each retrieved goal should be removed from the game after being // retrieved by the player. A "You Win!" message should display when the // player retrieves all goals. ********************************************************