+ All Categories
Home > Documents > Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ......

Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ......

Date post: 03-Jul-2018
Category:
Upload: lemien
View: 260 times
Download: 1 times
Share this document with a friend
24
Unit 1 Workbook ICS3U Huntsville High School Computer Science Ian McTavish Name:
Transcript
Page 1: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

Unit 1 Workbook ICS3U Huntsville High School Computer Science

Ian McTavish

Name:

Page 2: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

I McTavish ICS3U Workbook January 30, 2012 | Unit 1 1

Table of Contents Unit 1 ...................................................................................................................................................... 3

Expectations for Evaluation ................................................................................................................. 3

Assessment Due Dates......................................................................................................................... 3

February 3, 2012 ..................................................................................................................................... 3

Typing Challenge ................................................................................................................................. 3

February 6 - Your First Program .............................................................................................................. 4

Programming Primer ........................................................................................................................... 7

Most Popular Programming Languages.................................................................................................... 7

Must Include .................................................................................................................................... 7

Format ............................................................................................................................................. 7

Due Date ......................................................................................................................................... 7

Programming Primer Rubric................................................................................................................. 8

Feb 7 – Output ........................................................................................................................................ 9

Output in a Windows Form ................................................................................................................ 11

Methods vs. Properties .................................................................................................................. 11

Feb 8 – Variables, Strings ....................................................................................................................... 11

Variables ........................................................................................................................................... 12

Naming Conventions ......................................................................................................................... 12

Strings ............................................................................................................................................... 13

Complete the following table ......................................................................................................... 14

Feb 9 – Input ......................................................................................................................................... 15

U1D5usingVariablesxxx ...................................................................................................................... 16

Labels ................................................................................................................................................ 16

TextBoxes ...................................................................................................................................... 16

Button ............................................................................................................................................... 16

RichTextBox ....................................................................................................................................... 16

Form.................................................................................................................................................. 16

Code Tip ........................................................................................................................................ 17

Feb 10 – Data Types .............................................................................................................................. 18

Feb 13 – Careers Summative Intro ......................................................................................................... 20

Feb 14 – Math Operations, Concatenation ............................................................................................ 20

Page 3: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

2 Unit 1 | I McTavish ICS3U Workbook January 30, 2012

Feb 15 – 17 Career Summative Work Periods ........................................................................................ 22

Feb 21 – Programming Challenge Summative ........................................................................................ 22

Feb 22 – Wrap up Unit 1 ........................................................................................................................ 22

Works Cited ........................................................................................................................................... 23

Page 4: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

I McTavish ICS3U Workbook January 30, 2012 | Unit 1 3

Unit 1

Expectations for Evaluation A1. demonstrate the ability to use different data types, including one-dimensional arrays, in computer

programs

A4. use proper code maintenance techniques and conventions when creating computer programs

C2. use appropriate file maintenance practices to organize and safeguard data

D3. describe postsecondary education and career prospects related to computer studies

Assessment Due Dates Feb 17 Programming Primer

Feb 22 Careers Programming Assignment

February 3, 2012 What we’re covering today:

Welcome

course overview

Assessment & Evaluation

Expectations

Computer as a tool, not a toy

This is your job, welcome to the work world – show up, be prepared, focus, work hard

Breaks

Room – keep it clean

Where you can go

What to do when you’re done an assignment

Throughout unit 1 you will be working through this workbook, your programming primer, handouts

distributed in class and information from our class website. Please contact Mr. McTavish if you unclear

as to what you are to do.

Typing Challenge The ability to type quickly with no spelling errors will benefit you in this

course. Start off each day with All the Right Type. (Student

Applications/Business/All the Right Type). Click the course and your

name. Explore the different areas and practice!

Goal 1: Errors: 0

Goal 2: Errors: 0 WAM: 20

Goad 3: Errors: 0 WAM: 60

One error resulted in 153

errors in a program!

Page 5: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

4 February 6 - Your First Program | I McTavish ICS3U Workbook January 30, 2012

February 6 - Your First Program When you start the Visual Studio IDE for the first time, you need to quickly orient yourself around the

program.

On the Start Page, click Create Project (on the menu – File – New Project).

Select Windows Forms Application (always ask what type of program it is)

Give this program the name u1d2windowsxxx (u1 – unit 1, d2 – day 2, windows – the name of the assignment, xxx – replace with your initials. Use this format for all program names – note: NO SPACES)

1

2

3

Menu

Standard

toolbar

Start Page

Note – you

can create

and open

projects

here.

Page 6: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

I McTavish ICS3U Workbook January 30, 2012 | February 6 - Your First Program 5

1 2 3

4

5 1. The Solution Explorer is where you can see all the files for your program. Form1.cs is the windows form and should be the only file you use at this point.

2. Form Designer This is what your form actually looks like. Nothing much yet… This area is also where you view code. On the menu you can switch between code and Designer views.

3. Use the Toolbox to add different windows elements (i.e. buttons, menu bars). Simply drag the item onto your form. We’ll use the Button for this program.

4. Whenever an element is selected (Form1 in this diagram), the Properties window shows all the properties that you can set. The buttons allow you to sort them, or access the Events (i.e. a button click) available.

5. The Start Debugging button on the toolbar allows you to build and run your program. The command is also found under the Debug menu. Run it now – you should have a form show up, not much, but it’s your first program.

Page 7: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

6 February 6 - Your First Program | I McTavish ICS3U Workbook January 30, 2012

It’s important to name the objects you use with names that are easy to

understand: btn – this is a button, ShowMessage – this tells you what the

button does, note there are NO SPACES!

A Hello World program is a traditional method of writing your first program.

Can you find out who created the first Hello World program?

From the toolbox, drag the Button onto your form.

Make sure your button is selected and in the Properties window (Ctrl W, P), change the (Name) value from button1 to btnShowMessage

Change the Text value to: Show Message You may need to resize the button to show all the words.

On the Form Designer, double-click the button, this will take you to the code and add an event for when the button is clicked. This is the following code (note the first two lines are all on one line).

private void btnShowMessage_Click(object sender, EventArgs e)

{

}

Hit enter and type the following MessageBox.Show("Hello World");

Click the Start Debugging Button, your program should run (if it doesn’t, check for spelling mistakes, also MessageBox.Show(“Hello World”); should be between the {}. When you click the button on your program, you should get a Hello World Message.

MessageBox is a class that comes with Microsoft’s .Net programming languages. The Show method

allows you to show the message box, Hello World is the String that you are providing as a parameter to

display on the message box.

Page 8: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

I McTavish ICS3U Workbook January 30, 2012 | February 6 - Your First Program 7

Programming Primer A fundamental goal in this course is “learning how to learn”.

Technology changes at an incredible rate. The programming

languages I used in high school simply aren’t used anymore – we have

to assume that you will encounter the same issue. The challenge is to

learn the skills and be able to independently learn new programming

languages.

Your task is to research a programming language and create a

Programming Primer that explains how to program in that language.

Must Include

Brief overview of the language (one paragraph max)

How to create a program

How to create Output

How to declare and initialize variables o Boolean o Integer o Floating Point (Double, or decimal) o String

How to get input

Basic math operations

Concatenating Strings

Works Cited – with at least two or three citations in MLA style

Format

You may use any of the following methods to hand in your

Programming Primer.

Paper (The References tab is useful for adding citations)

Website (Google Sites is a free, easy way to create a website – Use Cite Your Sources from the school website to add citations)

Other – check with McTavish

Due Date

February 17

Most Popular

Programming

Languages

Java C C# C++ Objective-C PHP (Visual) Basic Python Perl JavaScript Delphi/Object Pascal Ruby Lisp Pascal Transact-SQL PL/SQL Ada Logo R Lua (TIOBE SOFTWARE)

Page 9: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

8 February 6 - Your First Program | I McTavish ICS3U Workbook January 30, 2012

Programming Primer Rubric

Level 4 (5 marks) Level 3 (6 marks) Level 2 (7 marks) Level 1 (8-10 marks) Marks

K 5 items included 6 items included 7 items included All items included

K Explanations and samples demonstrate limited understanding

Explanations and samples demonstrate some understanding

Explanations and samples demonstrate considerable understanding

Explanations and samples demonstrate thorough understanding

T Examples and/or samples are not clear

Examples and samples showed some choice of information covered in class

Examples and samples were obviously selected from class notes and the class textbook

Original examples and samples clearly explain the topic. Citations demonstrate when information was obtained from class notes, the textbook and independent research.

C There are errors in spelling and/or syntax

There are some errors in spelling and/or syntax

There are few errors in spelling and/or syntax

There are no errors in spelling and syntax

A Examples were ones covered in class

Example are slightly different than ones covered in class

Examples are based on class examples and show ability to use in new situations

Examples are original and additional examples are created

Comments Total:

Page 10: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

Feb 7 – Output Output is the process where computers make information available outside the computer – this could

be on a screen, printed or to control a device (a robot’s movements would be considered output). You

can also output information to a network like the Internet (Deitel, Deitel and Quirk).

1. Create Project – Select Console Application 2. Name: u1d3COutputxxx (replace xxx with your initials) 3. Click Ignore when you get the warning the location can’t be trusted 4. Add two lines so that the complete program looks like the following using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace u1d3COutputibm

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("Hello World");

Console.ReadLine();

}

}

}

5. Debug your program - what happens?

6. We will take some time to understand what is happening. using System;

using System.Collections.Generic;

using System.Linq;

using System.Text; The first four lines are using directives (Microsoft) – these allow you to state what namespaces the

program will use. For example System is a namespace in the .Net Framework. It contains a class called

Console which we access in this program (Microsoft). If we didn’t have these lines then later in the

program we would need to write:

System.Console.WriteLine("Hello World");

Page 11: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

10 Feb 7 – Output | I McTavish ICS3U Workbook January 30, 2012

namespace u1d3COutputibm

{

}

Every program should be in a namespace. The braces ({…}) define the block where we put our code

(Microsoft Corporation 8). The namespace is automatically the name of the file – you should not mess

with this!

Warning: the most common problem you will encounter is accidently deleting a brace or typing

outside of the block!

class Program

{

}

C# is an Object Oriented Programming language (OOP) – a class is used to create an object. Again, you

should not mess with this!

static void Main(string[] args)

{

}

This declares a method called Main. For a program to run it requires a Main method. A method is a

block of code that performs actions or computations. In Unit 2 we will learn what the rest of the terms

represent.

Console.WriteLine("Hello World");

Console.ReadLine();

As mentioned before –Console is a class in the System namespace. WriteLine is a method thatperforms

an action (in this case – writes a line of text to the console screen). The ReadLine method waits for the

user to type - we only need this so that the program doesn’t finish!

Page 12: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

I McTavish ICS3U Workbook January 30, 2012 | Feb 8 – Variables, Strings 11

Output in a Windows Form Open u1d2windowsxxx (from yesterday). Add the following line after your MessageBox line:

this.Text = "Hello World";

Run the program – what do you notice changes after you’ve pressed the button and clicked OK on the

MessageBox?

What happens if you change the line to the following:

btnShowMessage.Text = "Hello World";

.Text is a property that you can set and get.

Add a Textbox, change the (Name) property to txtOutput. Change the code so that when the button is

pressed you change the Text property to some text.

Methods vs. Properties

A method is like an action – for a car there would be a ‘drive’ action. A property is a value. A car has a

‘colour’ property.

Feb 8 – Variables, Strings Computer memory stores arbitrary bit patterns. As with a string of letters, the meaning of a string of bits

depends on how it is used. The particular scheme that is being used for a particular string of bits is a

data type. A data type is a scheme for using bits (binary digits) to represent values. These values are not

just numbers, but any kind of data that a computer can process. All values in a computer are

represented using one type of data or another.

In any programming language, there are many different data types and even ones you, as a programmer,

can create. Some types of data are so fundamental to programmers that most programming languages

have built in ways to represent them. These are the primitive data types. The names of the eight

primitive data types are:

Page 13: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

12 Feb 8 – Variables, Strings | I McTavish ICS3U Workbook January 30, 2012

Int double long short byte float boolean char

These data types are referred to as primitive because they are the foundations upon which larger parts

of a program are built. The first six listed above are used to store numeric data; boolean and char are

generally used to store alphabetic or character information. The basic difference between the numeric

primitives is in the range of numbers they can store. Many real-world programs deal with massive

amounts of data (billions of data items) and, thus, the smaller size types (byte and short) may save

significant amounts of space and time. But we will not use that much data in this course. Usually you

should use integers (for data that will not contain decimal places) or double (data containing decimal

places) for your numeric data .

Variables Essentially, a variable is a name for a location in computer memory which uses a particular data type to

hold a value.

The integer value appears in a storage space. The storage space is titled

"myNumber" and is an int (or integer) type. Note the naming convention for

variables: a name for a variable (as well as for a method) usually starts with a

lower case letter. A word that is part of the name starts with an uppercase

letter (like "Number"), unless it is at the start of the name. These conventions

are not required by syntax, but are useful to follow since they makes

programs more readable.

Naming Conventions Use a variable name that effectively describes the value being stored within it.

Use only the characters 'a' through 'z', 'A' through 'Z', '0' through '9', character '_'.

Start with lower case letter. First letter of other words in name are capitalized; eg. helloThere

A variable name cannot contain the space character.

Do not start with a digit.

The length of a variable name is <256 characters.

Upper and lower case count as different characters; eg. SUM and Sum are different names.

A name cannot be a reserved word.

A name must not already be in use in this part of the program.

Page 14: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

I McTavish ICS3U Workbook January 30, 2012 | Feb 8 – Variables, Strings 13

Strings Strings are a special type of variable. An integer will always take up the same amount of memory

regardless of its value. A string could be as small as a letter and as big as the works of Shakespeare.

Many times there are numbers that should be stored as strings. A telephone is a good example – since

you won’t add telephone numbers together or do other math operations – a string is the most

appropriate way to store it.

The following code example shows how to declare, initialize and output a String variable. Notice the

lines that start with // - these are comments that won’t run but explain the code.

//Declare a string variable

String strVar;

//Initialize a string variable

strVar = "Hello World";

//Output the string variable

MessageBox.Show(strVar);

Word

Decimal Number

Counting number

Yes/no True/false

Boolean

Integer

Double

String

Page 15: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

14 Feb 8 – Variables, Strings | I McTavish ICS3U Workbook January 30, 2012

Complete the following table

Data Type Console (Unmanaged) Windows Form (Managed)

Character Range:

Declare

Initialize

String Range:

Declare

Initialize

Declare System.String

varString1;

Initialize varString1 = "This

is a string.";

Integer Range: -2 147 483 647 to 2 147 483 647 (no decimal places)

Declare int x;

Initialize x = 12;

Declare Int32 x;

Initialize x = 12;

Double Range:

Declare

Initialize

Declare

Initialize

Boolean Range:

Declare

Initialize

Declare

Initialize

Valueless Range:

Declare

Initialize

Declare

Initialize

Page 16: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

I McTavish ICS3U Workbook January 30, 2012 | Feb 9 – Input 15

Feb 9 – Input Please read:

http://www.teach-

ict.com/as_a2/topics/input%20processing%20output/input_process_output/index.htm

answer the following questions.

_______________________is the data flowing into the system from outside. An example is:

_______________________is the action of manipulating the input into a more useful form. An example

is:

_______________________is the information flowing out of the system. An example is:

Comment [I1]: Input

Comment [I2]: Processing

Comment [I3]: Processing

Page 17: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

16 Feb 9 – Input | I McTavish ICS3U Workbook January 30, 2012

The Anchor property will resize

the item so that it stays the

same distance from the side you

choose. It’s an easy way to

allow your form to look good

regardless of the size.

U1D5usingVariablesxxx The goal is to create a windows program that uses a variety of variables. The Form will require the user

to input their name (string), the number of items they are purchasing (integer) and the price of the item

(double). The response will look as follows:

Bob,

You ordered 3 items at a price of $1.99 each. Your total cost is: $5.97.

1. Create a new Windows Form Application

2. Make sure to save it in the following location: D:/unit 1

3. Name: u1d5usingVariablesxxx (where xxx is your name)

4. On the form add the following items:

3 labels, 3 TextBoxes, 1 Button, 1 RichTextBox

5. Change the following properties

Labels

Properties Label1 Label2 Label3

Text Name Quantity Price

TextBoxes

Properties TextBox1 TextBox2 TextBox3

Name txtName txtQuantity txtPrice Anchor Top, Left, Right Top, Left, Right Top, Left, Right

Button

Properties Button

Text Calculate Name btnCalculate

RichTextBox

Properties RichTextBox

Name rtbOutput Anchor Top, Left, Right

Form

Properties RichTextBox

Text Using Variables WindowState Maximized

Page 18: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

I McTavish ICS3U Workbook January 30, 2012 | Feb 9 – Input 17

Pseudocode is where you plan

the code you are writing. You

write it as code – but don’t

worry about the syntax. Then

when you’re ready to write the

program you fix the syntax so it

is actually code.

Concatenation is where you combine two strings.

1. Run the program to ensure there are no errors. Close the program after it opens.

2. Double-click the button to create the button click method.

3. Here is the pseudocode for the program you

are creating

Declare variable name – string

Declare variable quantity – integer

Declare variable price – double

Declare variable total – double

Declare variable output – string

Initialize name to txtName->Text

Initialize quantity to txtQuantity->Text (make sure to

convert to double)

Inititialize price to txtPrice->Text (make sure to convert to integer)

