GSP 115 DeVry Week 2 Assignment Latest

Downloading is very simple, you can download this Course here:

http://wiseamerican.us/product/gsp-115-devry-week-2-assignment-latest/

Or

Contact us at:

SUPPORT@WISEAMERICAN.US

GSP 115 DeVry Week 2 Assignment Latest

GSP115

GSP 115 DeVry Week 2 Assignment Latest

 

GSP 115 DeVry Week 2 Assignment Latest

Complex Data Types

Instructions

Complete the following assignments. Copy and paste your finished code into a Word document, clearly identifying which assignment it is. Also, capture the output of the program and paste that into the Word document.If there are questions to be answered, put the answers after the output. When you complete all three of this week’s assignments, save the document as yourLastName_GSP115_W2_Assignments.docx. Submit it to the Week 2 assignment Dropbox.

  1. Compile Time Bugs (TCOs 2, 4, 5, and 6)

Find and fix the compile time bugs in the code at the end of this section. Compile time bugs show as errors when you compile, but the Visual Studio IDE also gives you visual clues in the form of red squiggly underlines, as shown here.jpg

Be aware that not every line that is marked as an error is actually an error. For example, if something causes one of your variables to not be created, such as forgetting to add the data type when you create it, everywhere in your code that references that variable will show an error. Fix the problem so your variable is created and the errors where the variable is referenced go away. You should work on bugs starting at the top of your code (that’s the order the compiler presents them to you). Fix the first line with a bug and then recompile. Often, this will clear additional errors. You may have to make some assumptions about what was actually intended. That’s OK. When the code compiles, run it and get a screen capture of the output.

Here is the code.

// Week 2 Assignment-1

// Description: Compile time errors in C Strings, Arrays, std:string,

// struct, enum, pointers, and std::array.

//———————————-

//**begin #include files************

#include // provides access to cin and cout

#include <> // provides access to std:array

#include // required for getline

//–end of #include files———–

//———————————-

using namespace std;

//———————————-

//**begin global constants**********

constintarraySize = 4;

// **there is a subtle bug here (needs “const”)

enumMyEnum // Needs to be before the struct that uses it

{ Dog, Cat, Fish, Squirrel };

structMyStruct

{ int a; float b; string c; MyEnum d; };

//–end of global constants———

//———————————-

//**begin main program**************

int main()

{ // Initialization

charmyCString[arraySize] = {0};

charmyOtherCString[] = {‘Yet another string’};

intmyInt[3] = {27, 39, 0, 42};

stringmyString;

MyStructaStruct = { 4,3.5,Dog ,”Dogs”};

int x;

int * pX = x;

array Animals;

// Storing values in uninitialized variables

myCString[0] = “A”;

myString = “A third string”;

x = 4;

for (inti = 0; i

Animals[i].a = rand();

Animals[i].b = rand()0/100.0;

Animals[i].c = MyEnum(rand()%4);

cout<< “Enter a name: “;

getline(cin, Animals[i].d); }

// Display the data

cout<< “myCString = ” <

 

  1. Problems With Pointers and New/Delete(TCOs 2, 4, 5, and 6)

The following code creates a pointer to an array of ints and allocates space for fiveints. It then loads the array with the square of values 0 through 4 and displays the results. Because this is a dynamic array allocation, we can reallocate a larger array. This time we allocate space for sevenints and load and display the squares. In the process, our code has created a memory leak, because we failed to follow the hard and fast rule of for every new there must be a delete.When you run this program (before you fix the memory leak), the output should look something like the following.

Figure 1: Memory Leak Output

Here’s a printout of what the values should be. The actual addresses, of course, will be different, but they should follow the same pattern.

Figure 2: Desired Output

Notice in Figure 1 that the address of nArray never changes and is the same for nArray[0] in both loops.

For this assignment, fix the memory leak. The output should look similar to Figure 2.

Here is the code.

// Week 2 Assignment-2

// Description: Problems with pointers and new/delete

//———————————-

//**begin #include files************

#include// provides access to cin and cout

//–end of #include files———–

//———————————-

usingnamespacestd;

//———————————-

//**begin global constants**********

constintarraySize = 5;

//–end of global constants———

//———————————-

//**begin main program**************

int main()

{ cout<

After creating and allocating memory for nArray.”<

and contains the value

“<< hex << *nArray<

cout<<” —>After initializing nArray.”< a

nd contains the value

“<< hex << *nArray<”

 

“< and contains the value “<< hex <<

*nArray

“< and contains the value “<< hex << *nArray<

// Wait for user input to close program when debugging.

cin.get();

return 0; }

//–end of main program————-

//———————————-

 

  1. Create a Program FromPseudocode (TCOs 1, 2, 4, 5, and 6)

This exercise will be to use pseudocode (in the form of comments) to write a program that creates and initializes the variables for a computer role-playing game character generator. This will only setup the variables. The difference from last week is that you must put your character attributes in a structure. You can make up your own variable names.

Here is the pseudocode.

// Week 2 Assignment-3

// Description: CRPG Character attributes using a struct

//———————————-

//**begin #include files************

#include// provides access to cin and cout

//–end of #include files———–

//———————————-

//**begin global constants**********

//–end of global constants———

//———————————-

usingnamespacestd;

//———————————-

//**begin main program**************

int main()

{

//**Enter code staring here

// Create structure

// initialize structure data members

// character ID [integer] initialized to 0

// strength [integer] initialized to 80

// armor [integer] initialized to 70

// health [float] initialized to 1.0f

// flag to indicate if the character is dead or alive [boolean] initialized to true

// Print out each of the data members in the structure.

//**End of your code

// Wait for user input to close program when debugging.

cin.get();

return 0;

}

//–end of main program————-

//———————————-