CS 142 Final

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

1. Consider the following code snippet: int ctr = 0; int myarray[3]; for (int i = 0; i < 3; i++){ myarray[i] = ctr; ctr = ctr + i; } cout << myarray[2]; What is the output of the code snippet? 0 1 2 3

1

What is the output from the following code snippet? int my_fun(int perfect) { perfect = 0; return ((perfect - 1) * (perfect - 1)); } int main(){ for (int i = 0; i < 4; i++){ cout << my_fun(i) << " "; } return 0; } -1 0 1 4 1 0 1 4 0 0 0 0 1 1 1 1

1 1 1 1

What is the output of the following code snippet? list<int>numberlist; int i; for (i = 0; i< 10; i++) { numberlist.push_back(i); } list<int>::iterator p; p = numberlist.begin(); while (p != numberlist.end()) { p++; cout << *p; p++; } 13579 02468 0123456789 123456789

13579

What will be the return value of following code snippet for x = 4 and n = 4? int foo(int x, int n) { if (n == 0) { return 1; } int p = foo(x, n / 2); if (n % 2 == 0) { return p * p; } else { return x * p; } } 12 64 256 128

256

In the following code snippet, what is the value of the return statement for x = 3 and n = 3? int myfunction(int x, int n) { if (n == 0) { return 1; } return x * myfunction(x, n - 1); } 9 27 6 81

27

2. What is the output of the following code snippet? int arr[5] = { 1, 2, 3, 4, 5 }; int* ptr = arr; ptr = ptr + 2; cout << *ptr << endl; There is no output due to a compilation error. 1 2 3

3

What is the output of the following code snippet? multiset<int> mytable; multiset<int>::iterator it; for (int i = 1; i <= 8; i++) { mytable.insert(i * 10); } mytable.erase(30); mytable.erase(50); mytable.erase(60); mytable.erase(20); mytable.erase(10); for (it = mytable.begin(); it != mytable.end(); it++) { cout << " " << *it; } 10 30 40 40 30 80 10 40 50 40 70 80

40 70 80

2. Which of the following statements hold true when you want to pass an array to a function? You cannot pass an array to a function. You have to pass all the values of the array as parameters to the function. A function always receives the starting address of the array. The function cannot make changes to the array.

A function always receives the starting address of the array.

Which of the following statements is correct about a recursive function? A recursive function must call another function. A recursive function calls itself. A recursive function must be simple. A recursive function must never call another function.

A recursive function calls itself.

In the given code snippet, what type of member function is view()? class CashRegister { public: void view() const; private: int item_count; double total_price; }; void CashRegister::view() const { cout << item_count << endl; cout << total_price << endl; } Accessor member function Mutator member function Private member function Constructor

Accessor Member Function

What will be the output of the following code snippet? int i; int j; for (i = 0; i < 6; i++){ for (j = 7; j > i; j--) { cout << "+"; } cout << endl; } A rectangle with six rows and seven columns of the plus sign. The number of rows increments by one on completion of one iteration of the inner loop. A right triangle with six rows and seven columns of the plus sign. The number of columns increments by one on completion of one iteration of the inner loop. A rectangle with seven rows and six columns of the plus sign. The number of rows increments by one on completion of one iteration of the inner loop. An inverted right triangle with six rows and seven columns of the plus sign. The number of columns decrements by one on completion of one iteration of the inner loop.

An inverted right triangle with six rows and seven columns of the plus sign. The number of columns decrements by one on completion of one iteration of the inner loop.

In the following code snippet, which constructor is called for the object declaration Building bldg(500)in the code below? class Building { public: Building(); Building(int new_height); void set_height(int new_height); void view() const; private: int height; }; Building::Building() { set_height(0); } Building::Building(int new_height) { set_height(new_height); } int main() { Building bldg(500); return 0; } Building() Building(int new_height) set_height(int new_height) All of the listed items

Building(int new_height)

1. Which one of the following statements is true about passing arrays to a function? By default, arrays are passed by value to a function. Arrays when updated in a called function are not reflected to the calling function. By default, arrays are passed by reference to a function. Arrays are passed by reference using the & sign.

By default, arrays are passed by reference to a function.

What is the output of the following code snippet? int size = 2; queue<string> q; q.push("Tom"); q.push("Dick"); q.push("Harry"); q.push("Elvis"); int i = 0; while (i < size) { q.pop(); cout << q.front() << endl; ++i; } Dick Harry Dick Elvis Tom Dick Elvis Harry

Dick Harry

1. What does the code snippet below do? int num = 0; int prev = 0; istringstream iss; iss.str("010 14 082 1 15 0820 -151"); while (iss >> num) { if (num > prev) { prev = num; } } cout << prev << endl; Divides the string "010 14 082 1 15 0820 -151" into space-separated words and prints out the one that is alphabetically the smallest Divides the string "010 14 082 1 15 0820 -151" into space-separated words and prints out the one that is alphabetically the largest Divides the string "010 14 082 1 15 0820 -151" into space-separated words and prints out the one that is numerically the smallest Divides the string "010 14 082 1 15 0820 -151" into space-separated words and prints out the one that is numerically the largest

Divides the string "010 14 082 1 15 0820 -151" into space-separated words and prints out the one that is numerically the largest

The reserved word virtual is used with a base-class member function to alert the C++ compiler that it must determine the actual member function to call at run-time. Thus derived classes can have their own (possibly completely different) versions of the base-class function. When a base-class defines a member function to be virtual, what should each derived class do? Derived classes need to do nothing further Each derived class should over-ride the virtual base-class function so that it defines a function with the same name that is unique to the derived class Derived classes should invoke the base-class virtual function Derived classes should only be used as array elements

Each derived class should over-ride the virtual base-class function so that it defines a function with the same name that is unique to the derived class

2. What is the output of the following code snippet? char name[] = "Harry Houdini"; name[3] = 'v'; cout << name << endl; Harry Houdini Harvy Houdini Havry Houdini Harry Houdiniv

Harvy Houdini

2. The code snippet below creates what kind of a problem? int main() { string* myword[20]; for (int i = 0; i < 10; i++) { myword[i] = new string("YouHadMeAtHello"); } cout << *myword[15] << endl; return 0; } Off by one error Invalid pointer dereference Syntax Error Array index out of bounds

Invalid pointer dereference

Which of the following is a benefit of encapsulation? It allows a function defined in one class to be reused in another class. It guarantees that an object cannot be accidentally put into an inconsistent state. It improves the performance of an application. It prevents functions that are internal to a class from changing private data members.

It guarantees that an object cannot be accidentally put into an inconsistent state.

Consider the following C++ variable names: I. 1st_instance II. basic_in_$ III. _emp_name_ IV. address_line1 V. DISCOUNT Which of the following options is correct? Only IV is a valid C++ variable name. Only I and IV are valid C++ variable names. Only I, IV, and V are valid C++ variable names. Only III, IV, and V are valid C++ variable names.

Only III, IV, and V are valid C++ variable names.

What happens when you define the data members in a class to be private? Only the member functions of the same class can access the data members. The member functions of every class can access the data members. Only private member functions of other classes can access the data members. Only private member functions of the same class can access these data members.

Only the member functions of the same class can access the data members.

Suppose that we have a Teacher class that contains two data members - a qualification and a name string. The ScienceTeacher class inherits from Teacher. Which of the following is true? ScienceTeacher contains a qualification and a lab section but no name string. ScienceTeacher contains a lab section but not a qualification. ScienceTeacher contains both a qualification and a name string. It is impossible to know without examining the definition of the ScienceTeacher class.

ScienceTeacher contains both a qualification and a name string.

2. What does the function f do? struct Point2D { double x; double y; }; struct Triangle { Point2D v1; Point2D v2; Point2D v3; }; void f(Triangle& t) { int temp = 12.5; temp = t.v1.x; t.v1.x = t.v1.y; t.v1.y = temp; } int main () { Triangle mytri; mytri.v1.x = 1.0; mytri.v1.y = 22.5; f(mytri); } Swaps values of x and y in vertex 1 of an argument of type Triangle Initializes value of x in vertex 1 of an argument of type Triangle Sets all x,y values in all vertices of an argument of type Triangle Swaps value of x in vertex 1 with value of x in vertex 2, for an argument of type Triangle

Swaps values of x and y in vertex 1 of an argument of type Triangle

The Shape base class defines a function void set_radius(double new_radius). The Circle class inherits from the Shape base class, but does not define the set_radius function. Which one of the following is correct? The Circle class will not compile because it does not define the set_radius function. The set_radius function cannot be called on Circle objects. The Circle class overrides the set_radius function. The Circle class inherits the set_radius function.

The Circle class inherits the set_radius function.

