100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

COS1511 Assignment 1 (QUIZ 100% ANSWERS) 2024 - DISTINCTION GUARANTEED

Rating
-
Sold
1
Pages
39
Grade
A+
Uploaded on
26-04-2024
Written in
2023/2024

COS1511 Assignment 1 (DETAILED ANSWERS) 2024 - DISTINCTION GUARANTEED Answers, guidelines, workings and references .................... Which of the following is a valid variable name? a. 3com b. three_com c. 3_com d. ampersand& Clear my choice Which of the following statements is NOT legal? a. char ch = 'b'; b. char ch = '0'; c. char ch = 65; d. char ch = "cc"; Clear my choice Question 3 Not yet answered Marked out of 1.00 Question 4 Not yet answered Marked out of 1.00 Question 5 Not yet answered Marked out of 1.00 What is the value of x after the following statements? fl oat x; x = 15/4; a. 3.75 b. 4.0 c. 3.0 d. 60 Clear my choice What is the value of x after the following statements? int x; x = 15/4; a. 15 b. 3 c. 4 d. 3.75 Clear my choice What is the value of x after the following statements? int x; x = 15 % 4; a. 15 b. 4 c. 3 d. 3.75 Clear my choice Question 6 Not yet answered Marked out of 1.00 Question 7 Not yet answered Marked out of 1.00 What is the value of x after the following statement? fl oat x; x = 3.0 / 4.0 + 3 + 2 / 5; a. 5.75 b. 5,75 c. 1.75 d. 3.75 Clear my choice Which C++ statements correctly declare a variable called age, and prompt a user for his/her age. a. int age = 0; cout >> "Please enter your age: ; cin << age; b. int age = 0; cout << "Please enter your age: "; cin >> ages; c. int age = 0; cout << "Please enter your age: "; cin >> age; d. int ages = 0; cout << "Please enter your age: "; cin >> age; Clear my choice Question 8 Not yet answered Marked out of 1.00 Question 9 Not yet answered Marked out of 1.00 Which C++ statement is the equivalent of the following statement using a single arithmetic assignment operator? sum = sum + 47; a. sum += 47; b. sum == 47; c. sum +47; d. sum += sum; Clear my choice How should the average calculation below be modifi ed to compute the correct average of the two numbers? int num1 = 10; int num2 = 20; fl oat average = 0.0; avg = num1 + num2 / 2; a. avg = (static_cast<int>(num1) + static_cast<int>(num2)) / 2.0; b. avg = (num1) + (num2) / 2.0; c. avg = (static_cast<fl oat>(num1) + static_cast<fl oat>(num2))/2.0; d. avg = (static_cast(num1) + static_cast(num2)) / 2.0; Clear my choice Question 10 Not yet answered Marked out of 1.00 Question 11 Not yet answered Marked out of 1.00 Question 12 Not yet answered Marked out of 1.00 What is the value of x after the following statement? fl oat x; x = 3.0 / 4.0 + (3 + 2)/ 5; a. 5.75 b. 5.50 c. 1.75 d. 3.75 Clear my choice What is the value of x after the following statements? fl oat x; x = 0; x += 3.0 * 4.0; x -= 2.0; a. 22.0 b. 12.0 c. 10.0 d. 14.0 Clear my choice Which of the following is not a valid variable name? a. myDouble b. sumOf4 c. return Clear my choice Question 13 Not yet answered Marked out of 1.00 Question 14 Not yet answered Marked out of 1.00 Which of the following is not a valid variable name? a. return b. myInt c. myInteger d. total3 Clear my choice Given the following code fragment and the input value of 4.0, what output is generated? fl oat tax; fl oat total; cout << "enter the cost of the itemn"; cin >> total; if ( total >= 3.0) { tax = 0.10; cout << total + (total * tax) << endl; } else { cout << total << endl; } a. 3 b. 3.3 c. 4.0 d. 4.4 Clear my choice Question 15 Not yet answered Marked out of 1.00 Given the following code fragment and the input value of 2.0, what output is generated? fl oat tax; fl oat total; cout << "enter the cost of the itemn"; cin >> total; if (total >= 3.0) { tax = 0.10; cout << total + (total * tax) << endl; } else { cout << total << endl; } a. 2.2 b. 2.0 c. 3.1 d. 4.4 Clear my choice Question 16 Not yet answered Marked out of 1.00 Question 17 Not yet answered Marked out of 1.00 If x has the value of 3, y has the value of -2, and w is 10, is the following condition true or false? if( x < 2 && w < y) a. true && true true b. false && false false c. false && false true d. true && false false Clear my choice What is the correct way to write the condition y < x < z? a. (y < x < z) b. ((y < x) && z) c. ((y > x) || (y < z)) d. ((y < x) && (x < z)) Clear my choice Question 18 Not yet answered Marked out of 1.00 Given the following code fragment, and an input value of 3, what is the output that is generated? int x; cout << "Enter a valuen"; cin >> x; if(x = 0) { cout << "x is zeron"; } else { cout << "x is not zeron"; } a. x is zero b. x is not zero c. unable to determine d. x is 3 Clear my choice Question 19 Not yet answered Marked out of 1.00 Given the following code fragment, and an input value of 5, what is the output? int x; if( x < 3) { cout << "smalln"; } else { if( x < 4) { cout << "mediumn"; } else { if( x < 6) { cout << "largen"; } else { cout << "giantn"; } } } a. small b. medium c. large d. giant Clear my choice Question 20 Not yet answered Marked out of 1.00 Question 21 Not yet answered Marked out of 1.00 Given the following code fragment, what is the output? int x = 5; if( x > 5) cout << "x is bigger than 5. "; cout << "That is all. "; cout << "Goodbyen"; a. x is bigger than 5. That is all b. x is bigger than 5 c. That is all. Goodbye d. Goodbye Clear my choice Given the following code fragment, what is the fi nal value of y? int x, y; x = -1; y = 0; while(x <= 3) { y += 2; x += 1; } a. 2 b. 10 c. 6 d. 8 Clear my choice Question 22 Not yet answered Marked out of 1.00 Question 23 Not yet answered Marked out of 1.00 Given the following code fragment, what is the fi nal value of y? int x, y; x = -1; y = 0; while(x < 3) { y += 2; x += 1; } a. 2 b. 10 c. 6 d. 8 Clear my choice What is the output of the following code fragment? int x = 0; while( x < 5) cout << x << endl; x ++; cout << x << endl; a. 0 b. 5 c. 4 d. unable to determine Clear my choice Question 24 Not yet answered Marked out of 1.00 Question 25 Not yet answered Marked out of 1.00 What is the value of x after the following statements? int x, y, z; y = 10; z = 3; x = y * z + 3; a. not defi ned b. 60 c. 30 d. 33 Clear my choice What is the fi nal value of x after the following fragment of code executes? int x=0; do { x++; } while(x > 0); a. 8 b. 9 c. 10 d. infi nite loop Clear my choice Question 26 Not yet answered Marked out of 1.00 Question 27 Not yet answered Marked out of 1.00 Question 28 Not yet answered Marked out of 1.00 Given the following code fragment, which of the following expressions is always true? int x; cin >> x; a. if( x < 3) b. if( x = 1) c. if( x == 1) d. if( (x / 3) >1 ) Clear my choice What is the output of the following code fragment if the value of myInt is 0? int other = 3, myInt; if(myInt != 0 && other % myInt !=0) cout << "other is oddn"; else cout << "other is evenn"; a. other is even b. other is odd c. 0 d. run-time error, no output Clear my choice Which of the following are equivalent to (!(x < 15 && y >= 3))? a. (x >= 15 || y < 3) b. (x > 15 && y <= 3) c. (x >= 15 && y < 3) d. > 15 || y < 3) Clear my choice Question 29 Not yet answered Marked out of 1.00 Question 30 Not yet answered Marked out of 1.00 Which of the following boolean expressions tests to see if x is between 2 and 15 (including 2 and 15)? a. (x <= 15 || x >= 2) b. (x >= 2 && x <= 15) c. (2 <= x || x <= 15) d. (2 <= x <= 15) Clear my choice What is the output of the following code fragment if x is 15? if(x < 20) if(x < 10) cout << "less than 10 "; else cout << "largen"; a. large b. nothing c. less than 10 d. no output, syntax error Clear my choice Question 31 Not yet answered Marked out of 1.00 What is the output of the following code fragment? int i = 5; switch(i) { case 0: i=15; break; case 1: i=25; break; case 2: i=35; break; case 3: i=40; default: i=0; } cout << i <<endl; a. 15 b. 25 c. 0 d. 40 Clear my choice Question 32 Not yet answered Marked out of 1.00 Question 33 Not yet answered Marked out of 1.00 What is wrong with the following switch statement? int ans; cout <<"Type y for yes on n for non"; cin >> ans; switch (ans) { case 'y': case 'Y': cout << "You said yesn"; break; case 'n': case 'N': cout << "You said non"; break; default: cout <<"invalid answern"; } a. ans is a int b. break; is illegal syntax c. nothing d. there are no break statements on 2 cases Clear my choice Which of the following data types cannot be used in a switch controlling expression? a. int b. char c. fl oat d. enum Clear my choice Question 34 Not yet answered Marked out of 1.00 Question 35 Not yet answered Marked out of 1.00 What is the output of the following code fragment? int x = 0; { int x = 13; cout << x <<","; } cout << x << endl; a. 13,13 b. 0, 13 c. 13,0 d. 13, 0 Clear my choice What is the value of x after the following statements? int x; x = 0; x = x + 30; a. 0 b. 30 c. 33 d. not defi ned Clear my choice Question 36 Not yet answered Marked out of 1.00 Question 37 Not yet answered Marked out of 1.00 What is the output of the following code fragment? { int x = 13; cout << x <<","; } cout << x << endl; a. 13,13 b. 0,13 c. 13,0 d. nothing, there is a syntax error Clear my choice What is the value of x after the following code executes? int x = 10; if(x++ > 10) { x =13; } a. 10 b. 9 c. 13 d. 11 Clear my choice Question 38 Not yet answered Marked out of 1.00 Question 39 Not yet answered Marked out of 1.00 What is the value of x after the following code executes? int x=10; if( ++x > 10) { x =13; } a. 10 b. 9 c. 13 d. 11 Clear my choice How many times is "Hi" printed to the screen for(int i=0; i < 14; i++); cout << "Hin"; a. 13 b. 15 c. 14 d. 1 Clear my choice Question 40 Not yet answered Marked out of 1.00 Question 41 Not yet answered Marked out of 1.00 Question 42 Not yet answered Marked out of 1.00 Given the following code, what is the fi nal value of i? int i; for(i=0; i <= 4; i++) { cout << i << endl; } a. 3 b. 4 c. 5 d. 0 Clear my choice Which statement represents the condition of the if statement below when it is rewritten without using the != operator? if ( number != 50 ) a. if ( (number < 50) || (number > 50) ) b. if ( (number < =50) || (number >= 50) ) c. if ( (number < 50) || (number >= 50) ) d. if ( (number =< 50) || (number > 50) ) Clear my choice If you want a loop to quit iterating if x < 10 and y > 3, what would be the proper loop condition test? a. (x < 10 && y > 3) b. (x >10 || y < 3) c. (x >=10 && y <=3) d. (x >=10 || y <=3) Clear my choice Question 43 Not yet answered Marked out of 1.00 Question 44 Not yet answered Marked out of 1.00 Question 45 Not yet answered Marked out of 1.00 Which loop structure always executes at least once? a. do-while b. for c. while d. sentinel Clear my choice Which of the following are valid case statements in a switch? a. case 1: b. case x < 4: c. case 'ab': d. case 1.5: Clear my choice What is wrong with the following for loop? for(int i=0; i < 10; i--) { cout << "Hellon"; } a. cannot use a for-loop for this b. i is not initialized c. infi nite loop d. off-by-one error Clear my choice Question 46 Not yet answered Marked out of 1.00 What is the value of x after the following statements? int x; x = x + 30; a. 0 b. 30 c. 33 d. not defi ned Clear my choice Question 47 Not yet answered Marked out of 1.00 Given the code below, which of the following loops will continue to accept values for the variable age, and print them out, aslong as the value entered is greater than zero? int age = 0; a. cout << “Enter an age greater than zero: “; cin >> age; do //begin loop { cout << “The age entered was: “ << age << endl << endl; cout << “Enter an age greater than zero: “; cin >> age; } while (age > 0); b. cout << “Enter an age greater than zero: “; cin >> age; while (age < 0) //begin loop { cout << “The age entered was: “ << age << endl << endl; cout << “Enter an age greater than zero: “; cin >> age; } c. for (i = 0; i < 10; i++) //begin loop { cout << “Enter an age greater than zero: “; cin >> age; cout << “The age entered was: “ << age << endl << endl; } d. do //begin loop { cout << “The age entered was: “ << age << endl << endl; cout << “Enter an age greater than zero: “; cin >> age; } while (age > 0); Clear my choice Question 48 Not yet answered Marked out of 1.00 Which of the following C++ do while statements will print the numbers 1 to 10 one per line on the screen given the declarationint count = 0;? a. do //begin loop { count = count + 1; cout << count << endl; } while (count <=10); { count = count + 1; cout << count << endl; } while (count <=10); b. do //begin loop { cout << count; count = count + 1; } while (count <=10) { cout << count; count = count + 1; } while (count <=10); c. do //begin loop { count = count + 1; cout << count << endl; } while (count < 10); { count = count + 1; cout << count << endl; } while (count < 10); d. do //begin loop { cout << count << endl; count = count + 1; } while (count < 10); Clear my choice Question 49 Not yet answered Marked out of 1.00 Which code segment will display "yes" if the value stored in the variable number is between 1 and 100, inclusive (including 1and 100)? a. if ( (number > 1) && (number <= 100) ) cout << "yes" << endl; { cout << "*"; count = count + 1; } while (count <= 4); b. if ( (number >= 1) && (number <= 100) ) cout << "yes" << endl; { cout << "*"; count = count + 1; } while (count <= 5); cout << endl; c. if ( (number >= 1) && (number < 100) ) cout << "yes" << endl; { cout << "*"; count = count + 1; } while (count < 5); cout << endl; d. if ( (number > 1) && (number < 100) ) cout << "yes" << endl; { cout << "*"; count = count + 1; } while (count <= 6); cout << endl; Clear my choice Question 50 Not yet answered Marked out of 1.00 Which of the following C++ for statements display fi ve asterisks on the screen on the same line and advances the cursor tothe next line when done? a. for (int count=1; count <= 5; count = count + 1) cout << “*”; cout << endl; b. for (int count=1; count <= 5; count = count + 1) { cout << “*”; cout << endl; } c. for (int count=0; count <= 5; count = count + 1) cout << “*”; cout << endl; d. for (int count=1; count < 5; count = count + 1) cout << “*”; cout << endl; Clear my choice Question 51 Not yet answered Marked out of 1.00 Which of the following C++ code segments below displays 5 asterisks in 3 rows? a. for (int outer = 1; outer <= 5; outer = outer + 1) { for (int inner = 1; inner <= 3; inner = inner + 1) cout << "*" ; cout << endl; } b. for (int outer = 1; outer < 5; outer = outer + 1) { for (int inner = 1; inner <= 3; inner = inner + 1) cout << "*" ; } c. for (int outer = 1; outer <= 5; outer = outer + 1) { for (int inner = 1; inner < 3; inner = inner + 1) cout << "*" ; cout << endl; } d. for (int outer = 1; outer <= 3; outer = outer + 1) { for (int inner = 1; inner <= 5; inner = inner + 1) cout << "*" ; cout << endl; } Clear my choice Question 52 Not yet answered Marked out of 1.00 Question 53 Not yet answered Marked out of 1.00 Which of the following C++ code segments below displays 2 lines containing 6 asterisks each? a. for (int outer = 1; outer < 6; outer = outer + 1) { for (int inner = 1; inner <= 2; inner = inner + 1) cout << "*"; cout << endl; } b. for (int outer = 0; outer <= 2; outer = outer + 1) { for (int inner = 1; inner <= 6; inner = inner + 1) cout << "*"; cout << endl; } c. for (int outer = 1; outer <= 2; outer = outer + 1) { for (int inner = 1; inner <= 6; inner = inner + 1) cout << "*"; cout << endl; } d. for (int outer = 1; outer <= 2; outer = outer + 1) { for (int inner = 1; inner < 6; inner = inner + 1) cout << "*"; cout << endl; } Clear my choice What is the output of the following code? fl oat value; value = 33.5; cout << value << endl; a. 33.5 b. 33 c. value d. not defi ned Clear my choice Question 54 Not yet answered Marked out of 1.00 Question 55 Not yet answered Marked out of 1.00 Given the C++ instructions below, which statements will swap the contents of the variables num1 and num2. int num1 = 10; int num2 = 15; int temp = 0; a. temp = num2; num1 = num2; num2 = temp; b. temp = num1; num1 = num2; num2 = temp; c. num1 = temp; num1 = num2; num2 = temp; d. temp = num1; temp = num2; num2 = temp; Clear my choice What is the output of the following code? cout << "This is a " << endl; a. This is a b. This is a c. nothing, it is a syntax error d. This is a endl Clear my choice Question 56 Not yet answered Marked out of 1.00 Which of the following lines correctly reads a value from the keyboard and stores it in the variable named myFloat? a. cin >> myFloat; b. cin << myFloat; c. cin >> "myFloat"; d. cin >> myFloat >> endl;

Show more Read less








Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
April 26, 2024
Number of pages
39
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

COS1511
Assignment 1 (QUIZ) 2024
Unique #: 749502
Due Date: 29 April 2024



Detailed solutions, explanations, workings
and references.

+27 81 278 3372

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
VarsityC AAA School of Advertising
View profile
Follow You need to be logged in order to follow users or courses
Sold
28681
Member since
8 year
Number of followers
13258
Documents
3117
Last sold
6 days ago

4,1

2819 reviews

5
1490
4
581
3
392
2
117
1
239

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions