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

QUESTION 1 What will this snippet display? int a = 10, b = 3; double c = 1.4; c

ID: 3673157 • Letter: Q

Question

  

QUESTION 1

What will this snippet display?

int a = 10, b = 3;

double c = 1.4;

c = a / b;

cout << c<< endl;

3.333

3

1.333

10

10 points   

QUESTION 2

What is the value of the boolean variable test?

int a = 5;

int b = 7;

int c = 10;

bool test (! ((c % a == 0) || (a * b >50)));

cout << test << endl;

3

1

0

2

10 points   

QUESTION 3

Will the following code compile?

#include<iostream>

#include<string>'

using namespace std;

char q;

int main()

{

string year;

cout << "Enter your graduation year ";

cin >> year;

cout << " Your graduation year is: " << year;

system("pause");

return 0;

}

True

False

10 points   

QUESTION 4

What will this program display?

2, 1

1, 1

2, 2

1, 2

10 points   

QUESTION 5

What header files are needed for this code? select all that apply.

int main()

{

string var;int zip;

cout << "Enter your zip code ";

getline(cin, var);

stringstream(var) >> zip;

cout << "Your zip code entered is: " << zip << endl;

cout << " Enter a letter to exit." << endl;

cin >> q;

return 0;

}

<iostream>

<fstream>

<string>

<sstream>

10 points   

QUESTION 6

What is the difference between "cin" and "getline" ? in one sentence.

Path: p

Words:0

10 points   

QUESTION 7

What should be changed in this code so that it performs the intended function ?

#include<iostream>

#include<string>

using namespace std;

char q;int main()

{

int name;

cout << "Enter your first and last names ";

getline(cin, name);

cout << " Your name is: " << name;'

cout << " Enter a letter to exit." << endl;

cin >> q;

return 0;

}

Change char q; to string q;

Change int name; to string name;

Change getline(cin, name); to cin >> name;

Change int name; to char name;

10 points   

QUESTION 8

The following code will compile:

#include<iostream>

#include<string>

using namespace std;

char q;int main()

{

int zip1, zip2, zip3, zip4;

cout << "Enter four different zip-codes ";

cin >> zip1 >> zip2;cin >> zip3 >> zip4;

cout << " Enter a letter to exit." << endl;cin >> q;

return 0;

}

True

False

10 points   

QUESTION 9

What is wrong in the following code?

#include<iostream>

#include<string>

using namespace std;

char q;

int main()

{

int zip1, zip2, zip3, zip4;

cout << "Enter three different zip-codes ";

cin >> zip1 >> zip2 >> zip3 >> zip4;

cout << " Enter a letter to exit." << endl;

cin >> q;

return 0;

}

This code will not compile.

The compiler expect four entry while the user will enter three different numbers.

The compiler expect three entries while the user want to enter four values.

Nothing is wrong with this code.

10 points   

QUESTION 10

Write a code that:

ask the user to enter a variable, then save the user entry as x of type double.

set y = ( ( -x - sqrt(x^2 - 8*x) )/ (2 - x);

if denominator is zero then display "undefined"

else

display the value for y

Compile your code.

Test your programme with x = -1

a.

3.333

b.

3

c.

1.333

d.

10

Explanation / Answer

Ans1) 3

beacuse a/b will be an integer so value of c will get overwritten to 3

Ans2) 0

because bool test (! ((c % a == 0) || (a * b >50))); is false as c % a == 0

Ans 3) true

It will compile.

Ans4) no question posted

Ans 5) It will require iostream(for input /output) and sstream (for string functions)

Ans6)cin will stop as soon as it encounters a space thus allows you to enter only one value without any space while getline reads even spaces and allows you to enter a complete sentence with spaces

Ans 7) chnage int name to string name

because name is generally a string variable and getline(cin, var); works for strings

Ans 8) true , it will compile

Ans 9) The compiler expect four entry while the user will enter three different numbers

because as output message to user you are displaying "Enter three different zip-codes" to the use but

you are asking the complier to take 4 values : cin >> zip1 >> zip2 >> zip3 >> zip4;

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