-2
$\begingroup$

There exist 5 rules for any pseudocode , one of these rules is : "Keep statements language independent" I don't understand what is this rule is saying. So can someone explain it and then give an example of pseudocode written to be language independent ? Moreover, the source for this rule is "Invitation to Computer Science, 8th Edition by Schneider/Gersting". Thanks in advance

$\endgroup$
3
  • 2
    $\begingroup$ Is your "5 rules for any pseudocode" coming from this blog on pseudocode? Yes or not, please add a reference to the source in your question. $\endgroup$ Commented Sep 27, 2018 at 23:42
  • $\begingroup$ You probably want to clarify whose 5 rules these are. I -1'd because the idea that there are 5 universal rules to pseudocode seems like a silly premise. $\endgroup$ Commented Sep 27, 2018 at 23:53
  • 1
    $\begingroup$ What specifically do you want explained? Do you understand what that rule is saying? Do you want to understand the reason for it? Please share your thoughts. This might help us provide you with better answers. $\endgroup$ Commented Sep 28, 2018 at 4:19

2 Answers 2

1
$\begingroup$

what is meant by independent is that Pseudocode is a description of a computer programming algorithm that uses structural conventions of a programming language, and is intended to be read by humans and not by machines. Pseudocodes usually do not use elements of sufficient detail that are not necessary for the needs of human understanding of an algorithm, such as variable declarations and codes. so that pseudocode is not tied to any programming language and pseudocode can be implemented in any language, whether it's C ++, Java, Python, or the latest programming language.

example

Start
Enter a, b
c = a + b
Print "c"
Finished

here is the same example, enter the values ​​a and b so as to produce a value of c (sum of a + b)

You can use this pseudocode as a basis for making the addition program from different programming languages.

Java

// File name: Sum.java
// Description: The program displays the sum of 2 numbers

// use the Scanner class
import java.util.Scanner;

public class Addition
{
 // the main method before executing the java application
 public static void main (String args [])
 {
  // for the Scanner to get input from the form
  Scanner input = new Scanner (System.in);

  int number1; // first number
  int number2; // second number
  int sum; // number of numbers 1 and 2

  // cursor 1
  System.out.print ("Enter the First Number:");
  // reads input number 1 from the user
  number1 = input.nextInt ();

  // cursor 2
  System.out.print ("Entering the Second Number:");
  // read input number 2 from the user
  number2 = input.nextInt ();

  // sum of numbers
  sum = number1 + number2;

  // displays addition
  System.out.printf ("Sum is% d \ n", sum);
 } // end method
} // end class Addition

{

return(a + b);

}

c++

#include <iostream.h>
void main ()
{
int a, b;
float c;


cout << "Enter a:";
cin >> a;
cout << endl;
cout << "Enter the value b:";
cin >> b;
cout << endl;
c = a + b
cout << "The result is =";
cout << c;
}

that's the 2 code example programming language that uses the same pseudocode. hopefully can help you. :)

$\endgroup$
2
$\begingroup$

The rule means roughly that the statements and constructs should be clear and not be directly expressed in any actual programming language. For example, imagine we want to present a silly toy example for an algorithm that determines if the value 5 is present in an array. Perhaps you have never seen C++, but I still give you the following description:

#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
   std::vector<int> v = { 1, 3, 5, 7 };
   auto iter = std::find(v.begin(), v.end(), 5);
   if(iter != v.end())
      std::cout << "found 5\n";
}

You might be confused and say "what include?", "what std::?", "what vector, find, auto, cout, <<, what is all this garbage?". And you would be absolutely right. My use of a concrete programming language is cluttering the presentation and obscuring what I really want to get across. So here's one possible pseudocode implementation of the above, in the spirit of the rule you mention:

A[1..4] = [1,3,5,7]
for i = 1 to 4:
   if A[i] == 5:
      print "found 5"

The logic behind the algorithm should be much clearer from this description to someone who has never seen C++ or some specific programming language I might have used.

$\endgroup$
2
  • $\begingroup$ "not be directly expressed in any actual programming language" That's overstating it. There's no reason at all that I can't write "if (A[i] == 5)" and call it pseudocode, even though C and Java both use that syntax. And your "if A[i] == 5:" doesn't somehow become invalid if somebody writes a compiler for a language with that syntax. $\endgroup$ Commented Oct 9, 2018 at 23:07
  • $\begingroup$ @DavidRicherby I don't disagree, but I couldn't think of a better way of expressing it. I think what you mention is right but a side issue, and the example makes my answer clear. $\endgroup$ Commented Oct 10, 2018 at 6:32

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.