ISTM 250 - Conceptual Exam 2

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

Which .NET feature is used by typed collections but not by untyped collections?

Generics

When you catch an exception, what method can you use to get the type of the exception?

GetType()

Which method of the Decimal class returns a false value if the entry can't be converted instead of throwing an exception?

TryParse()

What will the following method return? private string GetName(int customerID, bool readOnly)

a string

If you pass a variable by reference, the called method

can change the value of the variable in the calling method

If you pass a variable by value, the called method

can't change the value of the variable in the calling method

Which of the following statements would you use to pass a variable named message by reference to a method named DisplayMessage? DisplayMessage(reference message); DisplayMessage(ref message); DisplayMessage(message reference); DisplayMessage(message ref); DisplayMessage(message);

DisplayMessage(ref message);

What method of the String class lets you format numbers, dates, and times?

Format( )

If a text box entry can't be converted to a numeric data type, what type of exception occurs?

FormatException

When you call a method, the arguments you pass to it

must be declared with data types that are compatible with the parameters

The signature of a method is formed by the

name of the method and its parameter list

To define a tuple as the return type for a method, you define its members by separating them with commas and enclosing them in...

parentheses - ()

What is the value of length after the code that follows is executed? int[ ][ ] nums = { new int [ ] {1, 2, 3}, new int [ ] {3, 4, 5, 6, 8}, new int [ ] {1}, new int [ ] {8, 8} }; int length = nums[2].Length;

1

What is the value of lists after the statements that follow are executed? string[,] names = new string[200,10]; int lists = names.GetLength(0);

200

What is the value of kilos[1] after the code that follows is executed? decimal[] kilos = {200, 100, 48, 59, 72}; for (int i = 0; i < kilos.Length; i++) { kilos[i] *= 2.2; }

220.0

If the current date is January 3, 2021, what is the value of day after the following statements are run? DateTime date = DateTime.Now; int day = date.DayOfYear;

3

What is the value of index after the code that follows is executed? int[] values = {2, 1, 6, 5, 3}; Array.Sort(values); int index = Array.BinarySearch(values, 5);

3

What is the value of times[2,1] in the array that follows? decimal[,] times = { {23.0, 3.5}, {22.4, 3.6}, {21.3, 3.7} };

3.7

What is the value of length after the code that follows is executed? int[ ][ ] nums = { new int [ ] {1, 2, 3}, new int [ ] {3, 4, 5, 6, 8}, new int [ ] {1}, new int [ ] {8, 8} }; int length = nums.GetLength(0);

4

What happens when the code that follows is executed? string[] names = new string[5]; string name1 = names?[0];

A null value is assigned to the name1 variable.

When you declare and initialize the values in an array, you are actually creating an instance of what class?

Array

Which of the following statements sorts a one-dimensional array named values? values = Array.Sort(values); Array.Sort(values); values = ArrayList.Sort(values); ArrayList.Sort(values);

Array.Sort(values);

Consider the following code: Queue<String> products = new Queue<String(); products.Enqueue("Plate"); products.Enqueue("Bowl"); products.Enqueue("Cup"); products.Enqueue("Saucer"); What is the value of product after the following code is executed? string product = products.Dequeue(); product = products.Dequeue(); product = products.Dequeue();

Cup

Assuming the computer's regional settings are configured for the United States, which of the following statements creates a DateTime value whose date is set to March 28, 2021? DateTime date = new DateTime("03/28/2021"); DateTime date = DateTime.Parse("03/28/2021"); DateTime date = date.Parse("03/28/2021"); DateTime date = new DateTime().Parse("03/28/2021");

DateTime date = DateTime.Parse("03/28/2021");

Which statement determines the due date for an invoice that is due 45 days after the invoice date? DateTime dueDate = invoiceDate.Add(45); DateTime dueDate = invoiceDate.AddDays(45); DateTime dueDate = invoiceDate.Add(new TimeSpan(45)); DateTime dueDate = invoiceDate.Add(DateTime.DAYS, 45);

DateTime dueDate = invoiceDate.AddDays(45);

Which of the following statements creates a DateTime value named dueDate that's set to the date December 31, 2021? DateTime dueDate = new DateTime("12/31/2021"); DateTime dueDate = new DateTime(12, 31, 2021); DateTime dueDate = new DateTime("2021-12-31"); DateTime dueDate = new DateTime(2021, 12, 31);

DateTime dueDate = new DateTime(2021, 12, 31);

Which statement creates a DateTime value named invoiceDate that's set to the current date and time? DateTime invoiceDate = DateTime.Now; DateTime invoiceDate = DateTime.Today; DateTime invoiceDate = DateTime.Current; DateTime invoiceDate = DateTime.CurrentDateTime;

DateTime invoiceDate = DateTime.Now;

Which of the following expressions checks if the DateTime variable named date contains a date that falls in a leap year? date.IsLeapYear date.IsLeapYear() DateTime.IsLeapYear(date) DateTime.IsLeapYear(date.Year)

DateTime.IsLeapYear(date.Year)

Exceptions are objects that are created from the _________________ class or one of its subclasses.

Exception

Which of the following statements would you use to call a private method named InitializeVariables() that accepts no parameters and doesn't return a value? InitializeVariables(void); void InitializeVariables(); InitializeVariables(); void InitializeVariables(void);

InitializeVariables();

Consider the following code: private void btnCalculate_Click(object sender, System.EventArgs e) { decimal weightInPounds = 0m; try { weightInPounds = Convert.ToDecimal(txtPounds.Text); if (weightInPounds > 0) { decimal weightInKilos = weightInPounds / 2.2m; lblKilos.Text = weightInKilos.ToString("f2"); } else { MessageBox.Show("Weight must be greater than 0.", "Entry error"); txtPounds.Focus(); } } catch(FormatException) { MessageBox.Show("Weight must be numeric.", "Entry error"); txtPounds.Focus(); } } If the user enters 118 in the text box and clicks the Calculate button, what does the code do?

It calculates the weight in kilograms.

Which of the following is not true about the null-conditional operator? It prevents a NullReferenceException. If it finds a null value, no further operations take place. It checks the object or element that preceeds it for a null value. It can only be used with reference types.

It can only be used with reference types.

Consider the following code: private void btnCalculate_Click(object sender, System.EventArgs e) { decimal weightInPounds = 0m; try { weightInPounds = Convert.ToDecimal(txtPounds.Text); if (weightInPounds > 0) { decimal weightInKilos = weightInPounds / 2.2m; lblKilos.Text = weightInKilos.ToString("f2"); } else { MessageBox.Show("Weight must be greater than 0.", "Entry error"); txtPounds.Focus(); } } catch(FormatException) { MessageBox.Show("Weight must be numeric.", "Entry error"); txtPounds.Focus(); } } If the user enters -1 in the text box and clicks the Calculate button, what does the code do?

It displays a dialog box with the message "Weight must be greater than 0."

Consider the following code: private void btnCalculate_Click(object sender, System.EventArgs e) { decimal weightInPounds = 0m; try { weightInPounds = Convert.ToDecimal(txtPounds.Text); if (weightInPounds > 0) { decimal weightInKilos = weightInPounds / 2.2m; lblKilos.Text = weightInKilos.ToString("f2"); } else { MessageBox.Show("Weight must be greater than 0.", "Entry error"); txtPounds.Focus(); } } catch(FormatException) { MessageBox.Show("Weight must be numeric.", "Entry error"); txtPounds.Focus(); } } If the user clicks the Calculate button without entering data in the text box, what does the code do?

It displays a dialog box with the message "Weight must be numeric."

Consider the following code: private void btnCalculate_Click(object sender, System.EventArgs e) { decimal weightInPounds = 0m; try { weightInPounds = Convert.ToDecimal(txtPounds.Text); if (weightInPounds > 0) { decimal weightInKilos = weightInPounds / 2.2m; lblKilos.Text = weightInKilos.ToString("f2"); } else { MessageBox.Show("Weight must be greater than 0.", "Entry error"); txtPounds.Focus(); } } catch(FormatException) { MessageBox.Show("Weight must be numeric.", "Entry error"); txtPounds.Focus(); } } If the user enters "200#" in the text box and clicks the Calculate button, what does the code do?

It displays a dialog box with the message "Weight must be numeric."

What is the value of startDate after the following statements are executed? DateTime startDate = new DateTime(2021, 3, 1); startDate = startDate.AddMonths(3);

June 1, 2021

Which of the following is not true about a SortedList collection? Key values must be added to a sorted list in alphabetical order. You use the DictionaryEntry structure to work with an element of a sorted list. You can use a key to get its associated value. Each element in a sorted list consists of a key value and a related value.

Key values must be added to a sorted list in alphabetical order.

Which of the following statements declares a typed List collection named dueDays that will hold int values? List dueDays = new List(); List<int> dueDays = new List<int>(); IntList dueDays = new IntList(); ArrayList dueDays = new ArrayList();

List<int> dueDays = new List<int>();

What date is represented by d3 after these statements are executed? DateTime d1 = new DateTime(2021, 3, 1); DateTime d2 = new DateTime(2021, 3, 4); TimeSpan t = d2.Subtract(d1); DateTime d3 = d1.Add(t);

March 4, 2021

When you catch an exception, which of its properties can you use to get a description of it?

Message

Two properties of an object created from the Exception class are

Message and StackTrace

If a value that's assigned to an int variable is too large to be stored in it, what type of exception occurs?

OverflowException

Consider the following code: Queue<String> products = new Queue<String(); products.Enqueue("Plate"); products.Enqueue("Bowl"); products.Enqueue("Cup"); products.Enqueue("Saucer"); What is the value of product after the following code is executed? string product = products.Peek();

Plate

Which of the following is not true about collections? Some collections use indexes that start with 1. The capacity of a collection is adjusted automatically as new elements are added. The items in all collections can be modified. Collections can be used to store any type of object.

Some collections use indexes that start with 1.

When you declare a string data type, you are actually creating an object from the

String class

What method can you use to remove spaces from the beginning and end of a string?

Trim( )

Consider the code that follows. What does it do? string value = "2"; try { int num = Convert.ToInt32(value); } MessageBox.Show("Valid integer"); catch(FormatException) { MessageBox.Show("Invalid integer"); }

The code doesn't compile

Which property of the DateTime structure returns the current date with the time set to 12:00:00 AM?

Today

Which of the following is not an advantage of passing arguments by name?

You don't have to know the name of the associated parameter

Which of the following is not true for typed collections? Their classes can be found in the System.Collections.Generic namespace. Trying to add the wrong type of data to one will cause a compile-time error. You need to specify the data type of the collection when you declare it. You need to cast any elements that are retrieved from the collection to the specified data type.

You need to cast any elements that are retrieved from the collection to the specified data type.

A queue provides: an Item property for getting any item in the collection an Add() method for adding an item to the collection a Remove() method for removing an item from the collection a Dequeue() method for getting the next item in the collection

a Dequeue() method for getting the next item in the collection

To determine the cause of an exception, you can use the name of the exception class that's displayed use the error message that's displayed use the information in the stack trace all of the above

all of the above

When validating data entered into the text boxes of a form, it is notcommon to check whether

all text entries are non-numeric

In a try-catch statement, a catch block for the Exception class can be used to catch

any exceptions that aren't caught by previous catch blocks

When a statement within a try block causes an exception, the remaining statements in the try block

aren't executed

The process of checking user entries to make sure they're valid is called

data validation

Given a text box named txtNum, which of the following statements may cause a format exception? string s = txtNum.Text; if (txtNum.Text == null) newValue = 0; if (txtNum.Text == "") newValue = 0; d = Convert.ToDecimal(txtNum.Text);

decimal d = Convert.ToDecimal(txtNum.Text);

If you have an int variable named yrs and two decimal variables named prin and rate, which statement can you use to call the method with the following method declaration? private decimal GetInterest(int years, decimal interestRate, decimal principle) decimal interest = GetInterest(yrs, rate, prin); decimal interest = GetInterest(rate, prin, yrs); int interest = GetInterest(yrs, rate, prin); int interest = GetInterest(rate, prin, yrs);

decimal interest = GetInterest(yrs, rate, prin);

Which of the following statements creates an array of decimals named miles and assigns the values 27.2, 33.5, 12.8, and 56.4 to its elements?

decimal[ ] miles = {27.2m, 33.5m, 12.8m, 56.4m};

To generate an event handler for a control event, you can display the Events list for the control and then

double-click on the event

Given a typed List collection of int values named dueDays, which of the following statements adds the value 120 to the end of the list? dueDays.Add(120); dueDays.Append(120); dueDays.Insert(120); dueDays.Insert(0, 120);

dueDays.Add(120);

To delete an event handler, you not only have to delete its method but also its

event wiring

Which of the following for statements adds each element in a one-dimensional array named totals to a string named message? for (int i = 0; i < totals.Size; i++) message += totals[i] + "|"; for (int i = 0; i < totals.Length; i++) message += total + "|"; for (int i = 0; i < totals.Length; i++) message += totals[i] + "|"; for (int i = 1; i <= totals.Length; i++) message += total + "|";

for (int i = 0; i < totals.Length; i++) message += totals[i] + "|";

Which of the following foreach statements adds each element in a one-dimensional array named totals to a string named message? foreach (total : totals) message += total + "|"; foreach (total in totals) message += total + "|"; foreach (decimal total : totals) message += total + "|"; foreach (decimal total in totals) message += total + "|";

foreach (decimal total in totals) message += total + "|";

Which of the following statements gets the number of strings in the array that follows? string[ ] customers = new string[55]; int size = customers.UpperBound; int size = customers.Length; int size = customers.Size(); int size = Arrays.Size(customers);

int size = customers.Length;

When coding an expression-bodied method, what operator do you code after the method signature?

lambda operator (=>)

Because a stack retrieves items in the reverse order in which they were added, it is known as what type of collection?

last-in, first-out (LIFO)

What keyword do you code at the beginning of a method if you only want it to be available within the current class?

private

Which of the following declares a method named GetTotals() that returns a tuple that has two members named TotalQty and TotalAmt? private [int TotalQty, decimal TotalAmt] GetTotals(int year) {} private (int TotalQty, decimal TotalAmt) GetTotals(int year) {} private [TotalQty, TotalAmt] GetTotals(int year) {} private (TotalQty, TotalAmt) GetTotals(int year) {}

private (int TotalQty, decimal TotalAmt) GetTotals(int year) {}

Which of the following is a shorter way to code the following GetTotal() method? private decimal GetTotal(decimal subtotal, decimal tax) { return subtotal + tax; } private decimal GetTotal(subtotal, tax) { return subtotal + tax } private decimal GetTotal(decimal subtotal, decimal tax) { subtotal + tax } private decimal GetTotal(decimal subtotal, decimal tax) return subtotal + tax; private decimal GetTotal(decimal subtotal, decimal tax) => subtotal + tax;

private decimal GetTotal(decimal subtotal, decimal tax) => subtotal + tax;

Which of the following declares a method named GetMessage() that returns a string value and requires one decimal parameter named currentBalance and is only available within the current form? private void GetMessage(currentBalance) private string GetMessage(currentBalance) private string GetMessage(decimal currentBalance) protected string GetMessage(decimal currentBalance)

private string GetMessage(decimal currentBalance)

Which of the following declares a private method named GetMessage() that returns a string value and requires a string parameter named fullName and a decimal parameter named currentBalance? private string GetMessage(fullName : currentBalance) private string GetMessage(fullName, currentBalance) private string GetMessage(string fullName : decimal currentBalance) private string GetMessage(string fullName, decimal currentBalance)

private string GetMessage(string fullName, decimal currentBalance)

Which of the following method declarations is valid for a method that accepts an array of strings named customerNames? private string[] ParseCustomerNames(customerNames){} private void ParseCustomerNames(customerNames){} private void ParseCustomerNames(customerNames string[]){} private void ParseCustomerNames(string[] customerNames){}

private void ParseCustomerNames(string[] customerNames){}

An OverflowException can be avoided by a type of data validation known as

range checking

Consider the following code: private void btnCalculate_Click(object sender, System.EventArgs e) { decimal weightInPounds = 0m; try { weightInPounds = Convert.ToDecimal(txtPounds.Text); if (weightInPounds > 0) { decimal weightInKilos = weightInPounds / 2.2m; lblKilos.Text = weightInKilos.ToString("f2"); } else { MessageBox.Show("Weight must be greater than 0.", "Entry error"); txtPounds.Focus(); } } catch(FormatException) { MessageBox.Show("Weight must be numeric.", "Entry error"); txtPounds.Focus(); } } What type of data validation does this program do?

range checking and valid data type checking

To generate a method call and a method from existing code, you can use a feature called

refactoring

If the following GetInterest() method uses a decimal variable named interest to store the interest amount, which statement can you use to return the interest amount? private decimal GetInterest(int years, decimal interestRate, decimal principle) Return Interest; return dec interest; return decimal interest; return interest;

return interest;

To refer to the ninth element in a one-dimensional array named sales, you code

sales[8]

You can use the BinarySearch() method of the Array class to

search for a value in a sorted array and return the index of that value

Once you display the list of events for a control, you can wire an existing event handler to any event by

selecting the event handler from the drop-down list for the event

The list of methods that were called before an exception occurred is called the

stack trace

Given a typed Stack collection named colors that contains strings, which of the following statements retrieves the first item in the stack, stores it in a string variable named color, and removes the retrieved item from the stack? string color = colors.Peek(); string color = colors.Push(); string color = colors.Pop(); string color = colors.Ping();

string color = colors.Pop();

Which of the following statements declares a valid jagged array? string[4][ ] js = new string[ ][ ]; string[ ][4] js = new string[ ][ ]; string[ ][ ] js = new string[4][ ]; string[ ][ ] js = new string[ ][4];

string[ ][ ] js = new string[4][ ];

Which of the following statements declares a valid rectangular array? string[,] js = new string[,]; string[,] js = new string[4,4]; string[ ][ ] js = new string[ ][ ]; string[ ][ ] js = new string[4][4];

string[,] js = new string[4,4];

Which of the following code snippets passes an argument by name? subtotal:subtotal subtotal:=subtotal subtotal=subtotal subtotal=:subtotal

subtotal:subtotal

To display a dialog box, you can use the Show() method of

the MessageBox class

The code within a catch block is executed when

the code in the try block throws an exception

For each parameter in the parameter list for a method, you must code:

the data type of the parameter followed by the name of the parameter

When compared to untyped collections, typed collections reduce

the number of runtime errors and the amount of casting that's required

If you declare a parameter for a method as optional,

the parameter must be assigned a default value

You may want to code generic methods for data validation because

they allow you to reuse your data validation code

Which statement calls a method in the current form named SetButtons() and passes it a false value? this.SetButtons(false); this.SetButtons(disable); this.SetButtons(bool false); this.SetButtons(value=false);

this.SetButtons(false);

Which of the following statements would be used to wire the Click event of a button named btnClear to an event handler named ClearControls()? this.btnClear.Click += System.EventHandler(this.ClearControls); this.btnClear.Click += new System.EventHandler(this.ClearControls); this.ClearControls += System.EventHandler(this.btnClear.Click); this.ClearControls += new System.EventHandler(this.btnClear.Click);

this.btnClear.Click += new System.EventHandler(this.ClearControls);

What statement causes an exception to occur?

throw

In what interval of time is a TimeSpan value measured?

ticks

In C#, dates and times are actually stored as the number of

ticks that have elapsed since January 1, 0001

To refer to the second column in the fourth row of a rectangular array named vendors, you code

vendors[3,1]

What keyword do you code for the return type of a method that doesn't return any data?

void

You typically do not throw an exception

when invalid data is detected

In a try-catch statement, the finally block is executed

whether or not an exception occurs or a catch block is executed


Ensembles d'études connexes

World History Ch 17, Section 3--Luther Leads the Reformation

View Set

Linux - Chapter 15 - System and User security

View Set

Chapter 2- Fluid, Electrolyte, and Acid Balance (Exam Questions)

View Set

Module 2 Quiz Questions and Problem Set 2

View Set

Data Structures & Algorithms To Know in Javascript

View Set