Quiz 1-4

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which of the following operators compare using short-circuit evaluation? (More than one answer is possible). & == ++ && ||

&& ||

What is the value of the variable post at the end of the given code snippet? int post = 3; post = post - 2 * post; post++;

(-2)

Which of the Boolean expressions below is incorrect? You can assume x has been declared and assigned some integer value. (true) && (3 => 4) (x > 0) || (x < 0) (-10 < x < 0) !(x > 0) && (x > 0) (x != 0) || (x = 0)

(true) && (3 => 4) (-10 < x < 0) (x != 0) || (x = 0)

Which of the following is not a logical operator? - | - && - / - <> - <= - !

- / - <> - <=

Which of the following is not a legal C# identifier? - printSalesReportButton clear_all_the_customer_names_button - _calculateTotalButton - 1stPlayer - three Apples - printSalesReportButton clear_all_the_customer_names_button

- 1stPlayer - three Apples

which of the following is not a method in the Math class? - Sqrt - Pow - Random - Sin - Ln - Cot

- Random - Ln - Cot

In order to succeed in this course you need to _______________ (More than one answer is possible).

- Submit all labs and projects on time. - Examine very carefully all examples from the text and do the tutorials in the text. - Do the homework assignments. - Read lessons 0-7 and chapters 1-8 from the text. - Take the quizzes and exams at specified dates and time.

Which of the following are predefined data types in C#? - object - long - string - sbyte - char - boolean

- object - long - string - sbyte - char

The range of byte data type in C# is _________?

0 to 255

What is the output from Console.WriteLine(Math.Sin(Math.PI/2));?

1

What is the output of the following code snippet? int i = 1; while (i < 20) { Console.Write(i + " "); i = i + 2; if (i == 15) { i = 19; } }

1 3 5 7 9 11 13 19

Which of the following statements is incorrect? You can assume that i, j, and k have been declared with int i, j, k; (More than one answer is possible). 1 = i = j = k; i = 1; j = 1; k = 1; i == j == k == 1; i = 1 = j = 1 = k = 1; i = j = k = 1;

1 = i = j = k; i == j == k == 1; i = 1 = j = 1 = k = 1;

What is the output of the following code snippet? int num = 100; if (num < 100) { if (num < 50) { num = num - 5; } else { num = num - 10; } } else { if (num > 150) { num = num + 5; } else { num = num + 10; } } Console.WriteLine(num);

110

C# has a predefined data type decimal. How many bits are allocated for this type and what suffix must be used when assigning literal decimal numbers to it?

128, m

What is the value of the cost variable after the following code snippet is executed? int cost = 82; if (cost < 100) { cost = cost + 10; } if (cost > 50) { cost = cost * 2; } if (cost < 100) { cost = cost - 20; }

184

What values does counter variable i assume when this loop executes? for (int i = 20; i >= 2; i = i - 6) { Console.Write(i + ", "); }

20, 14, 8, 2,

Assuming that a user enters 25 as the value for x, what is the output of the following code snippet? int x; Console.WriteLine("Enter a number: "); x = Convert.ToInt32(Console.ReadLine()); if (x < 100) { x = x + 5; } if (x < 500) { x = x - 2; } if (x > 10) { x++; } else { x--; } Console.WriteLine(x);

29

How many times is the text "Let's have fun with Java." printed when this code snippet is run? int i = 0; do { Console.WriteLine("Let's have fun with C#."); i++; if (i % 2 == 0) { i = 10; } } while (i <= 10);

3

What is the result when the following code is run? double x = 1; double y = 1; int i = 0; do { y = x / 2; x = x + y; i = i + 1; } while (x < 2.5); Console.Write(i + " ");

3

There are _____ projects and ______ quizzes to be completed individually for the course. All of them together account for _______% and _______% respectively of the course grade.

3, 6, 30, 20

What does the following code snippet print? int a = 120; int b = 90; int n1 = Math.Abs(a); int n2 = Math.Abs(b); int result = 1; for (int k = 1; k <= n1 && k <= n2; k++) { if (n1 % k == 0 && n2 % k == 0) { result = k; } } Console.WriteLine(result);

30

What is the output when the following recursive method is called with redo(44,3): public static int redo(int i, int j) { if(i == 0) return 0; else return redo(i/j, j) + 1; }

4

What is the result of the following expression? 17 % 3 * 2 - 12 + 15 + Math.Pow(8, 1/3);

8

How many times does the code snippet given below display "Loop Execution"? int i = 1; while (i != 10) { Console.WriteLine("Loop Execution"); i++; }

9

How many times will the output line be printed in the following code snippet? for (int num2 = 1; num2 <= 3; num2++) { for (int num1 = 0; num1 <= 2; num1++) { Console.WriteLine("" + num2 + " " + num1); } }

9

What is the last output line of the code snippet given below? int i = 0; while (i < 10) { int num = 1; for (int j = i; j > 1; j--) { Console.Write(j + " "); num = num * 2; } Console.WriteLine("***"); i++; }

9 8 7 6 5 4 3 2 ***

The honorable title of father of Artificial Intelligence, a field in Computer Science, is given to ___________________.

Alan Turing

A(n) ______________ describes a set of well-defined logical steps that must be taken to perform a task.

Algorithm

How many times does the following loop execute? for (double d = 1; d != 10; d++) { d = d / 3; Console.Write(d + " "); }

An infinite number of times

________ is not an object-oriented programming language.

C

The ________________ is the part of a computer's hardware that executes each instruction in a program.

CPU

What happens when you declare: int number = 10000 x 10000 x 10000; (pretend x is really *, quizlet wont let it display) Console.WriteLine(number);

Compilation error: The result of 10000 x 10000 x 10000 is too large to be stored in an int variable number.

A _______ is a method that executes when a specific event such as clicking the mouse takes place while an application is running.

Event handler

All labs are already solved and video recorded. All I have to do is follow the Panopto video walkthrough recordings in Canvas Modules to complete and submit them before dues dates. They are optional and not required to turn in. Isn't that fabulous?

False

This is an asynchronous 100% online class with regular Zoom meetings scheduled at 10:30 AM-11:20 PM MTWTh

False

Assuming that the user enters 60 as the input, what is the output after running the following code snippet? int num = 0; Console.Write("Enter a number: "); num = Convert.ToInt32(Console.ReadLine()); if (num < 10) { Console.WriteLine("Too small!"); } else if (num < 50) { Console.WriteLine("Intermediate!"); } else if (num < 100) { Console.WriteLine("High!"); } else { Console.WriteLine("Too high!"); }

High!

Which of the following loop(s) could possibly not enter the loop body at all? |. for loop ||. while loop |||. do loop

I and II only

Which loop does not check a condition at the beginning of the loop? |. The do loop ||. The while loop |||. The for loop

I only

Graded assignments for the course include ___________________ (More than one answer is possible).

Labs, Projects, Midterm, Final, Quizzes

The following code snippet contains an error. What is the error? int cost = 70; if (cost > 100); { cost -= 10; } Console.WriteLine("Discount cost: " + cost);

Logical error: if statement has do-nothing statement after if condition

What will be the output in the following switch statement if the user input for day was 9? Console.Write("Enter the day of the week (1-7): "); int day = Convert.ToInt32(Console.ReadLine()); switch (day) { default: Console.WriteLine("Looking forward to the Weekend"); break; case 6: Console.WriteLine("Today is Saturday"); break; case 7: Console.WriteLine("Today is Sunday"); break; }

Looking forward to the Weekend

Which of the following statements correctly displays the text Hello in a message box?

Messagebox("Hello");

What is the output of the code snippet given below? String s = "12345"; int i = 1; do { if (i > 1) { System.out.print(s.substring(i, i + 1)); } } while (i < 5);

No output (infinite loop)

What will be the output of the following code snippet? boolean token = false; while (token) { Console.WriteLine("Hello"); }

No output because of compilation error.

The ______ file contains an application's start-up code which executes when the application runs.

Program.cs

When you create a Visual C# application, use the _____________ window to examine and change a control's properties.

Properties

Analyze the following code. bool even = false; if (even = true) { Console.WriteLine("It is even!"); }

The code displays It is even!

What is the problem with the following if statement? double count = 15.0; if (count / 3) { Console.WriteLine("The value of count is "); }

The condition does not evaluate to a Boolean value

Analyze the following code. (More than one answer is possible) class Program { static void Main(string[] args) { int i = 0; for (i = 0; i < 10; i++); System.out.println(i + 4); } }

The program compiles despite the semicolon (;) on the for loop line, and displays 14. The for loop in this program is same as for (i = 0; i < 10; i++) { }; System.out.println(i + 4);

What is the output of the following code fragment? int i = 1; int sum = 0; while (i <= 11) { sum = sum + i; i++; } Console.WriteLine("The value of sum is " + sum);

The value of sum is 66

What is the output of the following code snippet? bool passed = false; String someStr = "Unknown"; passed = !(passed); if (!passed) { someStr = "False"; } if (passed) { passed = false; } if (!passed) { someStr = "True"; } else { someStr = "Maybe"; } Console.WriteLine(someStr);

True

_______________ is an extensive encoding scheme that is compatible with ASCII and can also represent the characters of many of the world's languages.

Unicode

Required but free software for the class include: _______________________ (More than one answer is possible).

VS 2017, VS 2019

In the following code snippet, when does the execution of the program switch from the inner loop to the outer loop? int i; int j; for (i = 0; i <= 9; i++) { for (j = 1; j < 5; j++) { Console.WriteLine("Hello"); } }

When the value of j becomes 5

What is the output of the following code snippet? String someString1 = "his"; String someString2 = "cycle"; if (someString1.CompareTo(someString2) > 0) { Console.WriteLine(someString2); } else { Console.WriteLine(someString1); }

cycle

Which of the following assignment statements is illegal? ushort s = 10; decimal d = 64.8; float f = -34.9; int t = 23; double flag = true;

decimal d = 64.8; float f = -34.9; double flag = true;

The ________________ method parses a string s to a double value.

double.Parse(s);

Because GUI programs must respond to the actions of the user, they are said to be ______________.

event-driven

These days we write code for computers to execute in ____________.

high-level language

What are the values of i and j after the following code fragment runs? 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++; } Console.WriteLine("i=" + i + ", j=" + j);

i = 1951, j = 0

Suppose the input for number is 9. What is the output from running the following program? class Program { static void Main(string[] args) { Console.Write("Enter an integer: "); int number = input.nextInt(); int i; bool isPrime = true; for (i = 2; i < number && isPrime; i++) { if (number % i == 0) { isPrime = false; } } Console.WriteLine("i is " + i); if (isPrime) Console.WriteLine(number + " is prime"); else Console.WriteLine(number + " is not prime"); } }

i is 4 followed by 9 is not prime

Which of the following options is a legally correct expression for inverting a condition? You may assume that variable--a has been declared as an integer and assigned some value appropriately. if (a ! 10) if (a !== 10) if (!(a == 10)) if (!a == 10) if(!(a <> 10))

if (!(a == 10))

Which of the following options checks that city is neither Chicago nor Dallas? You may assume city has been declared as string and assigned some value appropriately.

if (!(city.Equals("Chicago") || city.Equals("Dallas")))

What is the conditional required to check whether the length of a string s1 is odd?

if ((s1.Length() % 2) != 0)

Consider the following code snippet: bool attendance = true; bool failed = false; Which of the following if statements includes a condition that evaluates to true? (More than one answer is possible). if (!failed) { . . . } if (attendance) { . . . } if (attendance == "true") { . . . } if (failed == false) { . . . } if (attendance == failed) { . . . }

if (failed == false) { . . . } if (attendance) { . . . } if (!failed) { . . . }

Suppose one needs an if statement to check whether an integer variable pitch is equal to 440. You can assume that the variable pitch has been declared and assigned some value appropriately. Which condition is correct?

if (pitch == 440)

What is the output of the code fragment given below? int i = 0; int j = 0; while (i < 27) { i = i + 2; j++; } Console.WriteLine("j=" + j);

j=14

A(n) ______________ is a mistake that does not prevent a program from starting but causes it to produce incorrect results.

logic error

Instead of using binary numbers for instructions, assembly language uses short words known as ______________.

mnemonics

What is the number of iterations in the following loop? for (int i = 1; i <= n; i++) { // iteration }

n

How do you extract the last name from the following declaration? string name = "Alex Morgan";

name.Substring(5, 6);

The data stored in an object are commonly called fields or _____________.

properties

An algorithm written out in plain English (or another language) statements is called _________________.

pseudocode

Assume the declaration var rand = new Random(); Which of the following is correct for simulating the toss of a pair of coins to get 0 (head) or 1 (tail)?

rand.Next(2) + " " + rand.Next(2);

When assigning a literal to a variable of the byte type, if the literal is too large to be stored as a byte value, it _____.

recieves a compile error

In Visual Studio each Visual C# application you create is called a ________________.

solution

The signature of the main method in a console application in C# is ___________________.

static void Main(string[] args);

Suppose s1 and s2 are two strings. Which of the following statements or expressions is incorrect? (More than one answer is possible). string s3 = s1 - s2; char c = s1[0]; char c = s1.charAt(s1.length()); int s = s1.length + s2. length; bool b = s1.compareTo(s2);

string s3 = s1 - s2; char c = s1.charAt(s1.length()); int s = s1.length + s2. length; bool b = s1.compareTo(s2);

A(n) ______________ is a mistake such as a misspelled keyword, a missing punctuation character, or the incorrect use of an operator.

syntax (compiler) error

To close an application's form in code, use ______ statement.

this.Close();

The absolute best way to get help in the course is _________________.

to attend the Zoom sessions

The ______ directives that appear at the top of a C# source code file indicate which namespaces the program will use.

using

What is the output of the following code? int x = 0; if (x < 4) { x = x++ + 1; } Console.WriteLine("x is " + x);

x is 1

To add a value of 1 to variable x, you write _______. x++; 1 + x = x; x += 1; x = 1 + x; x := 1;

x++; x += 1; x = 1 + x;

What is y after the following switch statement is executed? int x = 3; int y = 4; switch (x + 3) { case 6: y = 0; case 7: y = 1; default: y += 1; }

y=0


Conjuntos de estudio relacionados

DBMS Chapter 4: Logical Database Design and the Relational Model

View Set

Promulgated Forms- Unit 7 True/False Quiz

View Set

Medicare Part A Coverage and Eligibility Requirements

View Set

National Real Estate Pre and Post Test Questions

View Set

LS 7: Inventory and Cost of Goods Sold

View Set

CIT: 332 Systems Development II @ WKU - Spring 2019 Study Tool

View Set

History- Political Statement: from the Universal Declaration of Human Rights

View Set

Econ 1101 - Final Exam Review (Compilation of all Chapter Exam Reviews)

View Set