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

Answer all C++ Problems: Describe what will happen and the results of the operat

ID: 3551226 • Letter: A

Question

Answer all C++ Problems:





Describe what will happen and the results of the operation when these code sections arc executed: float sum=l; sum += 10; double average, n1 = 5.0, n2 = 8.0, n3 = 10.0; average = (n1 + n2 + n3)/3; float realNum; realNum = (15.0/7.0)+(15/7); Fill in the blank. (10) In C++ the = symbol is called the operator. An if-else statement without an else part is called a(n) if statement. The area in a program where a variable can be used is formally referred to as the of the variable. A variable can store only variable at a time. When English-like phrases are used to describe the steps in an algorithm the description is called Define and give an example use of following C++ terms: escape sequence, manipulator, pow(x,n), constant expression. (10) Given the following list of declarations in the same program determine which are valid and correct any that arc invalid. (10)

Explanation / Answer

4]

a)

sum will be equal to 11.000

10 ie an integer value is added according to type conversion rules it gets added to float

b)

same goes for this too

3 gets converted to float type

so average = 7.66667

c)

(15.0/7.0) =2.14 --- float/float -- so ans float

(15/7) =2 ...... int/int so ans =int

but now 2.14 gets added to 2 which is fine by type conversion rules

so ans =4.14


5]

a)

assignment operator

b)

else without if

c)

scope

d)

one

e)

comments


6]

Escape Sequences - These are character combinations that comprise a backslash () followed by some character. They give results such as getting to the next line ( ) or a tab space ( ). They are called escape sequences because the backslash causes an "escape" from the normal way characters are interpreted by the compiler. You must have seen these in cout statement.

Constant Expression - A constant expression can be evaluated at compile time. That means it has no variables in it. For example:

is a constant expression.

Manipulators - Manipulators are functions specifically designed to be used in conjunction with the insertion (<<) and extraction (>>) operators on stream objects, for example:


7]

union is invalid

best Price is invalid - space cant be used

letter-grade is invalid - -cant be used

char average cant be declared as it is initialised in float

   
  cout << boolalpha;
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