Please answer the following questions in written form 1 How

Please answer the following questions in written form:

1) How do imperative and declarative languages differ?

2) What OOP concepts do C structs fundamentally lack?

3) Why does OOP allow humans to develop larger applications?

4) What is the purpose of a class?

5) Why does the C language force the programmer to do more work and make more decisions?

6) What kind of variables do functional languages have?

7) What defining characteristics do well constructed abstractions have?

Solution

1)Answer:

Imperative Programming:

using the imperative programming language we try to say HOW we want to do something. For this purpose, we use statements that can change the current state of the application.

In imperative programming, you use assignment statements to locate some information in memory to use it later. The wide use of looping statements allows executing sequences of statements. If you want to check whether some condition is met before performing some actions, you can use conditional branching statements.

To better understand how this paradigm works, let’s take a look at a small example. Imagine that we want to change the color of a button after a user clicks it. According to the imperative paradigm, we have to know how we want to do it. Thus, we have to check the current state of the component and manipulate it. Here’s the code example:

if(user.likes()){
  if(!hasBlue()) {
removeRed();
addBlue();
}
} else {
  if(hasBlue()){
removeBlue();
addGrey();
  }
}

Imperative programming is probably the most widely spread paradigm. The most popular examples of imperative programming languages are C++, Java, and PHP. The main characteristics of such programming languages are direct assignments, common data structures, and global variables. Here’s an example of the code written in C++. It calculates factorial using recursion:

#include<iostream>
using namespace std;

int factorial(int n);

int main()
{
  int n;

cout << \"Enter a positive integer: \";
cin >> n;

cout << \"Factorial of \" << n << \" = \" << factorial(n);

  return 0;
}

int factorial(int n)
{
  if(n > 1)
  return n * factorial(n - 1);
  else
  return 1;
}

But despite the high popularity level, we have to admit that imperative programming languages can be non-scalable and sometimes too complicated. Moreover, they’re more error-prone than declarative programming languages.

Declarative Programming:

The term Declarative programming is often used as an opposite to the Imperative programming. Shortly speaking, this paradigm allows you to declare WHAT you want to be done.

This style of developing implies description of the logic of computation but not its control flow. By describing only the result that you want to get from the application (instead of the ways of reaching this result), you can minimize unwanted side effects. Developers describe the results they want to get without explicit description of required steps.

To better understand what we mean, let’s jump to the example with the button that we’ve mentioned earlier. In the case of declarative language and with the use of the React library, it may take the following form:

if(this.state.liked){
  return <blueLike />;
} else {
  return <redLike />;
}

In this example, we’re focused on the UI for a given state. There’s no need in extra checking. We just say what we want our application to do. Without a doubt, now it’s easier to understand what’s going on.

The examples of declarative languages that’ll help you understand the concept are SQL and HTML. When you use one of those, you just describe your goals without specifying how you want to achieve them. For example:

<body>
  <h1>Imperative vs. Declarative UI libraries and Which You Should Choose</h1>
  <p>Different approaches to the development process tend to form the established programming paradigms.</p>
</body>

The declarative programming paradigm is much simpler to understand and much safer to use. It’s more scalable and provides you with the possibility to reuse your code. You don’t have to worry about the implementation details.

4)Answer:

class:

A class can be defined as a template/blueprint that describes the behavior/state that the object of its type support.

In object-oriented programming, a class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods)


Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site