2. Consider the following code snippet. int* age = new int; *age = 20; cout << age << endl; delete age; *age = *age * 3; cout << age << endl; Which of the following statements is correct? There is no error in the code snippet. The age pointer is being used after the memory it is pointing to has been deleted. There are compilation errors. The age pointer was never initialized.

The age pointer is being used after the memory it is pointing to has been deleted.

1. Consider the following code snippet: void check(int chknum1[], int size){ int cnt = 0; for (int i = 0; i < size; i++) { if (chknum1[i] == 0) { cnt++; } } cout << "The total 0 values in the array are: " << cnt; } Which one of the following is true about the check function in the given code snippet? The check function counts all the elements with value 0 in an array as a parameter to the function. The check function removes all the elements with value 0 from an array passed as a parameter to the function. The check function counts all the elements with value 0 in an array passed as a parameter to a function and also returns the count. The check function adds 0 to the elements of an array as a parameter to a function and also returns the array.

The check function counts all the elements with value 0 in an array as a parameter to the function.

1. Consider the following code snippet: int marks[5] = { 35, 68, 90, 45, 67 }; for (int n = 0; n <= 5; n++){ cout << marks[n] << endl; } What is the result of executing this code snippet? The code snippet does not give any output. The code snippet displays all the marks stored in the array without any redundancy. The code snippet has a bounds error. The code snippet executes an infinite loop.

The code snippet has a bounds error

What is the result of the following statement? string s = "New" + " " + "Jersey"; The string s has the following value: "New Jersey" The statement results in an error because the + operator can be used only with numbers. The statement results in an error because the + operation cannot be performed on string literals. The string s has the following value: "NewJersey"

The statement results in an error because the + operation cannot be performed on string literals

Which common error is present in the code below, which is intended to calculate the average value from a sum of numbers? double total; int n; double input; while (cin >> input) { total = total + input; n++; } if (n != 0) { double average = total / n; } Uninitialized variables Infinite loop Type mismatch Division by zero

Uninitialized variables

1. Which one of the following options can be used to store a set of values when the size of the set is not known at the time of compilation? Vectors Arrays Variables Functions

Vectors

The Department of Motor Vehicles uses a vehicle registration program that declares a Vehicle class as a base class. The Car class and the Truck class both inherit from the Vehicle class. Which types of objects can be passed to the function register(Vehicle& v)? Only Vehicle objects Only Car and Truck objects Vehicle, Car and Truck objects It is impossible to know without examining the implementation of the Car and Truck classes

Vehicle, Car and Truck objects

1. Assume that the main function definition of a C++ program ABC.cpp is int main(int argc, char* argv[]). If the ABC program is run with the following command, which of the options is true? ABC Alex Brendon Chris Roger 32 33 44 78 argc = 8 and argv[0] = "Alex" argc = 8 and argv[0] = "ABC" argc = 9 and argv[0] = "Alex" argc = 9 and argv[0] = "ABC"

argc = 9 and argv[0] = "ABC"

Which line of code should replace the placeholder symbols ? ? ? to count correctly the number of integers among the inputs that are less than 100? int count = 0; int input; while (cin >> input) { if (input < 100) { ? ? ? } } input += count; input++; count++; count += input;

count++

Which of the following loops executes the statements inside the loop before checking the condition? for while do-while None of the listed items

do-while

What is the output of the following code snippet? #include <iostream> int fun(int x){ int ret_value = 0; if (x > 5) { ret_value = x; } else { ret_value = fun(2 * x); } return ret_value; } int main(){ cout << "fun(2) = " << fun(2); return 0; } fun(2) = 4 fun(2) = 8 fun(2) = 16 fun(2) = 32

fun(2)=8

2. What is the name for the large storage area that is managed by the run-time system? stack RAM pile heap

heap

What are the values of i and j obtained after the following code fragment is run? int i = 60; int j = 50; int count = 0; while (count < 5){ i = i + i; i = i + 1; j = j - 1; j = j - j; count++; } cout << i<< endl << j; i = 65, j = 1 i = 65, j = 45 i = 1951, j = 0 i = 1951, j = 45

i = 1951, j = 0

Which of the following statements can be used to validate that the user input for the floor variable is between 0 and 20? if (floor >= 0 || floor <= 20) if (floor <= 0 && floor >= 20) if (floor <= 0 || floor >= 20) if (floor >= 0 && floor <= 20)

if (floor >= 0 && floor <= 20)

In an airline reservation system, the number of available seats in an airplane is required. Which data type should be used to store this value? double float int string

int

Which statement will correctly compute random integers between integer values a and b? int r = rand() % (b - a + 1) + a; int r = rand() % (a - b + 1) + a; int r = rand() % (b - a - 1) + a; int r = rand() % (b - a + 1) - a;

int r = rand() % (b - a + 1) + a;

1. Which code correctly swaps the integer values stored in the array data at positions first and second? int temp = data[first]; data[first] = temp; data[second] = data[first]; int temp = data[first]; data[first] = data[second]; data[second] = temp; int temp = data[first]; data[first] = data[temp]; data[second] = temp; int temp = data[first]; data[first] = data[second]; data[second] = data[first];

int temp = data[first]; data[first] = data[second]; data[second] = temp;

2. Which of the following is a legal statement to dynamically allocate memory for an array whose size is not known until run time? int size; // Assume that size is set at run time double[] darray = new double[size]; int* intarray = new int[size]; int* intptr = int[size]; It is not possible to dynamically allocate memory for an array, the size must be known at compile time.

int* intarray = new int[size];

1. Consider the variable declarations shown below. string s = "42"; int n = 0; Which of the following code snippets converts the string s to an integer n? istringstream strm; strm.str(n); str >> s; ostringstream strm; strm.str(n); str << s; istringstream strm; strm.str(s); strm >> n; ostringstream strm; strm.str(s); strm << n;

istringstream strm; strm.str(s); strm >> n;

1. Which of the following options represents a legal way of writing to a file on the basis of the code snippet provided? ofstream out_file; out_file.open("Scores.txt"); // statement to write into the file out_file >> "Peter" >> " " < 20 < endl; out_file << "Peter" << " " << 20 << endl; out_file.write_line("Peter"); out_file << 20 << endl; out_file.write_line("Peter"); out_file >> 20 >> endl;

out_file << "Peter" << " " << 20 << endl;

Study the following class definition: class Car { public: Car(double speed); void start(); void accelerate(double speed); void stop(); double get_speed() const; private: double speed; }; Which of the following options would make logical sense in the definition of the void accelerate(double speed)function? this->speed = this->speed; speed1 = this->speed; this->speed = speed; this.speed = speed;

this->speed = speed;

1. Consider the following line of code for calling a function named func1: func1(vectdata, vardata); Which one of the following function signatures is valid for func1, where vectdata is an integer vector and vardata is an integer variable? void func1(vectdata, vardata) void func1(vector<int> vectdata, vardata) void func1(vector<int> vtdata, int vdata) void func1(int vdata, vector<int> vtdata)

void func1(vector<int> vtdata, int vdata)

What is the output of the following code snippet? class CashRegister { public: void set_item_count(int count); void view() const; private: int item_count; }; void CashRegister::view() const { cout << item_count << endl; } void CashRegister::set_item_count(int count) { item_count = count; } int main() { CashRegister reg1, reg2; reg1.set_item_count(15); reg2.set_item_count(10); reg1.view(); reg2.view(); return 0; } 15 25 15 10 10 15 15 15

15 10

What is the output of the following code snippet? multiset<int> mymultiset; mymultiset.insert(41); mymultiset.insert(71); mymultiset.insert(71); mymultiset.insert(71); mymultiset.insert(15); multiset<int>::iterator it; for (it = mymultiset.begin(); it != mymultiset.end(); it++) { cout << " " << *it; } 15 41 71 15 41 71 71 71 41 71 71 71 15 41 71 15

15 41 71 71 71

1. Given the following code snippet, what is the value of the variable day? istringstream strm("16 Jan 1981"); int day = 0; string month; strm >> day >> month; 0 16 1981 No value because the code snippet cannot compile due to errors.

16

What is the output of the following code snippet? int pow(int base, int power) { int result = 1; for (int i = 0; i < power; i++) { result = result * base; } return result; } int main() { cout << pow(pow(2, 2), 2) << endl; return 0; } 4 8 16 32

16

What is the output of the following code snippet? int myfunction(int n) { if (n < 2) { return 1; } return n * myfunction(n - 1); } int main() { cout << myfunction(3) << endl; return 0; } 24 6 2 120

6

What is the output of the following code snippet? priority_queue<int> q; q.push(1); q.push(4); q.push(2); q.push(8); q.push(5); q.push(7); cout << q.top() << endl; 8 7 1 4

8

