Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to Programming: Understanding Algorithms and Programming Paradigms, Lecture notes of Programming Languages

An introduction to programming concepts, including the characteristics of procedural, object-oriented, and event-driven programming. Students will learn how to design and implement simple computer programs using C# and Visual Studio .NET. topics such as modular design, flowcharts, coding, documentation, compilation, testing, debugging, and maintenance.

Typology: Lecture notes

2020/2021

Uploaded on 07/31/2022

truong-anh-tu-fgw-hn
truong-anh-tu-fgw-hn 🇻🇳

4.8

(4)

8 documents

1 / 57

Toggle sidebar

Related documents


Partial preview of the text

Download Introduction to Programming: Understanding Algorithms and Programming Paradigms and more Lecture notes Programming Languages in PDF only on Docsity! Programming HAA fil UNIVERSITY of Gis) GREEN WICH Alliance with ago. Education • Course introduction • Problem solving and algorithm • Program development steps • .NET Framework Topics Unit 1 - Programming / Lecture 1 - Introduction 2 • Drawing tools (choose one): – Visio – Draw.io or Lucichart (online) – Astah (recommendation, using student email to register full version) • IDE – Visual Studio Community 2017 Course preparation Unit 1 - Programming / Lecture 1 - Introduction 5 • It’s a creative process, it is an act of – Defining a problem – Determining the cause of the problem – Identifying, prioritizing, and selecting alternative for a solution – Implementing a solution Problem solving 6 • An algorithm is a step-by-step description of the solution to a problem • An algorithm must be – Definite – Finite – Precise and Effective – Implementation independent Algorithm 7 • Followings are the tasks in order to define a problem – Specifying the input requirements – Specifying the output requirements – Specifying the processing requirements Tasks in defining a problem Unit 1 - Programming / Lecture 1 - Introduction 10 • The input specification is obtained by answering following questions – What specific values will be provided as input to the program? – What format will the values be? – For each input item, what is the valid range of values that it may assume? – What restrictions are placed on the use of these values? Specifying the input requirements Unit 1 - Programming / Lecture 1 - Introduction 11 • The output specification is obtained by answering the following questions – What values will be produced? – What is the format of these values? – What specific annotation, headings, or titles are required in the report? – What is the amount of output that will be produced? Specifying the output requirements Unit 1 - Programming / Lecture 1 - Introduction 12 • Input: Positive integer number • Output: Factorial of that number • Process: Solution technique which transforms input to output. Factorial of a number can be calculated by the formula n!=1*2*3*…*n Activity Find Factorial Number Unit 1 - Programming / Lecture 1 - Introduction 15 • Use case diagrams are used to gather the requirements of a system • So when a system is analyzed to gather its functionalities use cases are prepared and actors are identified. • The purposes of use case diagrams can be as follows: – Used to gather requirements of a system – Used to get an outside view of a system – Identify external and internal factors influencing the system – Show the interacting among the requirements are actors Use-case diagram Unit 1 - Programming / Lecture 1 - Introduction 16 Main elements of use-case diagram Unit 1 - Programming / Lecture 1 - Introduction 17 • Once the problem is defined clearly, several design methodologies can be applied • An important approach is Top-Down program design • It is structured design technique – It breaks up the problem into a set of sub-problems called Modules – It creates a hierarchical structure of the modules Modular Design Unit 1 - Programming / Lecture 1 - Introduction 20 • Flowchart is a diagrammatic representation of an algorithm • It uses different symbols to represent the sequence of operations, required to solve a problem • It serves as a blueprint or a logical diagram of the solution to a problem Flowchart Unit 1 - Programming / Lecture 1 - Introduction 21 Flowchart symbols (1/2) Unit 1 - Programming / Lecture 1 - Introduction 22 • An algorithm expressed in programming languages is called Program • Writing a program is called Coding • The logic that has been developed in the algorithm is used to write program STEPS IN Program Development: Coding Unit 1 - Programming / Lecture 1 - Introduction 25 • Document explains – How the program works and how to use the program (user manual) – How to maintain the program (developer manual) • Details of particular programs, or particular pieces of programs, are easily forgotten or confused without suitable documentation STEPS IN Program Development: Documenting the Program Unit 1 - Programming / Lecture 1 - Introduction 26 • Documentation comes in two forms – External documentation, which includes things such as reference manuals, algorithm descriptions, flowcharts, and project workbooks – Internal documentation, which is part of the source code itself (essentially, the declarations, statements, and comments) Forms of documentation Unit 1 - Programming / Lecture 1 - Introduction 27 • Programs are tested with several test criteria and the important ones are given below – Test whether each and every statement in the program is executed at least one (Basic path testing) – Test whether every branch in the program is traversed at least once (control flow) – Test whether the input data flows through the program and is converted to an output (data flow) Test criteria Unit 1 - Programming / Lecture 1 - Introduction 30 • Debugging is a process of correcting the errors – Programs may have logical errors which cannot be caught during compilation – Debugging is the process of identifying their root causes – One of the ways is to print out the intermediate results at strategic points of computation – Another way is to use support from the IDE • Testing vs Debugging – Testing means detecting errors – Debugging means diagnosing and correcting the root causes STEPS IN Program Development: Debugging Unit 1 - Programming / Lecture 1 - Introduction 31 • Program maintenance – Continuing process of maintenance and modification – To keep pace with changing requirements and technologies • Maintainability of the program is achieved by – Modularizing it – Providing proper documentation for it – Following standards and conventions (naming conventions, using symbolic constants, etc.) STEPS IN Program Development: Maintenance Unit 1 - Programming / Lecture 1 - Introduction 32 • There are two major types of programming languages – Low level languages (LLL) – High level languages (HLL) Types of programming languages Unit 1 - Programming / Lecture 1 - Introduction 35 • Every language has its strengths and weaknesses • FORTRAN is good for numeric data but not good to organize large program • PASCAL is good for structured and readable programs, but it is not as flexible as C • C++ has powerful object-oriented features, but it is complex and difficult to learn • The choice of PL depends on type of the computer used, type of program, and the expertise of the programmer What makes a good language? Unit 1 - Programming / Lecture 1 - Introduction 36 • Programming on Host Environment: – The environment under which a program is designed, coded, tested & debugged • Operating on Target Environment – The external environment which supports the execution of a program Target Development Environments Unit 1 - Programming / Lecture 1 - Introduction 37 Hello.c Hello.exe Hello.ex e Compiler • Software that translate high-level language (C++, Java, C#, etc) to machine language. • Compiler X can covert high-level Y to machine language Z. Complier Example Intel x86 machine code Motorola 68000 machine code C++ Code C++ Complier for Intel C++ Complier for Motorola Problem • A big problem facing developers is the many different types of processors that run code. • Windows, Macintosh, and Unix machines use a wide variety of hardware, as do personal digital assistants, cell phones, large computers, and other platforms. • One way to make a program work on each of these devices is to translate the program to the native instruction • Much like the native languages of devices. • CIL was originally known as Microsoft Intermediate Language (MSIL). • CIL is a CPU- and platform-independent instruction set. • It can be executed in any environment supporting the .NET framework • Hello World Example in CIL Common Intermediate Language (CIL) Common Language Runtime (CLR) • The Common Language Runtime (CLR) manages the execution of code. • CLR uses Just-In-Time (JIT) compiler to compile the CIL code to the native code for device used. • Through the runtime compilation process CIL code is verified for safety during runtime, providing better security and reliability than natively compiled binaries. • Native image generator compilation (NGEN) can be used to produces a native binary image for the a specific environment. What is the point? .NET Framework Visual Studio .NET Operating System Common Language Runtime .NET Framework (Base Class Library) ADO .NET and XML ASP .NET Web Forms Web Services Mobile Internet Toolkit Windows Forms Common Language Specification C++ C# VB Perl J# … V is u a l S tu d io .N E T CIL • C# compiler translates C# source code into CIL C# source CIL .locals init ([0] class Calc c, [1] int32 sum) newobj instance void Calc::.ctor() stloc.0 // c = ptr to new object ldloc.0 ldc.i4.2 // pass second arg ldc.i4.4 // pass first arg callvirt instance int32 Calc::Add(int32,int32) stloc.1 // sum = retval Calc c = new Calc(); int sum = c.Add(2, 4); C# compiler • What we have described so far will lead us to Platform independent environment. How? • Can we use compiled classes written in X language in a program written in Y language? • VB.NET + C#.NET code Platform and Language Independent Language interoperability • All .NET languages can interoperate C# calling VB.NET class Hello { static void Main() { System.Console.WriteLine(Greeting.Message()); } } Class Greeting Shared Function Message() As String Return "hello" End Function End Class NGEN install time compile • Can compile CIL into machine code when app installed – use native image generator ngen.exe – can speed startup time since code pre-compiled – but cannot do as many optimizations – original IL must still be available for type information CLR IL ngen Execute native image cache machine code C# VB.NET Language variability • Not all .NET languages have exactly the same capabilities – differ in small but important ways class Hello { static void Main() { int i; uint u; } } Class Greeting Shared Sub Main() Dim i as Integer End Sub End Class signed integer unsigned integer signed integer only • Common Language Specification (CLS) defines type subset – required to be supported by all .NET languages – limiting code to CLS maximizes language interoperability – code limited to CLS called CLS compliant Common Language Specification public class Calculator { public uint Add(uint a, uint b) { return a + b; } } not CLS compliant to use uint in public interface of public class
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved