CIS 199 - Exam 1

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

Which of the following binary arithmetic operators have the highest precedence (execute first). Choose all that apply: * / % - +

* / %

What will the value of the variable z be after the following sequence of statements complete execution? Enter the numeric value (number only) below. int x = 3; int y = 4; int z; z = x/y;

0

Match each statement to the appropriate object-oriented programming concept: 1) This is where the structure of a type of entity is defined, including what attributes will be stored and what behaviors/tasks will be able to be performed by instances of this category of entity. It serves as a blueprint. For example, this would define that every Student has a name, a student ID number, and a GPA and that they can add and drop courses. 2) This is an instance (or tangible example) of the type of entity defined previously. The values of each attribute are stored here. For example, student John Smith, with ID number 1234567 and GPA 3.9.

1) class 2) object

What will the value of the variable 'test' be after the following sequence of statements complete execution? Enter the numeric value (number only) below. int x = 42; int test; test = x++;

42

What does the following C# expression evaluate to? Type the value below (number only). 22 - 2 * 10 + 3

5

The equality operator in C# is ___

==

Explain the difference between radio buttons and checkboxes.

A checkbox is a control that is a small rectangle that indicates whether a user has chosen an option. When a form contains multiple checkboxes, the user can select any number of them. When options are grouped so that only one can be checked at a time and selecting one deselects the others, they are called radio buttons.

Explain the difference between camel casing and Pascal casing naming conventions. Which should be used for naming variables and controls in C#?

Camel casing, also called lower camel casing, is a style of creating identifiers in which the first letter is not capitalized, but each new word is -- for example, studentName. Pascal casing, also called upper camel casing, is a style of creating identifiers in which the first letter of all new words in a name, even the first one, is capitalized -- for example, DisplayName. By convention in C#, variables and controls are named using camel casing.

When a user types in a TextBox GUI control, which property is used to retrieve the entered string?

Text

Which property of a Window's Form controls the message displayed in the form's title bar?

Text

A string literal that begins with a $ indicates that string interpolation is being used.

True

C# is case sensitive, so the following identifiers would all refer to different variables: num2, Num2, NUM2

True

When if/else statements are nested, each else always is paired with the most recent previous unpaired if unless curly braces force a different pairing.

True

Which of the statements below are functionally equivalent to (producing the same result as) the given statement: count--;

count = count - 1; count -= 1; --count;

In a switch statement, a case can be labeled as ___ to execute in the event that none of the other provided cases match the test expression (selector).

default:

What data type is the numeric literal 2.5 stored as?

double

Using the code fragment below, when does Needs Work get displayed? if (score < 60) gradeString = "F"; WriteLine("Needs Work");

every time the program is run (likely a logic error)

EC: Write a C# code fragment that uses a TryParse with the double variable testScore. The input is coming from a TextBox named testScoreTxt. If the TryParse is successful and the testScore is zero or higher, display the message "Valid input" using MessageBox.Show. Otherwise, display the message "Invalid score. Try again!" using a MessageBox.

if (double.TryParse(testScoreTxt.Text, out testScore) && testScore >= 0) MessageBox.Show("Valid input"); else MessageBox.Show("Invalid score. Try again!");

Write a C# code fragment that tests the value stored in double variable gpa. If the gpa is between 0.0-4.0 (inclusive) it is valid. In this case, output the value of the gpa with 2 digits of precision followed by a space and "is a valid GPA" - for example, "3.50 is a valid GPA". For any other gpa, output the value of the gpa with 2 digits of precision followed by a space and "is NOT a valid GPA" - for example, "4.25 is NOT a valid GPA". Send the output to the console.

if (gpa >= 0.0 && gpa <= 4.0) WriteLine ($"{gpa:F2} is a valid GPA"); else WriteLine ($"{gpa:F2} is NOT a valid GPA");

Which of the following C# expressions means, "If itemNumber is neither 8 nor 9, add FEE to price"?

if (itemNumber != 8 && itemNumber != 9) price = price + FEE;

Write a C# code fragment that outputs the word "High" when the value of the double variable testScore exceeds 85. If the value of testScore is between 60 and 85 (inclusive), output the word "Average". If the value of testScore is less than 60, output the word "Low". Use a nested if/else if structure and strive to be efficient.

if (testScore > 85) WriteLine("High"); else if (testScore >= 60) WriteLine("Average"); else WriteLine("Low");

Which of the following expressions is equivalent to the following code fragment? if (y > x) if (y < z) Write("Between");

if (y > x && < z) Write("Between");

If you want to perform one action when a Boolean expression evaluates as true and an alternate action when it evaluates as false, you can use a(n) ___ statement.

if/else

___ errors are not violations of the programming language rules. Instead, the code will execute but produces incorrect results.

logic

Write a code fragment that will display the value of double variable mealPrice in the Label named mealPriceLabel using currency formatting. You may assume that the variable mealPrice has been declared and given a value already.

mealPriceLabel.Text = mealPrice.ToString("C");

If a Button's identifier is reportButton when its Click event handler is created, then, by default, the name of its Click method is ___.

reportButton_Click() or ReportButton_Click() in VS 2019

The expressions in each part of a conditional AND expression are evaluated only as much as necessary to determine whether the entire expression is true or false. This feature is called ___ evaluation.

short-circuit

The conditional OR operator is written as ___.

||

When interacting with the various numeric types, C# will often perform an implicit (automatic) type conversion (or cast) for you. Sometimes, however, you must perform an explicit type conversion (or cast). How do you perform an explicit type conversion (or cast) in C#? Give a short code fragment example that includes the syntax of the cast. Consider an assignment statement between an int variable and a double variable. When would the assignment require an explicit cast and why?

An explicit type conversion is performed by specifying the desired type inside parentheses and placing it in front of the value (or variable) to be converted temporarily to the new type. For example: double d = 9.5; int i = (int)d; You are required to use an explicit type conversion when trying to assign an incompatible value into a variable of another type. Such an assignment could result in a loss of data, so the compiler forces the programmer to explicitly cast the incompatible value. Here, attempting to assign a double variable to an int variable would require an explicit cast as shown above.

Explain the difference between syntax errors and logic errors

Each high-level language has its own syntax, or rules of the language. For example, to produce output, you might use the verb print in one language and write in another. All languages have a specific, limited vocab, along with a set of rules for using that vocab. The compiler issues an error message each time a programmer commits a syntax error -- that is, each time the programmer uses the language incorrectly. In addition to learning the correct syntax for a particular language, a programmer must understand computer programming logic. The logic behind any program involves executing the various statements and procedures in the correct order to produce the desired results. You might be able to use a computer language's syntax correctly but be unable to obtain correct results because the program is not constructed with proper logic. These kinds of mistakes (where the program executes but produces incorrect results) are known as logic errors.

What value does a TryParse method return if the string argument cannot successfully be converted to the specified numeric type?

False

When producing formatted output with method ToString or with string interpolation, the format specifier "D" is used to convert a numeric value to a string that represents a currency amount, such as $100.00 in the US.

False

What is meant by short-circuit evaluation in decision making expressions in C#?

In compound conditional tests involving AND/OR logic, the conditional Boolean expressions are evaluated only as much as necessary to determine whether the entire expression is true or false. This feature is called short-circuit evaluation. If the final answer can be determined entirely by the left conditional, the right side of the test will not get evaluated.

Please identify whether each item is considered hardware or software. Keyboard MS PowerPoint Application MacOS Catalina OS Touchpad (on laptop)

Keyboard - hardware MS PowerPoint Application - software MacOS Catalina OS - software Touchpad (on laptop) - hardware


Ensembles d'études connexes

Chapter 7: The Empires of Persia

View Set

Lección 10 Estructura: 10.2 Grammar tutorial: The preterite and the imperfect

View Set

Article 110 - Requirements for Electrical Installations (QUARTER 1)

View Set

Personal Finance: Auto Insurance--Who Am I?

View Set

RAD 114 CHEST (Problem Solving for Technical and Positioning Errors)

View Set

AP1 Prac3 lab 9(14&15) mastering questions

View Set

UNIT: CAUSES AND CONSEQUENCES OF WORLD WAR II - VICTORY & DEFEAT

View Set

Operating Systems and You: Process Management Quiz

View Set

Chap 2 Individual Behaviour , Personality, and Values

View Set

GEB1101:M2-C16: Mastering Financial Management

View Set