What is the output of the following code snippet? class ShoppingCart { public: void set_product_count(int count); void view() const; void view_count() const; private: int product_count; }; void ShoppingCart::view() const { for (int i = 0; i < product_count; i++) { view_count(); } } void ShoppingCart::view_count() const { cout << product_count << " "; } void ShoppingCart::set_product_count(int count) { product_count = count; } int main() { ShoppingCart shpcrt1; shpcrt1.set_product_count(8); shpcrt1.view(); return 0; } 0 8 8 8 8 8 8 8 8 8 8 8 8 The code snippet will not give any output because of a compile-time error.

8 8 8 8 8 8 8 8

Suppose myfunction is defined as follows. How many calls to myfunction are made, including the first, when myfunction(10) is executed? int myfunction(int n) { if (n <= 2) { return 1; } return n * myfunction(n - 1); } 120 9 6 10

9

ow many times will the following loop run? int i = 0; while (i < 9) { cout << i << endl; i++; } 0 8 9 10

9

Which of the following hides the implementation details of the data members and member functions within a class? Virtualization Encapsulation Inheritance Abstraction

Encapsulation

What is the output of the following code snippet if the input is "I love maps I love programming stop"? map<string, int> x; string str; while (cin >> str) { if(str == "stop") break; x[str] = x[str] + 1; } map<string, int>::iterator iter; for (iter = x.begin(); iter != x.end(); iter++) { cout << iter->first << " - " << iter->second << endl; } love - 2 I - 2 maps - 1 programming - 1 I - 2 love - 2 maps - 1 programming - 1 I - 2 love - 2 programming - 1 maps - 1 programming - 1 I - 2 love - 2 maps - 1

I - 2 love - 2 maps - 1 programming - 1

What is the output of the following code snippet? class Pet { public: Pet(string new_name); void pet_info(); private: string name; }; Pet::Pet(string new_name) { name = new_name; } void Pet::pet_info() { cout << "My name is " << name << "."; } class Cat : public Pet { public: Cat(string new_name); void pet_info(); }; Cat::Cat(string new_name) : Pet(new_name) { } void Cat::pet_info() { cout << "I am a cat."; Pet::pet_info(); } int main() { Cat cat = Cat("Felix"); cat.pet_info(); return 0; } I am a cat. My name is Felix. My name is Felix. I am a cat. My name is Felix. I am a cat.

I am a cat. My name is Felix.

1. Suppose you wrote a program that reads data from cin. You are now required to reimplement it so that you can read data from a file. You are considering the following changes. I. Declare an ifstream variable in_file II. Replace all occurrences of cin with in_file III. Replace all occurrences of >> and get_line with the appropriate operations for ifstream objects What changes do you need to make? I and II I and III II and III I, II, and III

I and II

When testing code for correctness, it always makes sense to Test all possible cases with a computer Identify boundary cases and test them Check all cases by hand Assume invalid input will never occur

Identify boundary cases and test them

Consider the following declaration for the Car class: class Car { public: Car(); void set_speed(double new_speed); double get_speed() const; private: double speed; }; The AeroCar class inherits from the Car class. For the AeroCar class to override the set_speed function, what must be done? The AeroCar class must define the function void set_speed(double new_speed) The AeroCar class must define the function void override_set_speed(double new_speed) The AeroCar class must define the function void override(string set_speed, double new_speed); The AeroCar class cannot override the set_speed function.

The AeroCar class must define the function void set_speed(double new_speed)

What will be the final output of the following code snippet when a user enters input values in the order 10, 20, 30, 40, and -1? int main(){ double sum = 0; int count = 0; double salary = 0; double average = 0; cout << "Enter salaries (-1 to stop): " << endl; while (salary != -1) { cin >> salary; if (salary != -1) { sum = sum + salary; count++; } } if (count > 0) { average = sum / count; cout << "The Average Salary: " << average << endl; } else { cout << "No data!" << endl; } return 0; } The Average Salary: 0 The Average Salary: 25 The Average Salary: 20 The Average Salary: 15

The Average Salary: 25

1. Assume that the file "Results.txt" contains the following data: Peter 90 John 80 Mary 100 Robert 40 Simon 50 Samuel 30 What is the output of the following code snippet? string name; int total = 0; double count_pass = 0; double average = 0; int scores; ifstream in_file; in_file.open("Results.txt"); while (in_file >> name >> scores) { if (scores >= 50) { total = total + scores; count_pass++; } } average = total / count_pass; cout << "The average of passed students: " << average << endl; The average of passed students: 0 The average of passed students: 90 The average of passed students: 80 There is no output due to compilation errors.

