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

1)Write a C++ if expression for the following statement: If x is less than or eq

ID: 3723146 • Letter: 1

Question

1)Write a C++ if expression for the following statement:

If x is less than or equal to 10 or y is less than or equal to 10.

2) The following program uses the switch case programming structure (substitute for if and if-else). Fill in the blanks with what is missing.

#include <iostream>

#include <cmath>

using namespace std;

int main()

{

double y =10;

double x = 5;

double z;

z= pow(x,2) + pow(y,2);

switch(______) // Write in the blank what needs to go to compare z to various numbers.

{

case______: // If z = 150

cout << “ z = 1 “ << endl;

break;

case:______:_ // else if z = 200

cout << “z = 20” << endl;

break;

case:_______:_//else if z= 300

cout << “ z = 125” << endl;

break;

case:________:// else z = 400

cout << “ z = 200” << endl;

break;

}

return 0;

}

3)In the following program, in which the arguments are passed by reference, what are the final values of x and y that will be displayed in the cout statement? .

#include <iostream>.

using namespace std;

void function( int&, int&);

int main()

{

int x = 0; .

int y = 0;

function(x,y)

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

return 0;

}

void function( int& q , int& r )

{

q=35

r=240

cout << “this is a small function.” ;

}

a. .x =

b. .y=

4) Determine whether or not the names below are valid:

a. 3%599_____________________

b. livingasteroids__________________

c. Canniptioner______________

d. 12Fits=a caniption_______________

Explanation / Answer

|| is used for or , && is used for and

1 . if( x<=10 || y<=10 )

2 . // in switch statement the expression must have an integral or enumerated type

switch((int)z)

{

case 150: // If z = 150

cout << " z = 1 " << endl;

break;

case 200: // else if z = 200

cout <<" z = 20"<< endl;

break;

case 300://else if z= 300

cout << " z = 125"<< endl;

break;

case 400:// else z = 400

cout << " z = 200" << endl;

break;

}

3. as the x and y are passed by reference ,the changes done to q and r will affect x and y .Hence values are

x = 35

y = 240

4. variable names must be started with a letter or underscore _ then it can contain numbers.

a is invalid

b is valid

c is valid

d is invalid.