Simply C#An Application Driven Tutori

Gratis

0
0
666
3 months ago
Preview
Full text

O N T E N T S

  O N T E N T SC Drawing Application 1 1 Introducing Computers, the Internet and C# 2 Welcome Application 4 Introducing the Visual Studio . 1.6) c) IDEs d) as a replacement for the Internet b) high-level languages a) platforms d) W3C c) Windows b) BASIC a) .

1.11 Categorize each of the following items as either hardware or software:

1.12 Translator programs, such as assemblers and compilers, convert programs from one lan-

  guage (referred to as the source language) to another language (referred to as the target lan- guage). Determine which of the following statements are true and which are false:a) A compiler translates high-level-language programs into target-language programs.

1.13 Computers can be thought of as being divided into six units

  a) Which unit can be thought of as “the boss” of the other units? b) Which unit is the high-capacity “warehouse” that retains information even when the computer is powered off?c) Which unit might determine whether two items stored in memory are identical?

1.14 Expand each of the following acronyms:

  1.15 What are the advantages to using object-oriented programming techniques? The key advantage with using object-oriented programming is thatit tends to produce software that is more understandable because it is better organized and has fewer maintenance requirements than software produced with earlier methodologies.

2 Welcome Application

  NET IDE Solutions 4 Tutorial 2Welcome Application a) the component object box c) pinned command d) minimize command a) drop-down list b) menu c) tool tip d) down arrow a) help documentation b) a toolbar c) windows for accessing project files d) All of the above. a) Solution Explorer window b) Properties window c) Start Page d) Toolbox link b) a Solution Explorer a) component-selection feature c) menus d) a menu bar a) component b)Form c) icon d) property a) Web View b) Excel c) a Web tab d) Internet Explorer a) toolbars b) icons b) Auto Hide feature d) Toolbox Instructor’s Manual Exercise SolutionsTutorial 2 MULTIPLE-CHOICE 2.11 For Web browsing, Visual Studio .

2.13 The does not contain a pin icon

  a) Dynamic Help window b) Solution Explorer window c) Toolbox window d) active tab 2.14 When clicked, in the Solution Explorer window will expand nodes and will collapse nodes. ( 2.16 Closing and Opening the Start Page) In this exercise, you will learn how to close andEXERCISESreopen the Start Page (Fig.

2.17 Enabling Auto Hide for the Solution Explorer Window) In this exercise, you will

  Double click the Panel icon in the Toolbox to add another Panel to the Form . Then add the Button to the Panel by dragging and dropping it on the Panel .

3.12 Create the GUI for the alarm clock in Fig. 3.34

  Finally, to draw a border around the edge of the Snooze Label , change the BorderStyle property of the Snooze Label to FixedSingle . To place the GroupBox in the correct location on the Form , set the Location property to 104 ,38 .

40 Size

  Label Form Label Form Text h) Adding the time to the . Change the ForeColor to Silver (located in the Web tab) to make the time stand out against the black background.

3.13 Create the GUI for the microwave oven shown in Fig. 3.35

  Add a Label to the right Panel by clicking theLabel in the Toolbox once, then clicking once inside the right Panel . Place a Button in the right Panel by click- ing the Button control in the Toolbox once, then clicking inside the Panel .

1 Button is located at 40 , 80 and the Start Button is located at 8 , 92

  Change the Text property of each Button such that numbers 0–9 , the pound ( # ) and the star ( ) keys are represented. Change the Size of eachButton to 24 , 80 , and notice how the small Size causes the Text to align vertically.

3.15 Create the GUI for the vending machine in Fig. 3.37

  Change the Text property of the Label to A1 , the TextAlign property to TopCenter and the Size to56 , 16 . Add a Label to the Form , and change the Text property to B2 , BorderStyle to FixedSingle , Font Size to36 , TextAlign to Mid- dleCenter and Size to 160 , 72 .

i) Adding the input Button Finally, add Button s to the GroupBox . For the seven But- s

  Then change the Text property of the But- ton s such that each Button has one of the values A , B , C ,1 , 2 , 3 or 4 , as shown in Fig. Set its to , its to ,BorderStyle FixedSingle Font Bold TextAlign Middle-its to , its style to , its toCenter Size 56 23 Tex 92.9 Labeland its to , .

i) Adding the image. Add a PictureBox to the Form . Set its BackColor to Transpar-

  25 T U T O R I A L 4 Designing the InventoryApplication Introducing TextBoxes and ButtonsSolutions Tutorial 4Designing the Inventory Application Instructor’s Manual Exercise SolutionsTutorial 4 4.1 A new Windows application is created by selecting from the File menu. Label Label 4.3 When creating a , you can specify the of that .

4.4 Changing the value stored in the property will change the name of the file

  Name File a) b) c) File Name d) Full PathTextBox 4.5 should be used to prefix all names.txt tbx a) b)Frm tbn c) d) 4.6 A(n) helps the user understand a control’s purpose. Button Label a) b) descriptiveLabel c) output d) title bar 4.7 A is a control in which the user can enter data from a keyboard.

4.11 GUI) In this exercise, you apply the GUI design guidelines you have learned to a graphical user interface for an address book (Fig. 4.22)

  Double click AddressBook.cs in the Solution Explorer window to open the Form in design view. Rearrange the controls and modify their properties so that the GUI conforms to the design guidelines you have learned.

4.12 In this exercise, you apply the GUI design guidelines you

  Double click Calculator.cs in the Solution Explorer window to open the Form in design view. Rearrange the controls and modify their properties so that the GUI conforms to the design guidelines you have learned.

4.13 In this exercise, you apply the GUI design guidelines you have

  Rearrange the controls and modify their properties so that the GUI conforms to the design guidelines you have learned. Rearrange the controls and modify their properties so that the GUI conforms to the design guidelines you have learned.

2. Label s indicating control usage should end with colon

  Label lblCountTotal; // 31 32 // 45 /// <summary> { 44 if ( disposing ) 43 { 42 39 /// Clean up any resources being used.40 /// </summary> 41 protected override void Dispose( bool disposing ) 38 33 37 } 36 // 35 // call 34 // TODO: Add any constructor code after InitializeComponent 1 );} // end method btnCount_Click } // end class FrmCounter 5.13 (Account Information Application) Create an application that allows a user to input aname, account number and deposit amount (Fig. Then add the value in the Deposit amount: TextBox to the value in Deposit amount: output Label , and display the result in the Deposit amount: output Label .

5.15 The following event handler should multiply two inputs when the user clicks a Calcu-

  /// <summary> 60 59 // Windows Form Designer generated code } 69 57 76 3 1 // Exercise 5.15 Solution 2 // Multiplication.cs (Correct) } 78 } // end class FrmMultiplication 77 74 75 } // end method btnCalculate_Click // calculates the total cost of an item including tax 73 { 72 object sender, System. 43 42 41 49 // 40 // call 39 // TODO: Add any constructor code after InitializeComponent 38 // 37 36 if ( disposing ) { // } /// </summary> 62 61 /// The main entry point for the application.

5.16 Copy the directory C:\Examples\

  } // 39 // 45 // call 44 // TODO: Add any constructor code after InitializeComponent 43 // 42 41 40 InitializeComponent(); Tutorial 5Completing the Inventory Application Answer: Below is the code with all errors corrected. Container components = null ;37 38 public FrmAccountInformation()39 { 40 //41 // Required for Windows Form Designer support 42 // 43 InitializeComponent(); 44 45 //46 // TODO: Add any constructor code after InitializeComponent 47 // call48 // 49 }50 51 /// <summary>52 /// Clean up any resources being used.53 /// </summary> 54 protected override void Dispose( bool disposing ) ▲Default name Default account number 80 [STAThread] 72 static void Main() 73 { 74 Application.

6 Enhancing the Inventory

51 ApplicationIntroducing Variables, Memory Concepts and Arithmetic Solutions Tutorial 6Enhancing the Inventory Application Instructor’s Manual Exercise SolutionsTutorial 6