Initialize total to price*quantity (* is used to multiply)

Initialize output to a concatenated string name “, \n\nYou ordered “, quantity ,“ items at a price of $1.99

each. Your total cost is: $5.97.

Using the information covered in class, declare the variables. The last part is tricky so feel free to ask for

the code example.

Code Tip

//Declare variable

Double dblPrice;

//Initialize - Try Parse takes the text and converts it to a Double

Double.TryParse(txtPrice.Text, out dblPrice);

//Output - Concatenates "The Price is: " with the price in a dollar format

MessageBox.Show(String.Concat("The Price is: ",dblPrice.ToString("$0.00")));

Page 19: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

18 Feb 10 – Data Types | I McTavish ICS3U Workbook January 30, 2012

Feb 10 – Data Types Throughout this course you will use the following types of variables on a regular basis:

integers, floating points, strings, and Boolean values

In this walkthrough you will create a program for a ball manufacturer that will take the radius of a ball,

the quantity of balls to make and output “You will need 10m2 of material” (10m2 would be replaced with

the calculated surface area of the ball).

It was determined that the following variables are needed.

Variable Variable Name Type of Variable

Radius of the ball dblRadius Double Quantity of balls intQuantity Integer Surface Area of the ball dblSurfaceArea Double Output strOutput String PI (used to calculate radius dblPi const Double Whether radius is a valid value blRadiusInput Boolean Whether quantity is a valid value

blQuantityInput Boolean

You’ll notice that Pi is const Double. Const is a constant – since Pi never changes using const prevents

you from being able to change the value of Pi in the program.

We will also need the following items on our

form:

Item Name Property

TextBox txtRadius TextBox txtQuantity Button btnCalculate RichTextBox rtbOutput

The labels weren’t included since we won’t use

them in the program.

Pseudocode

Declare variables

Initialize variables

Calculate Surface Area

Calculate surface area of all the balls

Output results

Page 20: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

I McTavish ICS3U Workbook January 30, 2012 | Feb 10 – Data Types 19

Complete Code using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace u1feb10DataTypesIBM

{

public partial class Form1 : Form

{

//Declare constants

const Double dblPi = 3.14;

public Form1()

{

InitializeComponent();

}

/*

* btnCalculate_Click method

* Runs when the buton is pressed

*/

private void btnCalculate_Click(object sender, EventArgs e)

{

//Declare variables

Double dblRadius;

Int32 intQuantity;

Double dblSurfaceArea;

String strOutput;

Boolean blRadiusInput;

Boolean blQuantityInput;

//Initialize variables

blRadiusInput = Double.TryParse(txtBallRadius.Text, out

dblRadius);

blQuantityInput = Int32.TryParse(txtQuantity.Text, out

intQuantity);

//Calculate Surface Area

dblSurfaceArea = 4 * dblPi * dblRadius *dblRadius;

//Calculate surface area of all the balls

dblSurfaceArea = dblSurfaceArea * (Double)intQuantity;

//output results

strOutput = dblSurfaceArea.ToString();

rtbOutput.Text = "You will need " + strOutput + "m^2 of

material.";

rtbOutput.Text += "\nValid Radius: " + blRadiusInput.ToString();

rtbOutput.Text += "\nValid Quantity: " +

blQuantityInput.ToString();

}

}

}

Page 21: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

20 Feb 13 – Careers Summative Intro | I McTavish ICS3U Workbook January 30, 2012

Feb 13 – Careers Summative Intro This assignment will be handed out in class.

Feb 14 – Math Operations, Concatenation

Stage 1: Integer Math Purpose: To create a program that performs basic math calculations.

1. Set up the form to look like the diagram above. This requires:

3 TextBoxes

5 Buttons

1 Label

2. Change the properties of each of the items. Change the name values to the ones

indicated in the diagram 1. Change the Text values to the values in the text boxes. Also,

change the Name property of the Form to Calculate by Bob. (Replace Bob with your

name).

3. Double click btnMod, On the next page is the code I used.

3 4 12 = +

-

*

/

1. txtOp1

2. txtOp2

3. txtAnswer

4. btnAdd

5. btnSubtract

6. btnMultiply

7. btnDivide

8. btnMod

9. lblEqual

1 2 3 4

5

6

7

9

% 8

Diagram 1

Page 22: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

I McTavish ICS3U Workbook January 30, 2012 | Feb 14 – Math Operations, Concatenation 21

1. /* 2. This function runs when the Modulus button is pressed. 3. It divides Operator 1 by Operator 2 and returns the 4. remainder. 5. */ 6. private: System.Void btnMod_Click(System.Object sender,

System.EventArgs e) {

7. //Declare Variables 8. System.Int32 iOp1; 9. Int32 iOp2; 10. Int32 iAnswer;

11.

12. //Get values

13. Int32.TryParse(txtOp1.Text ,out iOp1);

14. Int32.TryParse(txtOp2.Text, out iOp2);

15. //Calculate Answer

16. iAnswer = iOp1 % iOp2;

17.

18. //Display result

19. txtAnswer.Text = iAnswer.ToString();

20. }

Note: The numbering will not be the same as yours, it is used so that you know that line 6 is only on

one line. Also, be careful where you type – not the placement of brackets!

4. Run the program, if there are errors, use View – Other Windows – Error List to identify

the errors. Try to fix them yourself before asking for help.

5. Add code for each of the other buttons (Save yourself some typing, use copy and paste

and then just modify the relevant line).

6. Run the program, make sure it works properly.

Stage Two: Double Math Purpose: To modify your program so you can also perform calculations using decimal numbers.

1. In Form Designer, click and drag to select all the items, Copy the items (either right-click,

Ctrl-C or use the menu).

2. Past the items below.

3. You will need to set the Name property. Use the same format as above, but add D to

the end of each name. Example: txtOp1D, btnAddD

The D represents Double.

4. Use the code from above, but remember to use Double instead of Int32 (you’ll also need

to modify the TryParse statement. Again, make sure to add D to the end of variable

names.

5. See Mr. McT for sample code.

Note: You can’t do Modulus with Double values! Bonus, can you use an If statement to prevent

divide by 0?

Page 23: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

22 Feb 15 – 17 Career Summative Work Periods | I McTavish ICS3U Workbook January 30, 2012

Feb 15 – 17 Career Summative Work Periods Remember to refer to the rubric to ensure you get maximum marks.

Feb 21 – Programming Challenge Summative Put your skills to the test!

Feb 22 – Wrap up Unit 1 There will be an online practice test so you can prepare for the final exam.

Page 24: Unit 1 Workbook ICS3U - tldsb.on.castories\ics3u4u\20112012... · Programming Primer Rubric ... allows you to show the message box, ... Computer memory stores arbitrary bit patterns.

I McTavish ICS3U Workbook January 30, 2012 | Works Cited 23

Works Cited Deitel, P. J., H. M. Deitel and D. T. Quirk. Visual C++ 2008 How to Program. 2nd. Upper Saddle River:

Pearson Education, 2008.

Microsoft Corporation. "C# Language Specification Version 4.0." C# Language Specification Version 4.0.

Microsoft Corporation, 2010. 8.

Microsoft. Namespaces (C# Programming Guide). 2012. 1 February 2012

<http://msdn.microsoft.com/en-us/library/0d941h9d(v=vs.80).aspx>.

—. using (C# Reference). 2012. 1 February 2012 <http://msdn.microsoft.com/en-

US/library/zhdeatwt(v=vs.80).aspx>.

TIOBE SOFTWARE. TIOBE Programming Community Index for January 2012. 2012. 1 February 2012

<http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html>.

Index Anchor .......................................................... 16 boolean ......................................................... 12 Boolean ......................................................... 18 button click ................................................... 17 byte ............................................................... 12 char ............................................................... 12 class ................................................................ 6 concatenation ............................................... 17 constant ........................................................ 18 data type ....................................................... 11 Debugging ....................................................... 5 double ........................................................... 12 Double .......................................................... 18 float .............................................................. 12 floating points ............................................... 18 Form Designer ................................................. 5 IDE .................................................................. 4 Int ................................................................. 12 integers ......................................................... 18 long ............................................................... 12

MessageBox ..................................................... 6 method ...................................................... 6, 10 Modulus ........................................................ 21 namespace .................................................... 10 Object Oriented Programming ....................... 10 OOP ............................................................... 10 parameter ........................................................ 6 primitive ........................................................ 11 Properties ........................................................ 5 pseudocode.................................................... 17 Pseudocode ................................................... 18 RichTextBox ................................................... 16 short .............................................................. 12 Solution Explorer ............................................. 5 strings ............................................................ 18 Strings ........................................................... 13 Toolbox ............................................................ 5 TryParse ......................................................... 17 Visual Studio IDE .............................................. 4 Windows Forms Application............................. 4


Recommended