Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Dr. Abraham Most slides are from your textbook.

Similar presentations


Presentation on theme: "Programming Dr. Abraham Most slides are from your textbook."— Presentation transcript:

1 Programming Dr. Abraham Most slides are from your textbook

2 Programming in C# Download C# express from http://www.microsoft.com/visualstudio/en- us/products/2010-editions/visual-csharp- express

3 3 Pseudocode A mixture of English and formatting to make the steps in an algorithm explicit Algorithm to Convert base-10 number to other bases While ( the quotient is not zero ) Divide the decimal number by the new base Make the remainder the next digit to the left in the answer Replace the original decimal number with the quotient

4 4 Following an Algorithm

5 5 Algorithm for preparing a Hollandaise sauce IF concerned about cholesterol Put butter substitute in a pot ELSE Put butter in a pot Turn on burner Put pot on the burner WHILE (NOT bubbling) Leave pot on the burner Put other ingredients in the blender Turn on blender WHILE (more in pot) Pour contents into lender in slow steam Turn off blender

6 6 Developing an Algorithm Two methodologies used to develop computer solutions to a problem –Top-down design focuses on the tasks to be done –Object-oriented design focuses on the data involved in the solution But first, let's look at a way to express algorithms: pseudocode

7 7 Pseudocode A way of expressing algorithms that uses a mixture of English phrases and indentation to make the steps in the solution explicit There are no grammar rules in pseudocode Pseudocode is not case sensitive

8 8 Testing Test plan A document that specifies how many times and with what data the program must be run in order to thoroughly test it Code coverage An approach that designs test cases by looking at the code Data coverage An approach that designs test cases by looking at the allowable data values

9 9 Testing Test plan implementation Using the test cases outlined in the test plan to verify that the program outputs the predicted results

10 10 Object-Oriented Design Class (or object class) A description of a group of similar objects Object (instance of a class) A concrete example of the class Classes contain fields that represent the properties (name, eye color) and behaviors (responsibilities) (shop, cook) of the class Method A named algorithm that defines behavior (shop, cook)

11 11 Programming Language Paradigms Imperative –Procedural Characterized by sequential instructions A program in which statements are grouped into a hierarchy of subprograms Fortran, C, C++ –Object-oriented model Program consists of a set of objects and the interactions among the objects Python, Java, Smalltalk, Simula

12 Let us look at some real examples of C#

13 Hello program using System; namespace sayHello { class sayHello { static void Main(string[] args) { Console.WriteLine("Hello!"); Console.WriteLine("Welcome to Dr. Abraham's C# Class!"); Console.ReadLine(); }

14 How do you write and run a program? Use visual studio to create a project. The project file will have the extension csproj. The project stores all related files, including the source file you write. Every project has a solution file with the extension sln. You would be opening this file when you want to return to your program you were writing. This will open all associated files. The associated files may be contained in a subdirectory. After writing the source code, go to build and build your solution, which creates the intermediate code. Go to debug and start without debugging. The program run will finish and give you a prompt to press any key to continue. Start with debugging, it will complete the run and return to you to the IDE. If your IDE does offer “without debugging”, add a console.readkey() statement.

15 Using the Form designer You can size the form by holding the handles in the corners or the middle. Controls and other items are added to the form using the toolbox. If control or item has properties that can be set. To write the code for an event, you can click on the view code button above the solution explorer or by simply clicking on a button or anything else on the form. Files with code you write will have extension.cs. Files ending with designer.cs are code files generated by visual studio.

16 Naming Controls and Boxes Use a convention you will remember. I start all button names with btn. For example an accept button will be named btnAccept. An exit button will be named btnExit. All text boxes will start with txt. For example, sales amount will be named txtSalesAmount. All labels with start with lbl. For example, lblEnterName. It is up to you to choose naming conventions you will recognize.

17 Arithmatic + - * / % precedence given to the last three. Relational operators > = <= Equity Operators == !=

18 If statement explained using System; public class Comparison { public static void Main( string[] args ) { int number1; // declare first number to compare int number2; // declare second number to compare Console.Write( "Enter first integer: " ); number1 = Convert.ToInt32( Console.ReadLine() ); Console.Write( "Enter second integer: " ); number2 = Convert.ToInt32( Console.ReadLine() ); if ( number1 == number2 ) Console.WriteLine( "{0} == {1}", number1, number2 ); if ( number1 != number2 ) Console.WriteLine( "{0} != {1}", number1, number2 ); if ( number1 < number2 ) Console.WriteLine( "{0} < {1}", number1, number2 ); if ( number1 > number2 ) Console.WriteLine( "{0} > {1}", number1, number2 ); if ( number1 <= number2 ) Console.WriteLine( "{0} <= {1}", number1, number2 ); if ( number1 >= number2 ) Console.WriteLine( "{0} >= {1}", number1, number2 ); } // end Main

19 About some Types in C# Value Types Size (in bits) Range sbyte 8 128 to 127 byte 8 0 to 255 short 16 -32768 to 32767 ushort 16 0 to 65535 int 32 147483648 to 2147483647 uint 32 0 to 4294967295 long 64 -9223372036854775808 to 9223372036854775807 ulong 64 0 to 18446744073709551615 char 16 0 to 65535 booltrue, false Enum types and struct types Reference types include class types, interface types, delegate types, and array types Pointer types


Download ppt "Programming Dr. Abraham Most slides are from your textbook."

Similar presentations


Ads by Google