6.1 Parentheses that are added to an expression simply to make it easier to read are known

  MULTIPLE-CHOICE as parentheses. QUESTIONS a) necessary b) redundant c) embedded d) nested 6.2 The operator performs division.

d) 6.3 Every variable has a

  a) from right to left b) from left to right c) according to the rules of operator precedence d) from the lowest level of precedence to the highest level of precedence 6.6 Variable declarations in event handlers begin with their . 6.7 TextBox Entering a character in a raises the event.

d) 6.8 The operator makes an explicit conversion from one type to another

a) cast b) changetype c) convert d) conversion 6.9 Variables used to store integer values should be declared with the keyword.integer b) int a) c) intvariable d) None of the above.

6.10 The name of a variable in a variable declaration should come directly after its

  Run( new FrmTemperatureConverter() ); { 65 static void Main() 64 [STAThread] 63 /// </summary> 62 protected override void Dispose( bool disposing ) /// </summary> 16 // Labels to display Fahrenheit temperature 27 // Button to perform the conversion 26 25 private System. 57 if ( disposing ) 56 55 { protected override void Dispose( bool disposing ) 54 /// </summary> 53 /// <summary> // 51 50 } 49 48 47 InitializeComponent(); 46 // // Required for Windows Form Designer support 45 // Buttons to add, subtract, multiply and divide, 29 Answer: 7 12 namespace SimpleCalculator 11 10 9 using System.

6.14 This code modifies the values of intNumber1 , intNumber2 and intResult . What are

  if ( disposing ) 43 { 42 protected override void Dispose( bool disposing ) 41 /// </summary> 40 /// <summary> { 38 37 35 36 } 34 InitializeComponent(); // 33 // Required for Windows Form Designer support 32 // 44 45 if (components != null ) { } 57 56 /// The main entry point for the application. Dispose(); 58 { 57 if (components != null ) 56 intAverage = ( intNumber1 + intNumber2 + intNumber3 ) / 3 ; Tutorial 6Enhancing the Inventory Application } // end class FrmAverageDebugging 98 } 99 ▲ Programming Challenge 6.17 (Digit Extractor Application) Write an application that allows the user to enter a five-digit number into a TextBox .

g) Creating an event handler for the Clear

  Form 16 /// </summary> 15 21 Introducing Algorithms, Pseudocode and Program Control Solutions Tutorial 7 49 public FrmWageCalculator() 50 {51 // 52 // Required for Windows Form Designer support53 // 54 InitializeComponent(); 55 56 }57 58 /// <summary>59 /// Clean up any resources being used.60 /// </summary> 61 protected override void Dispose( bool disposing )62 { 63 if ( disposing )64 { 65 if (components != null )66 { 67 components. 7.33).int Each customer enters an account number (an ), a balance at the beginning of the monthdecimal decimal (a ), the total of all items charged for the month (a ), the total of all creditsdecimalapplied to the customer’s account for the month (a ), and the customer’s alloweddecimalcredit limit (a ).

7.14 Assume that txtAge is a TextBox control and that the user has entered the value

  Container components = null ;26 27 public FrmAMorPM()28 { 29 //30 // Required for Windows Form Designer support 31 // 32 InitializeComponent(); 33 34 }35 36 /// <summary>37 /// Clean up any resources being used.38 /// </summary> 39 protected override void Dispose( bool disposing )40 { 41 if ( disposing )42 { 43 if (components != null )44 { 45 components. EventArgs e ) 64 private void FrmAMorPM_Load( 63 // determines if the specified time lies in the AM or PM 62 } 54 /// The main entry point for the application.

8 Dental Payment

  a) the text displayed in the dialog’s title barButton b) a constant representing the s displayed in the dialog c) the text displayed inside the dialog d) a constant representing the icon that appears in the dialogButton 8.4 You can specify the (s) and icon to be displayed in a message dialog by using theMessageBoxButtons and constants. Show( 120 119 // clear text displayed in Label { 111112113114115116117118 // display message 110 // if no name entered and no CheckBox checked, 108109 lblTotalResult.Text = "" ; 107 89 88 64 69 73 // call 72 // TODO: Add any constructor code after InitializeComponent 71 // 70 68 InitializeComponent(); 74 // 67 // Required for Windows Form Designer support 66 // 65 { // } 86 } 87 } 82 components.

8.14 Assume that txtName is a TextBox and that chkOther is a CheckBox next to which is a

  Text == "" || 1 34 35 //36 // TODO: Add any constructor code after InitializeComponent 37 // call38 // 39 }40 41 /// <summary>42 /// Clean up any resources being used.43 /// </summary> 44 protected override void Dispose( bool disposing )45 { 46 if ( disposing )47 { Tutorial 8Dental Payment Application 79 80 } // end method btnEnter_Click 68 private void btnEnter_Click( 69 object sender, System. /// <summary> 47 } 54 45 // 44 42 // TODO: Add any constructor code after InitializeComponent 43 // call // 41 40 39 InitializeComponent(); // { if (components != null ) [STAThread] 61 67 /// </summary> 66 65 /// The main entry point for the application.

9 Car Payment Calculator

  EXERCISES9.11 (Table of Powers Application) Write an application that displays a table of numbersfrom 1 to an upper limit, along with each number’s squared value (for example, the number n to the power 2, or n ^ 2) and cubed value (the number n to the power 3, or n ^ 3). /// <summary> 13 { 25 27 // call 36 41 // TODO: Add any constructor code after InitializeComponent 40 // 39 38 InitializeComponent(); // 37 // Required for Windows Form Designer support 34 { 35 // 28 public FrmTableOfPowers() 33 32 private System.

a) Copying the template to your working directory. Copy the directory C:\Examples\ Tutorial09\Exercises\MortgageCalculator to your C:\SimplyCSP directory

  Use the method to display a header in the . For this exercise, use the following numbers 5 10 15 20 25 30 of years: , , , , and .

