Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can I get some help with these questions for my CS C++ course? CS 109/110 Fall 2

ID: 3757547 • Letter: C

Question

Can I get some help with these questions for my CS C++ course?

CS 109/110

Fall 2018

3

SHORT ANSWER:

1.

Given the following code:

string thisClass = “CS109/110”;

Write the single line of the code that finds the number of characters in the variable class. Save the result to a

new variable using a proper data type and name.

2.

What is the value of letter after the following two lines of code are executed?

char letter =‘B’;

letter+=5;

3.Next to each variable declaration below, state valid or invalid. If invalid, state why. In this case valid means it is allowed by the compiler and will run without error.

a.int letter = 9;

b.int 5number = 5;

c.int this is a number = 7;

d.int number5 = 5;

e.int for = 4;

4.

What is the numeric value of x below?

a.int x = 10 % 3;

b.int x =9 % 2;

c.int x = 46 % 2;

5.

Looking at 4b and 4c, what can the remainder be used for?

DEBUG CODE:

6.

Read the code below:

int num;

cout << "Enter a number? ";

cin >> num;

if (num = 5) {

cout << "Your number is 5." << endl;

} else {

cout << "Your number is not 5" << endl;

}

What is the behavior of this code? Is there an error? If so, what is the error? If not, is the behavior of the code

appear to be intended?

CS 109/110 Fall 2018 UIC 7. The following code fragment is run, what is printed to the console? Explain why. double x, y, z; x = 0.8; y = 0.2; z=1.0-x-y; if (z == 0){ cout "correct!" endl; else { cout ''Inccorect. " endl; READ CODE: 8. Below is a code fragment; assume x is an integer with the value 40 at the start of the code fragment. Execute each code fragment and show the output below that code fragment. if (X 25) { x=x*2 if(X0) } else 5 9. Write the output from the code below: int i, j; int n - 5; for (j = 0; j ''o'' = n-i; ++j){ cout . cout "4" endl; 10. Rewrite the following code fragment as a nested if-else statement. The new code should not have a nested if statement, but should only include one if-else statement, and logical and relational operators. Your new code should be shorter, clearer, and easier to read but functionally perform the same as the original code. int a; int b; 4

Explanation / Answer

char letter =‘B’;

letter+=5; // letter = G after execution.

a.int letter = 9;----- Valid

b.int 5number = 5;----- invalid, because a variable name cannot star with a integer value.

c.int this is a number = 7;-------- invalid, a variable name cannot have white spaces

d.int number5 = 5;----- valid,

e.int for = 4;------ invalid, because for is keyword, it cannot be used as a variable.

a.int x = 10 % 3; // x =1

b.int x =9 % 2; // x=1

c.int x = 46 % 2; // x=0

We can use this result or remainder to check if the number is even or odd.

Behavior of the code is check if the input number is 5 or not. Yes there is an error, in if statement, i.e. if(num=5),here assignment operator is used which is used to assign the values not to check them, instead of this a relational operator should be used which check the value i.e if (num==5).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote