Assignment Briefs 09-10-2022

Explain the concept of an algorithm and describe common lgorithmic techniques and solutions

Task 1

A . Explain the concept of an algorithm and describe common algorithmic techniques and solutions.

What is an algorithm?

An Algorithm is a procedure to solve a particular problem in a finite number of steps for a finite-sized input. The algorithms can be classified in various ways. They are:

  1. Implementation Method
  2. Design Method
  3. Design Approaches
  4. Other Classifications

Implementation Method: There are primarily three main categories into which an algorithm can be named in this type of classification. They are:

  • Recursion or Iteration: A recursive algorithm is an algorithm which calls itself again and again until a base condition is achieved whereas iterative algorithms use loops and/or data structures like stacks, queues to solve any problem. Every recursive solution can be implemented as an iterative solution and vice versa. Example: The Tower of Hanoi is implemented in a recursive fashion while Stock Span problem is implemented iteratively.
  • Exact or Approximate: Algorithms that can find an optimal solution for any problem are known as the exact algorithm. For all those problems, where it is not possible to find the most optimized solution, an approximation algorithm is used. Approximate algorithms are the type of algorithms that find the result as an average outcome of sub outcomes to a problem. Example: For NP-Hard Problems, approximation algorithms are used. Sorting algorithms are the exact algorithms.
  • Serial or Parallel or Distributed Algorithms: In serial algorithms, one instruction is executed at a time while parallel algorithms are those in which we divide the problem into subproblems and execute them on different processors. If parallel algorithms are distributed on different machines, then they are known as distributed algorithms.

B Create a flowchart from the following algorithm.

Step 1: Input a, b, c

Step 2: d  sqrt ( )

Input

a, b, c

d  sqrt(

b x b – 4 x

a x

c

 

Step 3: x1  (–b + d) / (2 x a)

C. Describe computer programming principles.

 Computer Programming is the process of writing, testing, troubleshooting, debugging and maintaining of a computer program. Good programming practices mix art, craft and engineering discipline.

Some of the principles of computer programming are:

  • Keep It Simple, Stupid (KISS)
  • Write DRY Code
  • Open/Closed
  • Composition Over Inheritance
  • Single Responsibility
  • Separation of Concerns
  • Document Your Code etc.

Keep It Simple, Stupid (KISS)

It sounds a little harsh, but it`s one of the most important coding principles to live by. What does KISS mean?

It means you should be writing code as simple as possible. One of the rules of basic programming is to never get caught up in trying to be overly clever or showing off with a thick block of advanced code. If you can write a script in one line, write it in one line.

Write DRY Code

The Don`t Repeat Yourself (DRY) computer programming principle means, plainly, not repeating code. It`s a common coding mistake. When writing code, avoid duplication of data or logic. If you`ve ever copied and pasted code within your program, it`s not DRY code especially if you don’t understand what the code does.

Open/Closed

This principle of programming means that you should aim to make your code open to extension but closed to modification. This is an important principle when releasing a library or framework that others will use.

For example, suppose you`re maintaining a GUI framework. You could release a version for coders to directly modify and integrate your released code. What happens when you release a major update four months later?

Their code will break. This will likely make your cohorts very unhappy. They will be reluctant to use your library for much longer, no matter how helpful it may have been in its heyday.

Instead, release code that prevents direct modification and encourages extension. Basic programming principles like this separate core behavior from modified behavior. The code is more stable and easier to maintain.

Composition over Inheritance

If you write code using object-oriented programming, you`re going to find this principle of programming to be very useful. The composition over inheritance principle states: objects with complex behaviors should contain instances of objects with individual behaviors. They should not inherit a class and add new behaviors.

Relying on inheritance causes two major issues. First, the inheritance hierarchy can get messy in a hurry. You also have less flexibility for defining special-case behaviors.

Single Responsibility

The single responsibility principle states that every class or module in a program should only provide one specific functionality. As Robert C. Martin puts it, "A class should have only one reason to change."

Classes and modules often start off this way. Be careful not to add too many responsibilities as classes get more complicated. Refactor and break them up into smaller classes and modules.

Separation of Concerns

The separation of concerns concept is an abstract version of the single responsibility principle. This idea states that a program should be designed with different containers, and these containers should not have access to each other.

A well-known example of this is the model-view-controller (MVC) design. MVC separates a program into three distinct areas: the data (model), the logic (controller), and what the page displays (view). Variations of MVC are common in today`s most popular web frameworks.

For example, the code that handles the database doesn`t need to know how to render the data in the browser. The rendering code takes input from the user, but the logic code handles the processing. 

Document Your Code

With all of this talk of the principles of coding, it can be easy to forget about the human on the other side who may eventually be getting into your code themselves.

Any senior developer will stress the importance of documenting your code with proper comments. All languages offer them; you should make it a habit to write them. Leave comments to explain objects, enhance variable definitions, and make functions easier to understand.

D. Summarize the historical development of computer programming since 1980s.

            Some notable languages that were developed in this period include:

 

    1980 – C++ (as C with classes, renamed in 1983)

    1983 – Ada

    1984 – Common Lisp

    1984 – MATLAB

    1984 – dBase III, dBase III Plus (Clipper and FoxPro as FoxBASE)

    1985 – Eiffel

    1986 – Objective-C

    1986 – LabVIEW (Visual Programming Language)

    1986 – Erlang

    1987 – Perl

    1988 – Tcl

    1988 – Wolfram Language (as part of Mathematica, only got a separate name in June 2013)

    1989 – FL (Backus)

 

    1990 – Haskell

    1990 – Python

    1991 – Visual Basic

    1993 – Lua

    1993 – R

    1994 – CLOS (part of ANSI Common Lisp)

    1995 – Ruby

    1995 – Ada 95

    1995 – Java

    1995 – Delphi (Object Pascal)

    1995 – JavaScript

    1995 – PHP

    1997 – Rebol

 

    2000 – ActionScript

    2001 – C#

    2001 – D

    2002 – Scratch

    2003 – Groovy

    2003 – Scala

    2005 – F#

    2005 – HolyC

    2006 – PowerShell

    2007 – Clojure

    2008 – Nim

    2009 – Go

    2010 – Rust

    2011 – Dart

    2011 – Kotlin

    2011 – Elixir

    2012 – Julia

    2012 – TypeScript

    2014 – Swift

E. Explain the major components of a programming language of your choice.

Major features of C# programming

    Boolean Conditions.

    Automatic Garbage Collection.

    Standard Library.

    Assembly Versioning.

    Properties and Events.

    Delegates and Events Management.

    Easy-to-use Generics.

    Indexers. 

F. Compare the strengths and limitations of modern computer programming languages.

  • Java – pros: enterprise standard, strong ecosystem; cons: verbose
  • Python – pros: friendly and easy, strong ecosystem; cons: indentation as syntax can be problematic
  • JavaScript – pros: ubiquitous, strong ecosystem; cons: quirky, broken semantics
  • C# – pros: a better Java; cons: complex
  • C++ – pros: excellent code generation, comprehensive design, strong ecosystem; cons: enormously complex
  • PHP – pros: easy, strong ecosystem; cons: quirky
  • C – pros: low-level access, excellent code generation, strong ecosystem; cons: primitive, archaic
  • Ruby – pros: elegant, productive; cons: too much like Perl
  • Perl – pros: strong string-handling; cons: nearly write-only
  • Scala – pros: comprehensive design, JVM ecosystem; cons: complex, nearly write-only
  • Clojure – pros: Lisp for JVM ecosystem; cons: Lisp syntax hard to get used to
  • Haskell – pros: functional superiority; cons: challenging to learn
  • Go – pros: simple and easy; cons: limited ecosystem
  • Swift – pros: Apple-supported, well-designed; cons: not finding traction outside of Apple
  • Kotlin – pros: Java-compatible, well-designed; cons: in the shadow of Java
  • R – pros: strong statistical ecosystem; cons: quirky
  • Objective-C – pros: Apple-supported; cons: inelegant
  • Visual Basic – pros: popular in the enterprise, well-supported; cons: antiquated

Task 2

A. Explain the benefits of Object-oriented design and an evaluate when to use Object-oriented design methodology.

Benefits of object-oriented methodology includes? 

Four (4) Advantages of Object-Oriented Programming

  • Modularity for easier troubleshooting. When working with object-oriented programming languages, you know exactly where to look when something goes wrong. ...
  • Reuse of code through inheritance. ...
  • Flexibility through polymorphism. ...
  • Effective problem solving.
  • Dynamic structure
  • Dynamic data access
  •  Rapid prototyping
  • Polymorphism Inheritance

Until recently, systems design had been largely accomplished with the use of traditional top-down, structured design methodologies. These methodologies were originally developed to help the designer cope with the myriad of complex concepts that must be dealt with when modeling even a simple business system. Structured methodologies, along with their counterpart, the relational data model, have worked admirably well considering their limitations. Unfortunately, the business environment is not becoming any simpler, and new design methodologies are required to cope with the increasing complexity of the business world.

B. Explain how objects are used in Object-oriented programming and the steps in creating an Object-oriented program using your chosen language.

What Is an Object in Programming?

Object-oriented programming, or OOP, is an approach to problem solving where all computations are carried out using objects. An object is a component of a program that knows how to perform certain actions and how to interact with other elements of the program. Objects are the basic units of object-oriented programming. A simple example of an object would be a person. Logically, you would expect a person to have a name. This would be considered a property of the person. You could also expect a person to be able to do something, such as walking or driving. This would be considered a method of the person.

Code in object-oriented programming is organized around objects. Once you have your objects, they can interact with each other to make something happen. Let`s say you want to have a program where a person gets into a car and drives it from A to B. You would start by describing the objects, such as a person and car. That includes methods: a person knows how to drive a car, and a car knows what it is like to be driven. Once you have your objects, you bring them together so the object (person) can get into the car and drive.

Classes and Objects

A class is a blueprint of an object. You can think of a class as a concept, and the object is the embodiment of that concept. You need to have a class before you can create an object. So, let`s say you want to use a person in your program. You want to be able to describe the person and have the person do something. A class called `person` would provide a blueprint for what a person looks like and what a person can do. To actually use a person in your program, you need to create an object. You use the person class to create an object of the type `person.` Now you can describe this person and have it do something.

Classes are very useful in programming. Consider the example of where you don`t want to use just one person but 100 people. Rather than describing each one in detail from scratch, you can use the same person class to create 100 objects of the type `person.` You still have to give each one a name and other properties, but the basic structure of what a person looks like is the same.

Methods and Functions

Once you have created objects, you want them to be able to do something. This is where methods come in. A method in object-oriented programming is a procedure associated with a class. A method defines the behavior of the objects that are created from the class. Another way to say this is that a method is an action that an object is able to perform. The association between method and class is called binding. Consider the example of an object of the type `person,` created using the person class. Methods associated with this class could consist of things like walking and driving. Methods are sometimes confused with functions, but they are distinct.

A function is a combination of instructions that are combined to achieve some result. A function typically requires some input (called arguments) and returns some results. For example, consider the example of driving a car. To determine the mileage, you need to perform a calculation using the distance driven and the amount of fuel used. You could write a function to do this calculation. The arguments going into the function would be distance and fuel consumption, and the result would be mileage. Anytime you want to determine the mileage, you simply call the function to perform the calculation.

C. Explain the impact of style on developing and maintaining programs.

Programming style is a set of rules or guidelines used when writing the source code for a computer program. Following a particular programming style will help programmers read and understand source code conforming to the style and help to avoid introducing errors.

Within the programming industry there is a desire to make software programs easy to maintain. The desire centers on money. Simply put, it costs less money to maintain a well written program. One important aspect of program maintenance is making source code listings clear and as easy to read as possible. To that end we will consider the following:

  1. Documentation
  2. Vertical Alignment
  3. Comments
  4. Indentation
  5. Meaningful Identifier Names Consistently Typed
  6. Appropriate use of Typedef
  7. D.    Explaining how to compile a program and debug codes using your chosen language.

How to compile a program using C#

  1. You write source code in C#.
  2. You then compile it using the C# compiler (csc.exe) into an EXE.
  3. The C# compiler outputs the MSIL code and a manifest into a read-only part of the EXE that has a standard PE (Win32-portable executable) header.
  4. When the compiler creates the output, it also imports a function named "_CorExeMain" from the .NET runtime.
  5. When the application is executed, the operating system loads the PE, as well as any dependent dynamic-link libraries (DLLs), such as the one that exports the "_CorExeMain" function (mscoree.dll), just as it does with any valid PE.
  6. However, since the operating system obviously can`t execute the MSIL code, the entry point is just a small stub that jumps to the "_CorExeMain" function in mscoree.dll.
  7. The "_CorExeMain" function starts the execution of the MSIL code that was placed in the PE.
  8. Since MSIL code cannot be executed directly, because it`s not in a machine-executable format, the CLR compiles the MSIL using the Just-In-Time (JIT) compiler (or JITter) into native CPU instructions as it processes the MSIL. The JIT compiling occurs only as methods in the program are called. The compiled executable code is cached on the machine and is recompiled only if there`s some change to the source code

There are several ways to debug a code and fix it.

Simple methods you can start with include using print statements to print out variables or commenting out part of the code until the error goes away. Using a debugging tool is an advanced method that will allow you to stop the code and inspect it as it is running. Adding tests to your code can help find bugs before they go to production. You can use error handling to report production bugs that you would rather not have users see. Of course, one of the best debugging procedures is simply asking other developers if they know what could be causing a bug and point you in the right direction.

Task 3

Using an OOP language involving multiple objects, design a Snake game that allows users to control the movement of a snake on a screen, to get points for eating food and avoiding running into the walls or the growing tail of the snake itself. In developing the game ensure you use the best software development practice. Finally, implement, test and debug the game.

 

Create the Screen:

import pygame

pygame.init()

dis=pygame.display.set_mode((400,300))

pygame.display.update()

pygame.quit()

quit()

 

import pygame

pygame.init()

dis=pygame.display.set_mode((400,300))

pygame.display.update()

pygame.display.set_caption(`Snake game by Abiodun`)

game_over=False

while not game_over:

    for event in pygame.event.get():

        print(event)   #prints out all the actions that take place on the screen

 

pygame.quit()

quit()

 

import pygame

pygame.init()

dis=pygame.display.set_mode((400,300))

pygame.display.update()

pygame.display.set_caption(`Snake game by Aiodun`)

game_over=False

while not game_over:

    for event in pygame.event.get():

        if event.type==pygame.QUIT:

            game_over=True

 

pygame.quit()

quit()

 

import pygame

pygame.init()

dis=pygame.display.set_mode((400,300))

 

pygame.display.set_caption(`Snake game by Edureka`)

 

blue=(0,0,255)

red=(255,0,0)

 

game_over=False

while not game_over:

    for event in pygame.event.get():

        if event.type==pygame.QUIT:

            game_over=True

    pygame.draw.rect(dis,blue,[200,150,10,10])

    pygame.display.update()

pygame.quit()

quit()

References:

https://www.geeksforgeeks.org/algorithms-design-techniques/

https://www.makeuseof.com/tag/basic-programming-principles/

https://www.quora.com/What-are-the-strengths-and-weaknesses-of-the-different-programming-languages

100% Plagiarism Free & Custom Written, Tailored to your instructions
paypal checkout

Our Giveaways

Plagiarism Report

for £20 Free

Formatting

for £12 Free

Title page

for £10 Free

Bibliography

for £18 Free

Outline

for £9 Free

Limitless Amendments

for £14 Free

Get all these features for
£83.00 FREE

ORDER NOW