i) Converting the length of the mortgage from years to months. Convert the number of years to months

  Use the method of the property to display the ListBoxlength of the mortgage in years and the monthly payments in the . Add( 97 "Mortgage Length (Years)\tMonthly Payment" ); 98 99 // perform payment calculation and display result for 100 // 5, 10, 15, 20, 25 and 30 years 101 while ( intYears <= 30 ) 102 { 103 104 // convert years to months for the calculation105 intMonths = intYears * 12 ; 106 // perform calculation 107 decPayment = ( decimal ) 108 ( intMortgageAmount * dblMonthlyRate * 109 Math.

9.14 What value does intMysteryValue contain when the following code is completed?

  Container components = null ; 24 25 public FrmCalcValue() 26 27 { // 28 // Required for Windows Form Designer support 29 // 30 InitializeComponent(); 31 // 32 // TODO: Add any constructor code after InitializeComponent 33 // call 34 // 18 17 =120 using System. ToString( intMysteryValue ); 74 73 72 57 [STAThread] 58 static void Main() /// </summary> 56 /// <summary> 43 if ( disposing ) 42 { 41 38 /// Clean up any resources being used.39 /// </summary> 40 protected override void Dispose( bool disposing ) 37 55 /// The main entry point for the application.

9.15 Find the error(s) in the following code:

  ToString( intTotal ); 80 84 // display the result 83 82 } 81 intX++; The counter should decrease, not increaseintCounter++; This should use <= rather than <while ( intCounter < 5 ) Introducing the while Repetition Statement Solutions Tutorial 9 40 // 41 } protected override void Dispose( bool disposing ) 46 /// </summary> 45 44 /// Clean up any resources being used. /// <summary> 43 42 // call { 39 // TODO: Add any constructor code after InitializeComponent 38 // 37 36 InitializeComponent(); // 35 // Required for Windows Form Designer support 47 48 // } 60 59 // Windows Form Designer generated code 58 57 } 56 base .

Dokumen baru