In: Computer Science
What are the types of 5th generation languages write code in each of those languages and please provide output also
thank you
There are four types of 5th generation languages:
(A). Procedural language: It is a structured programming language in which the code is written as sequence of instructions.
code: #include<stdio.h>
int main() {
int n1, n2, sum;
printf("enter the numbers ");
scanf("%d %d", &n1,&n2);
sum=n1+n2;
printf("%d+%d=%d", n1, n2, sum);
return 0;
}
output:
enter the numbers 5
6
5+6=11
(B). Object-Oriented Language: This use objects to store data and code instead of functions.In this language, we can define the data type of a data structure and the type of operations that can be applied to the data structure
code:
#include <iostream>
using namespace std;
int main()
{
int firstNumber, secondNumber, sumOfTwoNumbers;
cout << "Enter two integers: ";
cin >> firstNumber >> secondNumber;
// sum of two numbers in stored in variable
sumOfTwoNumbers
sumOfTwoNumbers = firstNumber + secondNumber;
// Prints sum
cout << firstNumber << " + " << secondNumber
<< " = " << sumOfTwoNumbers;
return 0;
}
output:
Enter two integers: 6
8
6+8=14
(C). Functional Programming language: It is based on mathematical functions.
code:
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
int main() {
char str[20] = "Hello World";
int len;
len = strlen(str);
cout<<"String length is: "<<len;
return 0;
}
output:
String length is: 11
(D). Logical programming languages: Logic programming is a programming strategy that uses logic circuits to control how facts and rules are expressed, rather than only mathematical functions.
code:
#include <stdio.h>
int main() {
int a = 1;
int b = 0;
if ( a && b ) {
printf("This will never print because condition is false\n"
);
}
if ( a || b ) {
printf("This will be printed print because condition is true\n"
);
}
if ( !(a && b) ) {
printf("This will be printed print because condition is true\n"
);
}
}
output:
This will be printed print because condition is true
This will be printed print because condition is true