Comp Sci

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

You can create a comment block by starting it with

/*

What signals to the compiler to ignore what comes after it on the rest of that line only?

//

What is in x at the end of this code? int x = 10; int y = 20; int z = 30; x = y = z = 0;

0

What is the index value of the first element in an array?

0

How many times will the word "HELLO" be printed to the screen in the code below? int main() { bool RUN = false; do { cout << "HELLO"; } while (RUN); }

1

What will be the value of A in the code below? int main() { double A; A = 9 / 5; }

1

What will be the value of A in the code below? int main() { int A; A = (7.0 * 3.0) / 2.0; }

10

What will the output from the following code be? int myarray[5], i, sum; for (i=0; i<5; i++){ myarray[i]=i; } for (i=0; i<5; i++){ sum+= myarray[i]; } cout<<sum;

10

What is the output of the following code fragment? int y = 30; int main() { y = 10; mystery(); cout << y << endl; } void mystery() { int y; y = 100; cout << y << ","; }

100,10

What is the value of the following expression? 7 * 3 + 8 - 9 * 2

11

Using the following statement what is output from the following cout<<setprecision(3)<<1234.56789<<" "<<98.87432<<endl;

1234.568 98.874

How many times will "OUT" be printed to the screen with the code below? int main() { int i = 0; int VALS = 130; while (i < VALS) { cout << "OUT"; i++; } }

130

What is printed to the screen in the code below? int getValue(int d) { d = 55; return d; } int main() { int data = 15; getValue(data); cout << data; }

15

What is the output of the following function call? //function body int mystery(int n) { int sum = 0, i; for (i = n; i < 10; i+= 2) { sum = sum + i; } return sum; } //function call cout << mystery(4);

18

Suppose the array grades has the following values: 0 17 1 55 2 14 3 38 4 83 5 16 6 29 What is the output of the following code? x = 0; for (i = 0; i < 7; i++) { if (grades[i] > 50) x += 1; } cout << x;

2

What will be the value of A in the code below? int main() { int A = 7; int B = 5; A = A % B; }

2

void func(int a) { a = 777; } int main() { int a = 222; func(a); cout << a; }

222

Assuming the executable file is called "./Lab1", what would be output to the screen below given the following command line? ./Lab1 Hello World int main(int argc, char *argv[]) { cout << argc << " " << argv[0] << endl; }

3 ./Lab1

What does the following expression evaluate to? 2 + 7 * 8 / 2

30

What is printed to the console with the following code? int myarray[] = {1, 2, 3, 4, 5, 6}; cout << myarray[3] << endl;

4

What is output to the console in the code below? struct MyStruct { int a; }; int main() { MyStruct s; int a = 55; s.a = 77; cout << a << endl; }

55

What is output to the screen with the code below? void myfunc(int &a) { a = 55; } int main() { int a = 77; myfunc(a); cout << a; }

55

What will the output from the following code be? int myarray[4], i, sum=0; for (i=0; i<4; i++){ myarray[i]=i; } for (i=0; i<4; i++){ sum+= myarray[i]; } cout<<sum;

6

int main(){ int i = 7; int j = 13; int k = 15; ofstream fout; fout.open("myfile"); fout << i << " " << j << " " << k; fout.close(); } What will the file "myfile" contain after this program runs?`

7 13 15

Assume the user inputs the following to the program: 7 9 8 What would be the value of C in the code below? int main() { int A, B, C; cin >> A >> B >> C; }

8

How many bits are in a byte?

8

What is printed to the screen with the following code? int getValue(int j, int k) { return j % k; } int main() { cout << getValue(30, 11); }

8

The following expression A *= 7; Is short hand for which expression?

A= A*7

Given the following input, what will be printed to the console? Hello My Darling Hello My Pal const int MAX_STRINGS = 6; string myarray[MAX_STRINGS]; for (int i = 0;i < MAX_STRINGS;i++) { cin >> myarray[i]; } cout << myarray[2];

Darling

cout stands for "Console Output" which means

Data FROM the computer (memory) TO the user (monitor)

cin stands for "Console In" which means

Data FROM the user (keyboard) TO the computer (memory)

Examine the following code: int main() { ofstream fout; fout.open("myfile.txt"); return 0; } Where is the file "myfile.txt" located after this program runs?

Either in the current working directory (e.g. the debug folder for code lite) or it doesnt exist because it wasnt closed

Under what conditions will the following code output "Unable to open output file" to the console? int main() { ofstream fout; fout.open("myfile.txt"); if (fout.fail()) { cout << "Unable to open output file" << endl; } }

If the file "myfile.txt" is empty.

Given the following file "myfile": John Jason Pi Radians Lo Behold Kuy Lza What will be printed to the console in the following code? int main() { ifstream fin; string line; fin.open("myfile"); getline(fin, line); cout << line; }

John Jasons

Given the following code: class Johnny { int z; public: void setZ(int _z); }; How would I declare a new instance of the "Johnny" class and name it john?

Johnny john;

Which of the following best demonstrates how to declare an instance of a class called MyClass using the zero argument constructor?

MyClass c;

53 Which of the following choices best demonstrates how to define a zero argument constructor?

MyClass::MyClass(){ }

Question 44 0 pts Will the following code compile successfully? class MyClass { int someVariable; public: int getVariable() const; }; int main() { MyClass m; m.someVariable = 55; return 0; }

NO

What does the following code print to the console? int myarray[3] = {1, 2, 3}; cout << myarray[3] << endl;

Nothing program will crash

What does ofstream mean?

Output File Stream

Given the following class: class MyClass { public: MyClass(); MyClass(int, string); }; What is the function MyClass() called?

The zero argument constructor

Given the following code, what be printed to the screen? class MyClass { public: int m_rabid; MyClass(int _is_rabid) { m_rabid = _is_rabid; } }; int main() { MyClass m; cout << m.m_rabid << endl; }

This code will not compile since the C++ provided constructor is no longer provided when the programmer specifies a constructor

The programmer tells the computer how to interpret the bytes in RAM.

True or False

In the following statement where does the result value get stored? a=b+c;

a

What is the data type of argv[1] given below assuming the following command line: ./Lab1 11 22 33 int main(int argc, char *argv[]) { cout << argv[1]; }

a c-style string??

The output from a linked program is

an .exe file (executable code) or source code

In the following code, what is the purpose of argc? int main(int argc, char *argv[]) { }

argc is used to tell the operating system that the user is using command line arguments

What type of values may be returned by the following function? char getValue(int min, string max, double avg);

char

If a memory location had the following bits what might they represent - select all possible correct answers. 11001001

char whole number

What member function of ofstream writes the data to the actual file?

close()

Every program begins with

compiler directives (#include)

A for loop contains four parts: Initializer, Condition, Step (or Update), and Loop Body. Given the following for loop: for (A; B; C) { D } What is the part, identified by B, known as?

condition

Which of the following contain escape sequences?

cout<<"hello\n"; cout<<"hello\t good bye";

If you enter more data values than needed the extra values

create problems for the next program

What data type is returned by the function prototype below? double func(int a);

double

Which of the following statements declares an array named friends that has 40 double elements?

double friends[40];

If you need a function to compute the average of two doubles and return a double, which of the following function prototypes should be used?

double getAverage(double number1, double number2);

The output from a compiler is an executable program

false

When using an IO manipulator, if you use the setw command it will persist until a new setw is used.

false

When you input values prompts are automatically displayed telling the user what to enter.

false

Will the following code compile? cin>>"my input">>myinput;

false

Will the following code compile? cin>>myvar>>endl;

false

Will the following code compile? cout>>"my output">>endl;

false

cout causes results values to be printed to a printer

false

if you have two strings a and b and concatenate them, the results will be that b will replace a

false

Convert the following while loop into a for loop: int i = 1; while (i < 10) { cout << i << endl; i *= 3; }

for (int i = 1;i <10;i *= 3) { cout << i << endl; }

The following code is called a/an? int MyFunction(int, double);

function prototype

Given the following code, what will be printed to the console? int sum; int myarray[] = {1, 2, 3, 4, 5}; for (int i = 0;i < 5;i++) { sum += myarray[i]; } cout << sum;

garbage

Given the following declarations, which of the following statements is not a valid function call (i.e., the compiler will flag it as an error)? string getLabel(int temperature); string label;

getLabel(5) = label;

What task is accomplished by the following code? x = 0; for (i = 0; i < 9; i++) { if (weights[i] < weights[i+1]) x++; } cout << x;

it prints a count of the number of elements in grades that are less than their adjacent, right hand neighbor

Given the following code: class { int a, b; public: void setA(int a); }; setA is called what?

member function

If there are n elements in an array what is the subscript of the last element in the array?

n-1

Is the following member function an accessor? class MyClass { public: int getValue(); };

no

Will an ifstream create a file that doesn't already exist when it is opened?

no

Will the following code compile? int main() { const int A = 77; cout << "Enter a value: "; cin >> A; return 0; }

no

Will the following code compile? int myarray[]; for (int i = 0;i < 3;i++) { cin >> myarray[i]; } cout << myarray[0];

no

Suppose I have the following declaratiion: bool photo[100][100]; How can I assign the value false to row 56, column 81?

photo[55][80] = false;

In the following what tells the program to stop executing and go back to the OS. int main() { // program instructions return 0; }

return 0;

A constructor is automatically called when an object is declared.

right

An output file stream will automatically create or overwrite a file when opened.

right

If the user doesn't specify private or public inside of their class, the member variables and member functions are by default private.

right

The input to the compiler is

source code

string getSomething(int a, char b, double c); What data type can be returned by this function?

string

Suppose I have the following array named scores: 86 73 [42] 51 68 [72] 91 49 Which of the following statements will add the two elements highlighted in yellow and assign them to the variable named sum?

sum = scores[2] + scores[5];

Input data comes in as a stream delimited by

tabs

What will the output from the following code be? int myarray[3], i; for (i=0; i<=3; i++){ myarray[i]=i; } cout<<myarray[1];

the program crashes because the index is out of bounds

Each location in RAM has its own address

true

The difference between a class and a struct is that a class' members are by default private and a struct's members are by default public.

true

The mod operator gives the remainder from a division.

true

The purpose of comments is to explain what the program is doing -- not what individual instructions do.

true

The user gives command to the operating system to run a program

true

You must check the value of argc before using argv since the program may crash if you exceed the bounds of argv.

true

argv is an array of c-style strings

true

Given the following code: class James { int a; public: void setValue(int val); }; If I used the member function "setValue", what variables can I use when I write its member function definition without declaring any new variables?

val and a

An input file stream will create a file if it doesn't already exist

wrong

ofstream means "Output File Stream" which means data coming from the file to the program.

wrong

Will the following code compile successfully? #include <string> using namespace std; struct MyStruct { string first, last; }; int main() { MyStruct s; s.first = "Hello"; return 0; }

yes

Can you use I/O manipulators with File streams?

yes without exception

In the following what tells the compiler to stop compiling the main program. int main() { // program instructions return 0; }

} or return 0;


Set pelajaran terkait

Personal Finance (The Stock Market)

View Set

Chapter 6 Social & Personality Development in Infancy

View Set

Biology 116 Chapters 17 and 18 Learning Outcomes

View Set

Interpersonal Communications Chapters 7-12

View Set

Romantic to Classic Ballet 18th/19th Century Dance in Russia

View Set

Varcarolis: Chapter 27 - Anger, Aggression, and Violence

View Set

Renal, Urinary, Reproductive system

View Set

McGraw Hill Connect: Class Activity 5 (Digestion)

View Set