Questions+for+Credit

C++ Questions to Answer for Credit

 * Answer any of the following questions. To receive credit, place your first intial and last name in parentheses beside the answer you give**.

 Hint: a leap year is divisible by 4. The exception are those years divisible by 100 are //not// leap years, unless they are also divisible by 400. For example, the years 1600 and 2000 are divisible by 4, 100, and 400. They were leap years. The years 1700, 1800, and 1900 were not leap years.
 * 1) Write a C++ snippet of code that will determine if a year entered is a leap year.

int yearEntered;

cout << “Enter the year: “; cin >> yearEntered;

//calculate if the year entered is a leap year


 * Answer:**

2. What is the output of the following snippet of code?

int main { const string TUNA = “tuna”; const string PICKLE = “pickle”; const string LETTUCE = “lettuce”; const string WRAP = “tortilla”;

string filling; string wrap;

filling = TUNA + “ and “ + PICKLE + “ with “ + LETTUCE; wrap = filling + “ in “ + WRAP + ‘.’; cout << “Filling : “ << filling << endl; cout << “Wrap : “ << wrap << endl;

return 0; }


 * Answer:**

3. What is wrong with the following statements?


 * 1) cin << score;
 * 2) cout >> maximum;
 * 3) cin >> “Enter data”;
 * 4) getLine(someString, cin);
 * Answer:**

4. If input data are entered as follows: 10 20 30  40 <span style="font-size: 10pt; font-family: 'Verdana','sans-serif'; mso-fareast-font-family: Verdana; mso-bidi-font-family: Verdana; msofareastfontfamily: Verdana; msobidifontfamily: Verdana; msolist: Ignore;">50 <span style="font-size: 10pt; font-family: 'Verdana','sans-serif';">60 <span style="font-size: 10pt; font-family: 'Verdana','sans-serif'; mso-fareast-font-family: Verdana; mso-bidi-font-family: Verdana; msofareastfontfamily: Verdana; msobidifontfamily: Verdana; msolist: Ignore;">70 <span style="font-size: 10pt; font-family: 'Verdana','sans-serif';">80 And the input statement that read it are cin >> a >> b >> c; cin >> d >> e >> f; cin >> a >> b; What are the contents of variables a, b, c, d, e, and f after the statements have executed?


 * Answer:**

<span style="font-size: 10pt; font-family: 'Verdana','sans-serif';">5. Given the input data

January 25, 2010

And the input statement

getline(cin, string1);

What is contained in the string variable after the statement is executed?


 * Answer:**

<span style="font-size: 10pt; font-family: 'Verdana','sans-serif';">6. Given the input data:

January 25, 2010

And the input statement

cin >> string1 >> string2;

What is contained in each of the string variables after the statement is executed?


 * Answer:**

<span style="font-size: 10pt; font-family: 'Verdana','sans-serif';">7. What does the following if statement do when the value in someInt is 77?

if (someInt <= 44 || someInt – 37 < 40) cout << “The data is within range.”; else cout << “The data doesn’t make sense”;


 * Answer:**

<span style="font-size: 10pt; font-family: 'Verdana','sans-serif';">8. Why does the following if statement always output “false” regardless of the value of someInt?

if (someInt = 0) cout << “true”; else <span style="font-size: 10pt; font-family: 'Verdana','sans-serif'; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"> cout << “false”;


 * Answer:**

<span style="font-size: 10pt; font-family: 'Verdana','sans-serif';">