TEC 151 - Geoff Campbell Exam 3

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

How do you add items to a ListBox using the Properties window?

1. Select the ListBox control in the Designer window. 2. In the Properties window, the setting for the Items property is displayed as (Collection). When you select the Items property, an ellipses button (...) appears. 3. Click the ellipses button. The String Collection Editor dialog box appears. 4. Type the values that are to appear in the ListBox into the String Collection Editor dialog box. Type each value on a separate line by pressing the Enter key after each entry. 5. When you have entered all the values, click the OK button.

Figure 1-49 shows the Visual Studio IDE. What are the names of the four areas that are indicated in the figure?

1. Toolbox 2. Form 3. Solution Explorer 4. Properties Window

What does a bounding box indicate about an object in the Designer?

A bounding box indicates that the object is selected and is ready to be edited.

What does a class specify about an object?

A class specifies the data that an object can hold and the actions that an object can perform. Classes can be thought of as "blueprints" that create a specific object.

What is the difference between a compiler and an interpreter?

A compiler is a program that translates a high-level program into a separate machine language program. This means that a program like C# we can put a message like "12+9" and the compiler will turn it into a bunch of 1's and 0's for the machine language to understand. An interpreter is a program that translates and executes the instruction in the program. This takes out the "translating" part of a compiler and skips right to performing or executing the task.

What is a flag and how does it work?

A flag is a variable that signals when some condition exists in the program. When the flag variable is set to false, it indicates that the condition does not yet exist. When the flag variable is set to true, it means the condition does exist.

What is the purpose of a try-catch statement?

A try catch statement is used to respond to the exception and prevent the program from termination.

What object is created in memory when an exception is thrown and has various properties that contain data about the exception?

An exception is an error that occurs unexpectedly while an application is running. The said exception must be handled properly or the application will stop executing. The object that is created in memory is called an exception object. The exception object has properties that contain data about the exception. When a programmer creates a catch clause, they can optionally assign a name to the exception object such as a catch or otherwise known as an exception ex. The ex specifies the name of that object, the programmer then uses the name ex to access the exception objects properties in the name block.

What type of software controls the internal operations of the computer's hardware?

An operating system controls the internal operations of the computer's hardware. This allows the devices connected to the computer like flash drives to be saved and retrieved while simultaneously allowing the computer to run.

What is another name for the top-down design process?

Another name for the top-down design process is called stepwise refinement. Top-down or stepwise refinement is defined as: ● The overall task that the program is to perform is broken down into a series of subtasks. ● Each subtask is examined to determine whether it can be further broken down into more subtasks. This step is repeated until no more subtasks can be identified. ● Once all of the subtasks have been identified, they are written in code. This process is called top-down design because the programmer begins by looking at the topmost level of tasks that must be performed and then breaks down those tasks into lower levels of subtasks.

Briefly describe the difference between design time and run time.

Design time is referred to as the time during which you build the GUI and write the application's code. Design time is time you use the Designer, Toolbox and the Properties window. Run time is referred to the time during which an application is executing. During run time you can interact with the running application, but you can not use the Designer, Toolbox or the Properties window, the code editor or parts of Visual Studio to make changes to your application.

What are filename extensions? What do they indicate about a file?

File name extensions are short sequences of characters that appear at the end of a filename and are preceded by a period, for example: .jpg , .docx, .pdf. They indicate the type of data stored in the file.

Why is the system time the preferred seed value for a Random object?

If a Random object uses the same seed value each time it is created, it always generates the same series of random numbers. Because the system time changes every hundredth of a second, it is the preferred value to use as the seed in most cases.

Describe the appearance of a Label control that's BorderStyle property is set to Fixed3D.

If the BorderStyle is set to Fixed3D, the control's text will have a recessed 3D appearance.

How many iterations will occur if the test expression of a for loop is false to begin with?

If the expression is false to begin with, it would not perform any iterations and would exit the loop.

How do you clear the text that is displayed in a Label control in code?

If you want to clear the text that is displayed in a Label control, you assign an empty string (" ") to the control's Text property.

In code what function do you call to move the focus to a control?

In code you move the focus control by calling the "Focus Method". The method's general syntax is: ControlName.Focus() Where the ControlName is the name for the control. For instance, you move the focus to the nameTextBox control with this statement: nameTextBox.Focus()

In the Toolbox in which group is the TextBox tool located?

In the Toolbox, the TextBox tool is located in the Common Controls group.

Write a programming statement that uses postfix mode to increment a variable named count.

Int count = 5 While (count <= 5) { count ++ }

Briefly describe how the && operator works.

This is the logical AND operator. It connects two Boolean expressions into one compound expression. Both subexpressions must be true for the compound expression to be true.

Briefly describe how the || operator works.

This is the logical OR operator. It connects two Boolean expressions into one compound expression. One or both subexpressions must be true for the compound expression to be true. It is necessary for only one of the subexpressions to be true, and it does not matter which.

How do you determine in code whether a RadioButton control or a CheckBox control is selected?

To determine if a RadioButton is selected code would look like: if (choice1RadioButton.Checked == true) { MessageBox.Show("You selected Choice 1.") } OR if (choice1RadioButton.Checked) { MessageBox.Show("You selected Choice 1") } For a CheckBox control code would look like: if (option1CheckBox.Checked) { MessageBox.Show("You selected Option 1.") }

What steps must you take to open an existing project?

To open an existing project, you must have Visual Studio already running. Click File then Open then select Project/Solution. The Open Project window will pop up. Find your folder that you want and press Open.

How do you specify a named argument?

To specify which parameter variable the argument should be passed to, you use the following format to write the argument in the method call: parameterName : value In this format parameterName is the name of a parameter variable and value is the value being passed to that parameter. ex. ) private void ShowName(string firstName, string lastName) { MessageBox.Show(firstName + " " + lastName) }

What two things does a variable declaration specify about a variable?

Variable declaration specifies: 1. The variable's data type, which is the type of data the variable will hold. 2. The variable's name.

What is meant by the term conditionally executed?

We say that the statements inside the curly braces are conditionally executed because they are executed only if the Boolean expression is true.

What does it mean when a Label control's AutoSize property is set to True?

When a Label control's AutoSize property is set to True, it means that the control automatically resizes itself to accommodate the size of the text it displays. This also means that you cannot manually change the size of the control by clicking and dragging its bounding box.

When an input file is opened what is its read position initially set to?

When an input file is opened, its read position is initially set to the first item in the file. As items are read from the file, the read position moves forward, toward the end of the file.

How can you view the project's form if it is not automatically displayed in the Designer?

When the project's form isn't automatically displayed you right-click Form1.cs in the Solution Explorer. Click View Designer in the pop-up menu. Then the form should reveal itself.

What are the two arguments that you pass to a TryParse method?

When you call one of the TryParse methods, you pass two arguments: (1) the string that you want to convert, and (2) the name of the variable in which you want to store the converted value.

How does Visual Studio help you to quickly correct syntax errors?

When you enter a statement into the editor, Visual Studio analyzes it and if a syntax error is found, it is underlined with a jagged line. If you hold the mouse cursor over the jagged line, a description of the error will pop up in a ToolTip window. The description usually gives you enough information to determine the cause of the error and how to fix it.

What happens when you position the mouse cursor over an edge or corner of a bounding box that has sizing handles?

When you position the mouse over the edge of a bounding box that has sizing handles, the cursor changes to a two-headed arrow. When the two-headed arrow appears, you can drag the mouse to resize the form.

What kind of code should be placed in the Load event?

When you run an application, the application's form is loaded into memory and an event known as the Load event takes place. The Load event takes place before the form is displayed on the screen. If you want to execute some code at this point, you can write a Load event handler containing the desired code. The code looks like: private void Form1_Load(object sender, EventArgs e) { MessageBox.Show("Prepare to see the form!") }

How can you access the documentation for Visual Studio? What resources are provided by the MSDN Library?

You access the MSDN Library by clicking Help in Visual Studio then selecting View Help. The MSDN Library provides complete documentation for Visual C# as well as other programming languages. There will be things like code samples, tutorials, articles and video tutorials.

By default the Open dialog box displays the contents of the user's Documents directory. How can you specify another directory to be initially displayed?

You can specify another directory to be initially displayed by storing its path in the InitialDirectory property. The code would look like: openFile.InitialDirectory = "C:\Data" if (openFile.ShowDialog() == DialogResult.OK) { // Continue to process the selected file... } else { // The operation was canceled. }

How can you read all of the items in a file without knowing how many items the file contains?

You can use the StreamReader boolean and have the program throw an exception if the program attempts to read beyond the end of the file. The code would look like: While (!inputFile.EndOfStream) { // Read an item from the file. // Process the item. }

You need to test a condition and then execute one set of statements if the condition is true. If the condition is false you need to execute a different set of statements. What structure will you use?

You will use the dual-alternative decision structure. which has two possible paths of execution—one path is taken if the Boolean expression is true, and the other path is taken if the Boolean expression is false.

6. What steps must you perform to change a form's Size property in the Properties window?

a. Locate the Size property in the Properties window. b. Click inside the area that holds the Size property's value and delete what is already in there. c. Type what size you want, for example 400, 300. Press the enter key and the for will be resized.

What steps must you perform to change a form's Text property?

a. Locate the Text property in the Properties window. b. Double-click the word Form1 and click the delete key to delete it. c. Type what you want the Text to say and press enter.

8. What steps do you perform to change a Button control's Text property?

a. Make sure the button control is selected. b. In the Properties window, locate the Text property. c. Click inside the area that holds the Text property's value, and delete what is currently in there. Then, type the new text in its place and press the enter key.

Write a programming statement that assigns an integer literal to a variable.

int hoursWorked = 40

When creating an event handler for a button

is it possible to skip a step by opening the code editor and writing all the event handler code yourself? Why or why not?, No, you can not skip a step by opening the code editor and writing the event handler code yourself, this is because when you double-click a control in the Designer, Visual studio creates an empty event handler, but it also writes code that you don't see elsewhere in the project. The code that is "elsewhere" is necessary for the event handler to properly function.

When determining whether a number is inside a range which logical operator is it best to use? When determining whether a number is inside a range

it is best to use the && operator. For example, the following if statement checks the value in x to determine whether it is in the range of 20 through 40:

Examine the following method header then write an example call to the method.

private void ShowValue() The following method contains the access modifier, return type, method name and parentheses. The word private means that this code can only be used when it is contained in a specific method. The return type or "void" means that the method is a void method, and does not return a value. The method name or "ShowValue" is a descriptive word/s so we can tell that this method is going to show some sort of value. The code may look like: private void Show Value () { MessageBox.Show("74") }

Can you use C# alone to perform advanced operations such as creating GUIs

reading data from a file, or working with databases? Why or why not?, No, you cannot use C# alone to perform advanced operations. This is because C# only provides the basic keywords and operators that you need to construct a program.

When a program runs in a text-based environment

such as a command line interface, what determines the order in which things happen?, Programs determine the order in which things happen in text-based environments. For example, if a user is trying to calculate an employee's pay, the program will tell the user to enter the hours worked, then enter the hourly pay rate. They will then press the enter key and then the program will display the pay. With text-based environments, the user has no choice but to enter the data as it is requested.

What are the values that the TextAlign property may be set to?

The TextAlign property may be set to: TopLeft, TopCenter, TopRight, MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter, or BottomRight.

Which class in the .NET Framework provides predefined named constants that are assigned the mathematical values for pi and e?

The class that pi and e are in is the Math.Pi and Math.E. Both are in the "Math" class.

How can you read the selected item from a ListBox while preventing an exception from occurring if no item is selected?

The items that are stored in a ListBox each have an index. The index is simply a number that identifies the item's position in the ListBox. The first item has the index 0, the next has the index 1, and so forth. The last index value is n − 1, where n is the number of items in the ListBox. When the user selects an item in a ListBox, the item's index is stored in the ListBox's SelectedIndex property. If no item is selected in the ListBox, the SelectedIndex property is set to −1. You can use the SelectedIndex property to make sure that an item is selected in a ListBox before you try to get the value of the SelectedItem property. You simply make sure the SelectedIndex property is not set to −1 before trying to read the SelectedItem property. i.e.) if (fruitListBox.SelectedIndex != −1) { selectedFruit = fruitListBox.SelectedItem.ToString() }

What is shown by each column in the Properties window?

The list of properties has two columns: the left column shows each property's name, and the right column shows each property's value.

What do you call a method that executes the statements it contains and then returns a value back to the statement that called it?

The method used to execute statements then return the value back are called value-returning method. Two examples of this are the .Parse and the .Void methods.

What determines an object's appearance and other characteristics?

The object's properties are what determines the object's appearance and other characteristics.

What is the standard naming convention used among C# programmers for method names? Why?

The standard naming convention used among C# Programmers for method names is Pascal case. It is used because it differentiates method names from variable and field names which use camelCase.

What is the term used for a number that is written into a program's code?

The term used for a number that is written into a programs is called a numeric primitive data type. There are three data types that can hold numbers. - int: can hold whole number only. - Double: can hold real numbers with decimals and rounds to 15 digits of precision. - Decimal: can hold real numbers, just like double can, but with greater precision. Decimal is rounded to 28 digits.

What are the three types of comments you can use in Visual C#?

The three types of comments are: - Line comment: appears on one line in a program. You begin a line comment with //. Everything written after the slashes, to the end of the line is ignored by the compiler. - Block comment: can occupy multiple consecutive lines in a program. A block comment starts with /* and ends with */. Everything between these markers is ignored. - Documentation comment: used by professional programmers to embed extensive documentation in a program's source code.

What is the purpose of the Toolbox in the Visual Studio environment?

The toolbox is a window that lets you select controls that you want to use in an apps interface. For example, Button, Label, and TextBox are all easily accessible through the toolbox.

What are the values on the right and left of an operator called?

The values on the left and right of an operator are called operands. They are values that the operator performs a task on.

What is a variable that is used to accumulate a total called?

The variable that is used to accumulate the total of the numbers is called an accumulator.

Give an example of a programming statement that uses string concatenation.

The + operator produces a string that is the combination of the two strings used as its operands. Ex: string message message = "Hello " + "world" MessageBox.Show(message) The first statement declares a string variable names message. The second statement combines the strings "Hello " and "world" The string "Hello world" is then assigned to the message variable. The third statement displays the contents of the message variable in a message box. When the message box is displayed, it shows the string Hello World.

What property allows you to change the color of a control's text?

The ForeColor property allows you to change the color of a control's text. When you select a control's ForeColor property in the Properties window, a down-arrow button appears, which displays the drop-down list of available colors.

Briefly describe the contents of the Form1.cs file.

The Form1.cs file contains code that is associated with Form1 form. When you write code that defines an action related to Form1, the code will be written in the Form1 file. Form1.cs files already contain code that was automatically generated by Visual Studio when the project was initially created. It is basically an outline for you to customize as you develop an application.

What are the different image formats that a PictureBox control can display?

The PictureBox control can display images that have been saved in the bitmap, GIF, JPEG, metafile or icon graphics formats.

List the values that the SizeMode property of a PictureBox control can be set to.

The SizeMode property can be set to: - Normal: the image will be positioned in the upper-left corner of the control. - StretchImage: resizes the image both horizontally and vertically to fit in the Picture-box control. - AutoSize: the PictureBox control is automatically resized to fit the size of the image. - CenterImage: centers the image in the PictureBox control without resizing it. - Zoom: uniformly resizes the image to fit in the PictureBox without losing its original aspect ratio.

What is a parameter list?

Notice that two parameter variables, num1 and num2, are declared inside the parentheses in the method header (line 1). This is often referred to as a parameter list. Also notice that a comma separates the declarations. Here is an example of a statement that calls the method: ShowMax(5, 10)

Name the family of methods in the .NET Framework that can be used to convert a string to any of the numeric data types.

Parse methods are the family we use to convert a string into any of the numeric data types. Parse typically means to analyze a string of characters for some purpose. There are 3 primary methods: a. int.Parse to convert a string into an int b. double.Parse to convert a string into a double c. Decimal.Parse to convert a string into a decimal.

7. How do you move a control to a new location on the form using the mouse?

Position the mouse cursor inside the control, and when the cursor becomes a four-headed arrow, you can click and drag the control to a new location.

What is pseudocode? What is a flowchart?

Pseudocode is defined as the process of informally writing out the steps of an algorithm before writing any actual code. Pseudo means fake, so you're basically sketching out what you want your program to look like before you execute anything. A flowchart is defined as a diagram that graphically depicts the steps of an algorithm. A flow chart has three different symbols used: an oval, parallelogram and a rectangle. The ovals represent the start and end of a program. Parallelograms are symbols for input and output, meaning they represent the steps in the order the program will read them. Rectangles are used as processing symbols. This means the program will perform some sort of process on the data entered.

The following statement calls a method named ShowHalf. The ShowHalf method displays a value that is half that of the argument. Write the method.

ShowHalf(50) The method might look something like this: private void ShowHalf(int number) { int value value = number/2 MessageBox.Show("The value is " + value) }

What is contained in the body of a loop?

Statements are contained in the body of the loop. For example the "while" loop used in the text box: While (Boolean Expression) { Statement Statement Etc. } All of the statements are in the body of the loop.

In code what characters do you enclose a string literal in?

String literal is enclosed in double quotation marks. ("........")


Ensembles d'études connexes

The Kingdom of Israel - The Reign of David

View Set

ECO 304L - EXAM 2 PRACTICE QUESTIONS

View Set

ACCT-104- CHAPTER 1-HOMEWORK- QUIZ - EXTRA CREDIT

View Set

Quizzes- ch 8 and onward- exam 2 anatomy

View Set

ITN 261 - Chapter 8, ITN 261 - Chapter 9, ITN 261 Chapter 10, ITN - 261 Chapter 11, ITN 261 chapter 12, ITN 261 Chapter 13

View Set

History Alive Medieval World Chapter 5

View Set