The average of passed students: 80

For the given code snippet, which of the following statements is true? double raise(double rate) { double new_pay_rate = rate * 1.1; return new_pay_rate; } int main(){ double rate = 40.0; double new_pay_rate = 0.0; new_pay_rate = raise(rate); cout << "Pay rate: " << new_pay_rate << endl; return 0; } The code snippet executes and displays "Pay rate: 40.0" The code snippet executes and displays "Pay rate: 44.0" The code snippet executes and displays "Pay rate: 0.0" There is no output because the program does not compile

The code snippet executes and displays "Pay rate: 44.0"

Consider the code snippet below: int main() { Shape* shapes[NUM_OBJECTS]; shapes[0] = new Circle(0, 0, 100, 150); shapes[1] = new Rectangle(200, 200, 50, 100); shapes[2] = new Circle(300, 50, 250, 250); shapes[3] = new Rectangle(100, 350, 200, 150); for (int i = 0; i < NUM_OBJECTS; i++) { shapes[i]->draw(draw_area); } for (int i = 0; i < NUM_OBJECTS; i++) { delete shapes[i]; } } In order for the loop to show different behavior when calling the draw function on the two different kind of objects in the shapes[] array, what must be true? The draw function must be a virtual function in the base class The objects must be aggregates of each other The objects in the shapes[] array should be unrelated to one another The shapes[] array should contain objects, not pointers

The draw function must be a virtual function in the base class

Which of the following is the correct first line for a function definition that takes two arguments of type int and returns true if the first value is greater than the second value? bool func(int a, int b) boolean func(int a, int b) int func(bool a, bool b) bool func(int a, b)

bool func(int a, int b)

Assuming that a user enters 45 as the brightness of a lamp, which of the following hand-trace tables is valid for the given code snippet? int brightness = 0; string description = ""; cout << "Please enter your lamp brightness (in watts): "; cin >> brightness; if (brightness >= 120){ description = "very bright"; } if (brightness >= 100) { description = "bright"; } else { description = "pleasant"; if (brightness <= 50) { description = "dim"; } } brightness description 0 "" 45 "pleasant" "dim" brightness description 0 "very bright" 45 "bright" brightness description 0 "" 45 "bright" "pleasant" brightness description 0 "bright" 45 "pleasant"

brightness description 0 "" 45 "pleasant" "dim"

1. Consider the following code snippet: int arr[2][3] = {{ 13, 23, 33 },{ 14, 24, 34 }}; What is the appropriate statement to display the value 24 from the given array? cout << arr[1][2]; cout << arr[2][2]; cout << arr[1][1]; cout << arr[2][1];

cout << arr[1][1];

Which of these statements ensures that myfunction terminates for all values of n in the following code snippet? int myfunction(int n) { // code goes here return myfunction(n - 1) + n * n; } if (n == 1) { return 1; } if (n < 1) { return 1; } if (n == 1) { return 1; } if (n == 0) { return 0; }

if (n == 0) { return 0; }

1. Which of the following options is the correct way to call the open function on an ifstream object named ifstr? ifstr.open() ifstr.open("data.txt") ifstreams (input file streams) ifstr.open("data.txt", "read") ifstr.open("data", ".txt")

ifstr.open("data.txt")

Which condition, when supplied in the if statement below in place of (...), will correctly protect against division by zero? if (...) { result = grade / num; cout << "Just avoided division by zero!" << endl; } (grade == 0) ((grade / num) == 0) (num == 0) (num != 0)

(num != 0)

What is the output of the following code snippet? int my_fun(int perfect) { return ((perfect - 1) * (perfect - 1)); } int main (){ for (int i = 0; i < 4; i++){ cout << my_fun(i) << " "; } return 0; } -1 0 1 4 1 0 1 4 -1 0 1 4 9 1 4 9 16

1 0 1 4


Set pelajaran terkait

CCNA1 Intro to Networks: Chapter 5 (Section 5.1.1)

View Set

Pharmacology A- test 2 with rationales

View Set

ACCT 202 - Chapter 13 Learnsmart

View Set

unit 2.03, 2.04 and 2.05 test personal finance

View Set

Exam 1:Homeostasis, genetics, fluid and electrolyte disturbance, anemia, ABG, immunity NCLEX questions

View Set