DeVry GSP 115 Week 1 Assignment latest

$28

Description

DeVry GSP 115 Week 1 Assignment latest

Week 1: Simple Data Types

Instructions

Complete the following assignments. Cut 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_W1_Assignments.docx. Submit it to the Week 1 assignment Dropbox.

  1. 1.Compile Time Bugs (TCO 4)

Find and fix the four (possibly five) compile time bugs in the code at the end of this section. Compile time bugs shown 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 . You will actually see more than five errors, but they are all caused by just four or five bugs. There is a case where you have either two bugs or one, depending on what you think the error is. In one case, it can be fixed with a single change. In the other case, it will take two changes to fix the problems.

Here is the code.

// Week 1 Assignment-1

// Description: Compile time errors with simple variables

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

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

#include<iostream>// provides access to cin and cout

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

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

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

// NO GLOBALS

//–end of global constants———

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

usingnamespacestd;

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

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

int main()

{

// Initialize variables

int 1IntVar;

int x = “Four”;

char y = “a”;

float z1 = 4.756f

z2 = 7.45f;

// Print out the values

1IntVar = x;

cout<<“1IntVar = “<< 1IntVar <<endl;

cout<<“x = “<< x <<endl;

cout<<“y = “<< y <<endl;

cout<<“z1 = “<< z1 <<endl;

cout<<“z2 = “<< z2 <<endl;

ductTape;

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

cin.get();

return 0;

}

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

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

  1. 2.Numbers and Conversions (TCO 4)

The following has one compile time bug. This bug only generates a warning in some compilers and would cause an exception during runtime. Visual Studio 2012 actually gives us an error at compile time. This is better, because you should never do the thing that causes this error. Fix the error and run the program. Compare the output to the code and answer the questions found after the code.

Here is the code.

// Week 1 Assignment-2

// Description: Numbers and conversions with simple variables

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

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

#include<iostream>// provides access to cin and cout

#include<iomanip>

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

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

usingnamespacestd;

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

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

int main()

{

// create and initialize variables

int x, y;

float f1 = 1.6767676f;

float f2 = 2.2f;

float diff;

// demonstrate math and number output

x = y;

x = f1; // What happens when you store a float into an int?

y = f2; // Does it round or truncate?

// display ints

cout<<“—>using default cout settings: “<<endl;

cout<<“x=”<< x <<” y=”<< y <<endl;

cout<<“f1=”<< f1 <<” f2=”<< f2 <<endl;

cout<<“—>using scientific settings: “<<endl;

cout<< scientific <<“x=”<< x <<” y=”<< y <<endl;

cout<< scientific <<“f1=”<< f1 <<” f2=”<< f2 <<endl;

cout<<“—>setting precision to 4″<<setprecision(4) <<endl;

cout<< scientific <<“x=”<< x <<” y=”<< y <<endl;

cout<< scientific <<“f1=”<< f1 <<” f2=”<< f2 <<endl;

cout<<“—>using fixed settings: “<<endl;

cout<< fixed <<“x=”<< x <<” y=”<< y <<endl;

cout<< fixed <<“f1=”<< f1 <<” f2=”<< f2 <<endl;

cout<<“—>setting precision to 12″<<setprecision(12) <<endl;

cout<< fixed <<“x=”<< x <<” y=”<< y <<endl;

cout<< fixed <<“f1=”<< f1 <<” f2=”<< f2 <<endl;

cout<<“—>restoring float (default) settings: “<<endl;

cout<<defaultfloat<<“x=”<< x <<” y=”<< y <<endl;

cout<<“f1=”<< f1 <<” f2=”<< f2 <<endl;

cout<<“—>setting precision to (default) 6″<<setprecision(6) <<endl;

cout<<“x=”<< x <<” y=”<< y <<endl;

cout<<“f1=”<< f1 <<” f2=”<< f2 <<endl;

cout<<“—–> Showing results of unusual and unexpected math operations “<<endl;

f2 = sqrt(f1);// take the square root of f1

cout<<“The square root of “<< f1 <<” is “<< f2 <<endl;

f2 = f2*f2; // square the square root of f1

cout<<“Squaring f2 should give us the same value as f1. f1 = “<< f1 <<” f2 = “<< f2 <<endl;

diff = f1 – f2; // This should be zero–is it?

cout<<“diff should be zero. diff = “<< diff <<endl;

cout<<“Oops. Let’s take another look at f1 and f2 in higher precision.”<<endl;

cout<<“—>setting precision to 12 places. f1 = “<<setprecision(12) << f1 <<” f2 = “<< f2 <<endl;

f2 = f2/diff; // What happens when we divide a floating point by something close to zero?

cout<<“Division by a very small number. f2 = “<< f2 <<endl;

f1 = f1/0.0; // What happens when we actually divide by zero?

cout<<“Division by zero. f1 = “<< f1 <<endl;

f1 = f1 * diff;

cout<<“Multiply a small negative number by infinity. f1 = “<< f1 <<endl;

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

cin.get();

return 0;

}

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

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

Questions

  1. 1.When storing a floating point number into an integer variable, does it truncate or round?
  2. 2.When the floating point numbers were printed out at higher precision, they were not the same value as entered.Research this issue and explain why.
  3. 3.Thesetprecision(12) command either sets the precision for 12 places after the decimal point or 12 digits total; select the right option for each case below.
  4. a.fixed [total/after the decimal point]
  5. b.scientific [total/after the decimal point]
  6. c.float [total/after the decimal point]
  7. 4.Based on the results of taking the square root and then squaring again, what would you say about the accuracy of floating point arithmetic in C ?
  8. 5.Dividing by zero in earlier compilers generates an error and an exception.What does Visual Studio 2012 produce as the result of dividing by zero?
  9. 3.Create a Program FromPseudocode (TCO 1)

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. It is slightly different from our iLab assignment.You can make up your own variable names.

Here is the pseudocode.

// Week 1 Assignment-3

// Description: Setup Variables for CRPG Character Generator

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

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

#include<iostream>// 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 Variables

// 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 variables.

//**End of your code

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

cin.get();

return 0;

}

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

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

 

DeVry Courses helps in providing the best essay writing service. If you need 100% original papers for DeVry GSP 115 Week 1 Assignment latest, then contact us through call or live chat.

DeVry GSP 115 Week 1 Assignment latest

Best DeVry GSP 115 Week 1 Assignment latest
DeVry GSP 115 Week 1 Assignment latest

 

 

 

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Add to cart