Computer Science Finale

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

You have a text file with integers 1 through 10 in order. You have associated that file with an input stream object infile. Consider the following code fragment while (infile >> a >> b) // a and b are integers, read two integers { infile >> a >> b; cout << (a+b); } What will be the first numeric output?

7

The binary sequence 01111100 can be converted into which hexadecimal sequence?

7C

Consider the following function. int my_func(int a) { return(a+3); } If the function is called using my_func(5), what will the function return?

8

Given the following code fragment, what is the final value of y? int x,y; x= -1; y= 0; while(x < 3) { y+=2; x+=1; }

8

Given the following code fragment, for how many iterations will the loop run? int x = 4; while(x<=12) { cout << x <<" "; x = x + 1; }

9

Which of the following is known as the stream insertion operation used by cout?

<<

Consider the following code fragment. int value=29; int* ptr1=new int; *ptr1=32; ptr1=&value; cout<<ptr1; What will be the output?

Address of value

Which of the following is a valid identifier?

All of the above

A finite sequence of precise instructions that leads to a problem solution is

An algorithm

What is the output of the following code? cout<< "Did you mean Henry O'\Henry?" << endl;

Did you meet Henry O'Henry?

If we make a mistake in the order of an arguments of the same data type in a function call, the compiler will flag it as a syntax error.

False

If x is 0, what is the value of (!x==0)?

False

The following function declaration guarantees the values in the array argument are not changed. void function1(int array[], int numElements);

False

The formatting options that were discussed for cout do not work for the output file streams.

False

A work station is more powerful than a PC and a Mainframe

False; Mainframe > Workstation > PC

Consider the following code fragment. string s1="Hello" string s2=" friend." s1+=s2; cout<<s1;

Hello friend.

Given an array of integers of size 5, how does the computer know where the 3rd index variable is located?

It adds space for 3 integers to the base address of the array

What is the output of the following code fragment? int score = 90; if(score > 90) cout <<"Great job on your" << score << "! \n"; else cout <<"Nice try on your " << score <<! \n";

Nice try on your 90.

Which Boolean operation is described by the following table? A B O T T T T F T F T T F F F

OR

The precondition(s) for a function describe:

States what is assumed to be true when the function is called

Not ending a C++ statement in a semicolon is an example of which type of error?

Syntax Error

Given the following code fragment, what is the output? char x; scanf("%c",x); printf("%c\n', &x);

Syntax error the argument in scanf %c expects a character, but x holds an integer the argument in prinft %c expects an int, but &x holds a character

Consider the following code fragment. bool my_bool=true; if(!mybool) cout<<"test"; else cout<<"Test"; What will be the output?

Test

Which of the following Boolean expressions tests to see if x is between 2 and 15 (including 2 and 15)?

(x >=2 && x <=15)

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; 40; default: i = 0; } cout << i << endl;

0

What will be the output of the following code fragment? int a=2, b=3; double c=static_cast<double>(a/b); cout<<c;

0

What are the valid indexes for the array shown below? int myArray[18];

0-17

What is the output of the following program fragment? cout << static_cast<double>(3)/4 << endl;

0.75

What is the value of x after the following statements? double x; x = 3.0 * 4.0; x-=2.0;

10.0

Consider the following code fragment: int a=3, b=5,c=8; c+=a; b*=c; What is the value of c?

11

Choose the binary equivalent of 30

11110

Consider the following function definition. void my_func(int value[ ],int size) { for (int i=0;i<size;++i) value[i]=value[i]+1; } Now consider the following code fragment that includes a call to the function. int array[5]={-1,3,7,5,14}; my_func(array,5); cout<<array[3]; What will be the output?

12

What is the difference between strcmp and strncmp?

They both compare, one expects an integer for the number of characters to compare

Functions may have multiple return statements

True

In a function with only call-by-reference parameters, any changes to the formal parameters will change the actual arguments passed to the function.

True

Secondary memory cannot be directly accessed by the processor.

True

Streams may be passed to a function

True

The new statement allows the program to allocate memory at run time.

True

The operation system is a program

True

The value inside a pointer can be updated.

True

Consider the following code-snippet. int my_var =20; int my_var2=35; my_var2=my_var; cout <<"Value is" << my_var2; What is the output on the screen?

Value is 20

The c++ keyword used to declare a character is ____.

char

Which of the following statements is NOT legal?

char ch = "bc";

It is desired to initialize a c-string ch with hello. which of the following is a correct way to do it?

char ch[]="hello";

Which of the following lines correctly reads a value from the keyboard and stores it in an already-declared float variable named myFloat?

cin >> myFloat;

Which is the correct way to use the get function to read a character from the keyboard and store it in the character variable ch?

cin.get(ch);

Consider the following code fragment with a logical error. The objective of the code is to display the word Hello five times. You'll have to write a c++ statement after the statement cout << "Hello" << endl;. Fill in the blanks with what statement will fix the error. bool my_bool = true; int count = 1; while(my_bool) { cout <<"Hello" << endl; //enter your code to correct program here if(count==5) my_bool=false; }

count++; if(count==6) my_bool=false;

Which of the following statements correct prints out the value that is in the memory address that the pointer p1 is pointing to?

cout << *p1;

Consider the following code fragment. cout << "Programming is"; cout.width(6); cout << "fun"; Rewrite the code using the setw manipulator to get the same output in a single statement. Assume iomanip.h file is already included

cout <<"Programming is" << setw(6) << "fun";

The command outFile.precision(2);

displays all floating point values sent to outfile with 2 decimal places

Write the code to declare an array of 10 doubles named grades

double grades[10];

Random Access is more common in secondary memory

false

The indexed variables (elements) of an array must be integers

false

If you need to write a function that will compute the tax on grocery store purchases, where the amount is in dollars and cents, which would be an appropriate function declaration?

float calculateTax(float amount);

Given the following string declaration, which of the following would correctly read an entire line from an input file stream named fin into a string variable named line. string line;

getline(fin,line);

Consider the following code fragment for( int i=3; i >=0; --i) { for(int j=2; j<=5; ++j) { if(j==3) break; if(i ==2) cout <<"i=""<<i<<"j="<<j<<endl; } }

i = 2 , j =2

Suppose you wanted to print something out to the screen when the value of x is between 3 and 7, exclusively( i.e., not including the 3 and the 7). How would you write the if statement?

if((3 < x) && (x <7))

In the name of the input file was in a variable named filename, which of the following is the correct way to open the input stream named inFile and associate it with this file?

inFile.open(filename);

What is NOT a correct way of declaring an array of integers?

int a ={-1,-3,9,2,13};

Which statement generates a random integer x as follows 5 < x < 11

int x = (rand() % 5) + 6 generates a number between 6-10 range = upper - lower + 1

Which header file needs to be included to use the setw function?

iomanip

Which function returns true if the character argument is a newline character?

isspace

Input devices

keyboard, mouse,

A function that is associated with an object is called a ______ function.

member

What is wrong with the following code? float scares[10], total;

nothing

What C++ stream object is associated with writing a file?

ofstream

How many addresses can a single piece of data have?

one

When is the external name of the file used in the program?

only when reading from the file

In the name of a file to open is the string variable name fileName, which of the following will correct open the file for output?

out_file.open(filenName.c_str());

Which statement will open the file data.dat for writing on the disk?

outstream.open("data.dat");

The putback function

places a character in the input stream

Consider the following code fragment. int val=35; int *ptr1=&val; int *ptr2=ptr1; *ptr2=35; Which of the following are true? Choose all correct answer

ptr1 and ptr2 are pointing at the same memory locations *ptr1 and *ptr2 have the same value

Given the following function declaration for a search function, and the following variable declarations, which of the following are appropriate function invocations for the partially filled array? const int SIZE=1000; int search(const int array[], int target, int numElements); int array[SIZE], target, numberOfElements, result;

results = search(array,target, numberOfElements);

Given an array named scores with 20 elements, what is the correct way to access the 20th element?

scores[19]

The member function setf stands for

set flag

A character array is initialized as char ch_array[20]="This is"; Write the statement using the strcat to set the value of the C-string as This is a test. Assume necessary header files have been declared.

strcat(ch_array, "a test");

What character will be in variable c after running this code? int x; char c; cin >> x; cin.get(c);

the character entered by the user

ROM is a type of main memory

true

Which C++ statement allocates run time memory for an array of 12 integers?

typedef int *ptr; ptr array; array = new int[12];

If you were to write a function for displaying the cos of an item to the screen, which function prototype would be the most appropriate?

void display(float myCost);

Which of the following function declarations will accept the following two-dimension array? int pages[10][30];

void p1(int pages[][39], int size);

Call-by-reference should be used

when the function needs to change the value of one or more arguments

Given the following code, how many times does the loop iterate? In other words, how many values of i are printed? int i; for (i = 0; i <= 4; i++) { cout << i << " " << endl; }

5

What is the value of x after the following code fragment executes? float x=36.0; x=sqrt(x);

6.0

Consider the following code fragment. int arr[3][3]={{1,2,3},{4,-2,6},{-11,7,13}} cout<<*(arr[2]+1); What will be the output?

7

Given the following code fragment, what is the output? int a = 5; double b = 2.1; double c; c = a - b; print(%.2lf\n",c);

2.90

Consider the following code fragment int num[4]={2,4,6,8}; cout<<(num[2]*num[1]); What will be the output on the screen?

24

What will be the output of the following code fragment? int func(int x) { int a=10; x=x+a; return (x); } int main () { int a=15; int x=5; cout<<func(a); return 0; }

25

Consider the following code fragment. char ch[10]="Fun"; cout<<strlen(ch); What is the output?

3

What is the value of x after the following statements? int x; x = 15 % 4

3 modulo: returns the remainder

What is the value of x after the following statement? float x; x= 3.0/4.0 + 3 + 2/5

3.75

Consider the following code fragment: int a = 10, b = 20; a+=b; What is the value of a?

30

What is the value of X after the following statements? int x; x=0; x = x+30;

30

What is the output of the following code? float value; value = 33.5; cout << value;

33.5

Consider the following code fragment enum Color{Red = 3, BLUE, GREEN}; Color my_color = BLUE; cout << my_color; What will be the output?

4

What is the output of the following program? void revise(int x, char& c) { x=27;c='B'; } int main { int a=11; char b='V'; revise(a,b); cout<<"a="<<a<<" b=""<<b<<<span" class="mceItemHiddenSpellWord">endl; return 0; }

a= 15, b= 'B' a does not change because it is a call by value in the function

The & operator is called the _____ operator.

address of

What is the name of the function to convert from a c-string that contains only digits to an integer?

atoi

A single digit that can hold a zero or a one is known as a

bit

What will be the output of the following code fragment? char ch=tolower('D'-1); cout<<ch;

c


Ensembles d'études connexes

Maternal Child 42 Cardiovascular Dysfunction

View Set

Important time marks for development (WCC)

View Set

Digital Forensics - Module 5 - Working with Windows and CLI Systems

View Set

Gynecologic Emergencies Ch.24 Hw

View Set

AIS-Ch.4: Relational Databases and Enterprises

View Set

High Performance Computing and Distributed Systems

View Set

La Division Celular - Notre 1er examen-7mo

View Set

MRU24.3: Video Activity: Moral Hazard

View Set

Los 21 Países, Las Capitales y Nacionalidades de Habla Español

View Set

CNA 210 | Ch. 4, Advanced Cryptography and PKI

View Set