• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 3 out of 18 pages
Exam (elaborations)

CSCI 240 Final Exam Questions with Correct Solutions Latest Version (Rated A+)

Document preview thumbnail
Preview 3 out of 18 pages

CSCI 240 Final Exam Questions with Correct Solutions Latest Version (Rated A+) The class X contains two data members: an integer called xVal and a float called xPerc. Which of the following is NOT a valid prototype for the class definition for X? a. void X( int, float ); b. void setxVal( int ); c. float getxPerc(); d. X( int, float ); e. void printX(); - Answers a. void X( int, float ); An instance of a class is known as a/an __________. a. variable b. method c. object d. thing - Answers c. object The :: operator is used to associate a method with a specific class. a. true b. false - Answers a. true Which of the following statements (a-d) about classes is true? a. A class can contain both data members and methods b. The members of a class may be private or public c. The name of the constructor is always the same as the name of the class d. The class definition contains prototype statements for the methods e. All of the statements (a-d) are true. - Answers e. All of the statements (a-d) are true. If a string will need room for 25 characters, how should it be defined so that it will be a valid string? a. char str[25]; b. char str[24]; c. char str[26]; d. char str[]; - Answers c. char str[26]; Which of the following string functions will ALWAYS produce a valid string after execution? a. strcpy b. strcat c. Both of the functions (a-b) will produce a valid string - Answers c. Both of the functions (a-b) will produce a valid string The null terminator is __________. a. used to advance to a new line when executing a cout statement b. represented as '0' c. used to end a valid string d. a movie starring Arnold Schwarzenegger e. All of the statements (a-d) are correct f. Only statements b and c are correct - Answers f. Only statements b and c are correct. Which of the following is the correct definition for a variable called dblRef that can hold a reference to the double variable dblNum? a. double dblRef = dblNum; b. double *dblRef = &dblNum; c. double &dblRef = dblNum; d. double &dblRef; - Answers c. double &dblRef = dblNum; Which of the following statements (a-d) are true if the following lines of code are executed? int G = 17; int &H = G; a. H is now an alternate name for G b. Adding 1 to H will change the value of G to 18 c. Subtracting 5 from G and printing H will display the value 12 d. The condition H == G will give a true result e. All of the statements (a-d) are true - Answers e. All of the statements (a-d) are true What will be displayed by the following code? int main() { int num[5] = { 2, 4, 6, 8, 10 }; int i; fn(num); for( i = 0; i 5; i++ ) cout num[i] ' '; return 0; } int fn( int n[] ) { n[3] = n[3] + 1; } a. The code will not display anything b. 2 4 6 8 10 c. 2 4 7 8 10 d. 2 4 6 9 10 e. There is not enough information provided to determine what will be displayed. - Answers d. 2 4 6 9 10 The following is a valid array definition. int ar[]; a. true b. false - Answers b. false Which of the following "chunks" of C++ code will print the contents of an array called ar that has been defined to hold 25 integer values and has been initialized with 25 integer values? int i; a. cout ar[]; b. for( i = 0; i == 25; i++ ) cout ar[i] " "; c. for( i = 0; i 25; i++ ) cout ar[i] " "; d. for( i = 0; i 25; i++ ); cout ar[i] " "; - Answers c. for( i = 0; i 25; i++ ) cout ar[i] " "; Which of the following statements (a-d) about Table is true? float Table[] = { 0.9, 0.8, 0.7, 0.6 }; a. The definition for Table will cause an error because there is no value specified inside of the square brackets b. Table[1] contains the value 0.9 c. There are actually 5 values stored in Table - the four listed and a null terminator as the fifth element d. The definition for Table will cause an error because an array cannot be initialized when it is created e. All of the statement (a-d) are false - Answers e. All of the statement (a-d) are false What is the subscript of the last element in the array Table if it is defined as follows? float Table[30]; a. 30 b. 31 c. 29 d. 0 e. none of the above - Answers c. 29 What will be displayed by the following code? int main() { int num = 3; fn(num); cout num; return 0; } void fn( int n ) { n++;

Content preview

CSCI 240 Final Exam Questions with Correct Solutions Latest Version 2024-2025 (Rated A+)

The class X contains two data members: an integer called xVal and a float called xPerc. Which of the
following is NOT a valid prototype for the class definition for X?



a. void X( int, float );

b. void setxVal( int );

c. float getxPerc();

d. X( int, float );

e. void printX(); - Answers a. void X( int, float );

An instance of a class is known as a/an __________.



a. variable

b. method

c. object

d. thing - Answers c. object

The :: operator is used to associate a method with a specific class.



a. true

b. false - Answers a. true

Which of the following statements (a-d) about classes is true?



a. A class can contain both data members and methods

b. The members of a class may be private or public

c. The name of the constructor is always the same as the name of the class

d. The class definition contains prototype statements for the methods

e. All of the statements (a-d) are true. - Answers e. All of the statements (a-d) are true.

,If a string will need room for 25 characters, how should it be defined so that it will be a valid string?



a. char str[25];

b. char str[24];

c. char str[26];

d. char str[]; - Answers c. char str[26];

Which of the following string functions will ALWAYS produce a valid string after execution?



a. strcpy

b. strcat

c. Both of the functions (a-b) will produce a valid string - Answers c. Both of the functions (a-b) will
produce a valid string

The null terminator is __________.



a. used to advance to a new line when executing a cout statement

b. represented as '\0'

c. used to end a valid string

d. a movie starring Arnold Schwarzenegger

e. All of the statements (a-d) are correct

f. Only statements b and c are correct - Answers f. Only statements b and c are correct.

Which of the following is the correct definition for a variable called dblRef that can hold a reference to
the double variable dblNum?



a. double dblRef = dblNum;

b. double *dblRef = &dblNum;

c. double &dblRef = dblNum;

, d. double &dblRef; - Answers c. double &dblRef = dblNum;

Which of the following statements (a-d) are true if the following lines of code are executed?



int G = 17;

int &H = G;



a. H is now an alternate name for G

b. Adding 1 to H will change the value of G to 18

c. Subtracting 5 from G and printing H will display the value 12

d. The condition H == G will give a true result

e. All of the statements (a-d) are true - Answers e. All of the statements (a-d) are true

What will be displayed by the following code?



int main()

{

int num[5] = { 2, 4, 6, 8, 10 };

int i;



fn(num);



for( i = 0; i < 5; i++ )

cout << num[i] << ' ';



return 0;

}

Document information

Uploaded on
December 27, 2024
Number of pages
18
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$8.79

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

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.
TutorJosh
3.5
(76)
Sold
496
Followers
16
Items
32874
Last sold
19 hours ago




Why students choose Stuvia

Created by fellow students, verified by reviews

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

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

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

Student with book image

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

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions