Hello, Today we will go through rpcbind for Remote Procedure call in Distributed System.
In distributed computing, a remote procedure call (RPC) is when a computer program causes a procedure (subroutine) to execute in a different address space (commonly on another computer on a shared network), which is coded as if it were a normal (local) procedure call, without the programmer explicitly coding the details for the remote interaction.  [Source:- Wikipedia]
What is rpcbind?
The rpcbind utility is a server that converts RPC program numbers into universal addresses. It must be running on the host to be able to make RPC calls on a server on that machine. - [ $ man rpcbind ]

Install rpcbind -> sudo apt-get install rpcbind

Today we will make a simple RPC for factorial.

First make a .x file
1
2
3
4
5
6
7
8
9
10
struct values{
 int num1;
};

program Fact{
 version fact_verse{
  float fac(values) = 1;

 } = 1;
} = 456789;

Here we have a struct called values and a program Fact
save the file. For now we will save as fact.x

Now the file is created run
rpcgen -aC fact.x

Now there are several middleware files created. Among them, we need to edit that fact_client.c and fact_server.c

Here is fact_client.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * This is sample code generated by rpcgen.
 * These are only templates and you can use them
 * as a guideline for developing your own functions.
 */

#include "test.h"


float
fact_1(int argc, char *host)
{
 CLIENT *clnt;
 float  *result_1;
 values  fac_1_arg;
 fac_1_arg.num1 = argc;

//#ifndef DEBUG
 clnt = clnt_create (host, Fact, fact_verse, "udp");
 if (clnt == NULL) {
  clnt_pcreateerror (host);
  exit (1);
 }
//#endif /* DEBUG */

 result_1 = fac_1(&fac_1_arg, clnt);
 if (result_1 == (float *) NULL) {
  clnt_perror (clnt, "call failed");
 }
//#ifndef DEBUG
 clnt_destroy (clnt);

 
//#endif  /* DEBUG */
 return *result_1;
}


int
main (int argc, char *argv[])
{
 char *host;
 int num, ans;
 printf("Enter a number");
 scanf("%d",&num);

 if (argc < 1) {
  printf ("usage: %s server_host\n", argv[0]);
  exit (1);
 }
 host = argv[1];
 ans = fact_1 (num,host);
 printf("the factorial is %d",ans);
exit (0);
}
Here we accept a number from the users. change the fact_1 method to accept another int and return int. Also, remember our main methods accepts several args. You need not write the whole program, you will edit it once created by rpcgen.

Here is fact_server.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
 * This is sample code generated by rpcgen.
 * These are only templates and you can use them
 * as a guideline for developing your own functions.
 */

#include "test.h"

float *
fac_1_svc(values *argp, struct svc_req *rqstp)
{
 static float  result;

 /*
  * insert server code here
  */
 int var = argp->num1;
 int ans = factorial(5);
 printf("in server %d",ans);
 
 result = ans;
 return &result;
}

int factorial(int a){
 if (a==1)
  return 1;
 else
  return a*factorial(a-1);
}

In the server file we just get the number from the argp parameter, which is the struct we created in the .x file. calculate the factorial and return it.

Have a good day :)

Wait... How to run?

Once you perform the necessary changes, you can make the executable files for that run make -f Makefile.fact
Where do the Makefile.fact came from? It will be created while running the rpcgen command.

Run server $ ./fact_server
Open another terminal run client $ ./fact_client localhost
Prolog is a logic programming language associated with artificial intelligence and computational linguistics.

It's my First day of Prolog and here is the Half Added login in Prolog. It is not a solution but it just works.
1
2
3
4
5
6
7
8
high(1).
low(0).

xor(X,Y,Sum) :- (((low(X) , low(Y)) ; (high(X) , high(Y))) , low(Sum)) ; (((low(X) , high(Y)) ; (high(X) , low(Y))) ,high(Sum)).

and(X,Y,Carry) :- (high(X), high(Y), high(Carry)) ; (((low(X) , low(Y)) ; (low(X) , high(Y)) ; (high(X) , low(Y))) , low(Carry)).

half_adder(X,Y,Sum,Carry):- xor(X,Y,Sum) , and(X,Y,Carry).

for Xor -> if [(X and Y is low or X and Y is high) and sum is low. ] OR [ (if X is low and Y is high or X is high and Y is low) and Sum is high]

for and -> if (X is high and Y is High And Carry is high) OR [(if X is low and Y is low or X is low and Y is high or X is high and Y is low)  and Carry is low]

low = 0 and high = 1

Output:
prolog task3.pl

The half adder adds two binary digits called as augend and addend and produces two outputs as sum and carry; XOR is applied to both inputs to produce sum and AND gate is applied to both inputs to produce carry. The full adder adds 3 one bit numbers, where two can be referred to as operands and one can be referred to as bit carried in. And produces 2-bit output, and these can be referred to as output carry and sum.


Half - Adder Truth Table
Thank you!
Hello here is a simple java program for file Handling. Here first we store the "java Programming" string into a file named "hi.txt" then we read the "hi.txt" and write it to another file "hello.txt" as well as display in the standard output. Then we read from Standard input and insert it into namaste.txt

Here is the code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.io.*;
public class FileHandler {
	public static void main(String args[]) throws IOException{
		System.out.println("Here");

		FileReader reader = null;
		FileWriter writer = null;
		InputStreamReader input = null;

		String message = "Java Programming";
		try {
			writer = new FileWriter("hi.txt");
			int i = 0;
			for(i = 0; i<message.length(); i++) {
				//System.out.println(message.charAt(i));
				int charInt = (int) message.charAt(i);
				writer.write(charInt);
			}
		} catch(Exception e){
			//handle the exception
			e.printStackTrace();
		} finally {
			//Always close reader or writer
			if(writer != null) // prevent another exception
				writer.close();
		}
		try {
			reader = new FileReader("hi.txt");
			writer = new FileWriter("hello.txt");
			int c;
			while((c = reader.read()) != -1) {
				char intChar = (char) c;
				System.out.print(intChar);
				writer.write(c);
			}
			System.out.println();
		} finally {
			if(reader != null)
				reader.close();
			if(writer != null)
				writer.close();
		}
		try {
			input = new InputStreamReader(System.in);
			writer = new FileWriter("namaste.txt");// greeting
			char c;
			System.out.println("Enter q to quite.");
			do {
				c = (char) input.read();
				if (c != 'q') { // won't store q
					writer.write(c);
				}
			} while (c != 'q');
		} finally {
			if(input != null)
				input.close();
			if(writer != null)
				writer.close();
		}
	}
}

We need to declare the variables (6,7,8) outside the try catch block as we need to close them in the finally block if they are used.
We iterate through the String to get each char to write in file (line 14), message.charAt(2) will return the char at index 2 of that String.
(Line 24) we must close the opened file. check it is not null before closing so it won't generate another exception (no file opened to close)
(Line 32) Type casting from int to char.
(Line 49) input.read() waits till users enter a char in the Terminal.

Thank you! Have a good day!

The Static Keyword means that the variables or methods are shared between all instances of that class as it belongs to the type, not the actual objects themselves.

So you can access static method of a class without it's object. For non static methods, every methods are associated with a object so you should call those non static method using your object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class Test {
    private int countObj;
    public Test() {
        countObj++;
    }
    public static void main(String args[]) {
        System.out.println("Hello, I am static.");
        aStatic();
        System.out.println("Calling non Static Method Directly.");
        nonStatic(); // not allowed
        Test aTest = new Test;
        System.out.println("Calling non Static Method via from object");
        aTest.nonStatic(); // Allowed 
    }
    static void aStatic() {
        System.out.println("Inside aStatic");
    }
    void nonStatic() {
        System.out.println("This is non Static Method.")
    }
}

We can call static methods from any methods of type class with it's name only, where as we need to specify the class to call from other class methods. Test.aStatic();
the countObj is a static variable so it is same for all the instance of the class. It will count the object created.
Thank you!
database management system.
query language.
structured query blanguage.
database design, store, update retrive data.
DDL data defination language. define structure (tubular form). eg create
DML Data manupulation language. systex to manupalate data, insert delete update, truncate, alter
DCL DAta control language, access specification, grant, revoke.

Truncate only erase values, structure remain same. only for table.
delete individual element and tables.

Lab...
Oracal Database Express Eddition

only one comand at a time.


Some commands:
create table t(id int, name varchar);

insert into t values(1, "test");
or
insert into t(id, name) values(2, "test2");

select * from t;
select id,name from t;
select * from t where id = 1;
select id from t where id = 1;5:52 AM 12/23/2002
Java is a general purpose programming Language. James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. This was initially called "Oak", which was renamed as "Java" in 1995. The development motive of java was to make a platform independent language that can create create softwares that can be embedded in various consumer electronic devices.

General Purpose Programming Language

A general-purpose language is a computer language that is broadly applicable across application domains, and lacks specialized features for a particular domain. This is in contrast to a domain-specific language (DSL), which is specialized to a particular application domain.

Features of java

  • Simple
  • Object-Oriented
  • Robust
  • Multihreaded
  • Architecture-Neutral
  • interpreted and High Performance
  • Distributed
  • Dynamic
  • Secure
  • Portable
A Simple java Program:

class JavaFirst
{
    public static void main(String args[])
    {
        System.out.println("Hello World!");
    }
}

Java Keywords


abstract final public
assert finally return
boolean float short
break for static
byte goto strictfp
case if super
catch implements switch
char import synchronized
class instanceof this
const int throw
continue interface throws
default long transient
do native true
double new try
else null void
enum package volitile
extends private while
false protected

Enhanced For Loop in Java

Enhanced loop was introduced on java 5. It is used to loop through the Arrays.
class LoopTest
{
    public static void main(String args[])
    {
         int numbers[]={10,11,12,13,14};
         for (int i : numbers)
         {
              System.out.println(i);
          }
     }
}
The Output of the Loop will be:
10
11
12
13
14

Array Declaration in Java

int [] a, b, c;
will create 3 arrays a, b and c
int a[], b ,c[];
will create 2 arrays a and c, where as a int variable b.

If we use the [] in front it will create all the variables as array.

Strings

In java String are not simply an array of characters. String is defined as objects. String are used to declare String variables. String objects have many special features and attributes that make them powerful.
.toUpperCase()
.toLowerCase()
.compareTo()
.indexOf()
.charAt()

The Bitwise Operators

Java defines several bit-wise operators which  can be applied to the integers, long, short, char and byte. Bit-wise operator works on bits and perform bit by bit operations.
Where a = 60 and b = 13
a = 0011 1100
b = 0000 1101
(Binary AND) a&b = 0000 1100
(Binary OR) a|b = 0011 110.1
(Binary XOR) a^b = 0011 0001
(Binary NOT) ~a = 1100 0011

Argument Passing

Call by Value and Call by Reference
When a primitive type is passed to a method, it is done by use of call-by-value. Object are implicitly passed by use of call-by-reference. 
Hello here is java code to change Infix expression to PostFix expression. infix expression is the expression we understand and do algebraic manipulation using BODMAS rule. Compilers uses PostFix expression to do calculation. Here we would make use of the stack we discussed in the previous articles.

If you are beginner in Java. The block at 10 - 13 is a initialization block.
Using constructor we set the max Size and the size of array to of that maxSize.
The core of this code is the method inToPostFix() Here we could explain the Algorithm in words

  1. Initialize the empty stack.(astack[])
  2. Scan each character of the given infix expression from left to right. (theExpression.charAt(i))
  3. If the scanner Character is an Operand then add it to post fix string (theFinalExpression)
  4. If the scanned character is an operator then
    1. If the stack is empty, push the scanner operator int the stack.
    2. If the stack is not empty then compare the precedence of the operator at the top of the stack. If the precedence of scanned is less then or equal to the precedence of operator at TOS, then pop TOS and add it to postfix string and push the scanned operator into the TOS. If the precedence of the scanned operator is higher then the operator at TOS then push operator to the stack.
  5. If the scanned character is opening parenthesis then push it on to the stack and continue the above process steps until closing parenthesis is not scanned. When we get closed parenthesis then pop the operators from the stack until we reach opening parenthesis and then pop opening parenthesis from stack.
  6. The process is continued until all the characters of infix expression are scanned. and pop all the remaining operators from stack and add them in to the postfix string in the way they pop out.
Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import java.util.Scanner;
class InToPostFix
{
 int maxSize;
 char astack[];
 int TOS;
 String theFinalExpression;
 String theExpression;
 
 {
  TOS = -1;
  theFinalExpression = "";
 }
 
 InToPostFix(int maxSize, String theExpression)
 {
  this.maxSize = maxSize;
  this.astack = new char [maxSize];
  this.theExpression = theExpression;
 }

 void inToPostFix()
 {
  for(int i = 0; i< maxSize ;i++)
  {
   char element = theExpression.charAt(i);
   if(isOperand(element))
    theFinalExpression = theFinalExpression + element;
   else if(isOperator(element))
   {
    if(stackIsEmpty())
     push(element);
    else
    {
     int a;
     a = checkThePrecedence(element);
     if(a == 3) // element is of higher precedence:w
      push(element);
     else if(astack[TOS] != '(')
     {
      char operator = pop();
      theFinalExpression = theFinalExpression + operator;
      push (element);
     }
    }
   }
   else if(element == '(')
    push(element);
   else if(element == ')')
   {
    char temp;
    while(astack[TOS] != '(')
    {
     temp = pop();
     theFinalExpression = theFinalExpression + temp;
    }
    pop();// Remove the '(' from stack
   }
  }
  //while(!(stackisEmpty())):q
  while(TOS != -1)
  {
   char temp = pop();
   theFinalExpression = theFinalExpression + temp;
  }
 }

 char pop()
 {
  char item = astack[TOS];
  TOS -= 1;
  return item;
 }
 
 int checkThePrecedence(char element)
 {
  char item = astack[TOS];
  int assign, assign2;
  if (item == '$')
   assign = 3;
  else if (item == '*' || item == '/')
   assign = 2;
  else //(item == '+' || item == '-')
   assign = 1;
  if (element == '$')
   assign2 = 3;
  else if(element == '*' || element == '/')
   assign2 = 2;
  else //(element == '+' || element == '-')
   assign2 = 1;
  if(assign2 > assign)
   return 3; // element is of higher precedence
  else if(assign2 == assign)
   return 2; // element is in same as in stack
  else //(assign2 < assign)
   return 1; // element is of lower precedence
 }

 boolean stackIsFull()
 {
  if(TOS == maxSize - 1)
   return true;
  else
   return false;
 }

 boolean stackIsEmpty()
 {
  if(TOS == - 1)
   return true;
  else
   return false;
 }
 
 void push(char element)
 {
  TOS += 1;
  astack[TOS] = element;
 }
 
 static boolean isOperand(char element)
 {
  if((element >='a' && element <='z') || (element >='A' && element <='Z'))
   return true;
  else
   return false;
 }
 
        static boolean isOperator(char element)
        {
                if(element == '+' || element == '-' || element == '*' || element == '/' || element == '$')
                        return true;
                else
                        return false;
        }

 void displayFinal()
 {
  System.out.println("The Final Exptession is:-\n" + theFinalExpression);
 }

 public static void main(String []args)
 {
  Scanner input = new Scanner(System.in);
  Scanner input2 = new Scanner(System.in);
  System.out.println("Enter the InFix expression");
  String theExpression = input.nextLine();
  int maxSize = theExpression.length();
  InToPostFix inToPostFix = new InToPostFix(maxSize, theExpression);
  inToPostFix.inToPostFix();
  inToPostFix.displayFinal();
  int option;
  int next = 1;
  while(next == 1)
  {
   System.out.println("Option:- \tTo do:\n1\tConvert another expression\n2\tExit this program");
   option = input2.nextInt();
   switch(option)
   {
    case 1:
    {
     System.out.println("Enter the InFix expression");
     theExpression = input.nextLine();
     maxSize = theExpression.length();
     InToPostFix inToPostFixOb = new InToPostFix(maxSize, theExpression);
     inToPostFixOb.inToPostFix();
     inToPostFixOb.displayFinal();
     break;
    }
    case 2:
    {
     next = 0;
     System.out.println("Thank you:)");
     break;
    }
    default:
     System.out.println("Please Enter a valid option");
   }
  }
 }
}

Here we use $ for power operation. Power has the highest precedence. We use while loop in the main function and switch case to match the options you selected and call the selected methods. If I need to explain any of the code above I will always be available in the comment section. Thank you!
Hello here is Circular Queue. Here we create two separate file for the class and the main method. Everything is simple and common code here. I would like to introduce a new style to initialize a instance variables. The code block from line no 7 to line no 10 on CircularQueue.java is a Initialization Block. The benefit of creating any initializing block is that every constructors on the class would use the block to initialize variables. To initialize the static variables we just use static keyword before the block.

Here is CircularQueue.java file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class CircularQueue
{
 int maxSize;
 int rear;
 int front;
 int aQueue[];
 {
  rear = -1;
  front = -1;
 }
 CircularQueue(int maxSize)
 {
  this.maxSize = maxSize;
  this.aQueue = new int[maxSize];
 }
 void enQueue(int item)
 {
  if(((rear+1) % maxSize) == front)
  {
   System.out.println("Queue is Full");
  }
  else
  {
   if (rear == front && front == -1)
   {
    front += 1;
   }
   rear = (rear+1) % maxSize;
   aQueue[rear] = item;
  }
 }
 void deQueue()
 {
  if(rear == front && rear == -1)
  {
   System.out.println("Queue is Empty.");
  }
  else
  {
   int item = aQueue[front];
   if(rear == front)
   {
    rear = -1;
    front = -1;
   }
   else
   {
    front = (front + 1) % maxSize;
   }
   System.out.println(item + " is deQueued from the Queue");
  }
 }
 
 String elementOrElements()
 {
  String send = (rear == front)? (" ") :("s ");
  return send;
 }
  
 void display()
 {
  int tmpfront = front;
  if(rear == front && rear == -1)
                {
                        System.out.println("Queue is Empty.");
                }
                else
  {
   System.out.println("The element"+ elementOrElements() + "on the Queue are:- ");
   for(int i=0; i<maxSize ; i++)
   {
    if(tmpfront != rear)
    {
     System.out.println(aQueue[tmpfront]);
     tmpfront = (tmpfront + 1) % maxSize;
    }
    else
    {
     System.out.println(aQueue[rear]);
     break;
    }
   }
  }
 }
}

And Here is CircularQueueTest.java file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Scanner;
public class CircularQueueTest
{
 public static void main(String []args)
 {
  Scanner input = new Scanner(System.in);
  System.out.print("Enter total no of elements to be in the queue:- ");
  int maxSize = input.nextInt();
  CircularQueue queue = new CircularQueue(maxSize);
  int select;
  int term = 0;
  while (term == 0)
  {
   System.out.print("\nOption:\tTo Do:\n1\tTo push element.\n2\tTo POP element.\n3\tTo Display the Queue elements.\n4\tTo Exit the Program.\nEnter your option:- ");
                 select = input.nextInt(); 
   switch(select)
   {
    case 1:
    {
     System.out.print("Enter element to insert in the Queue:- ");
     int ele = input.nextInt();
     queue.enQueue(ele); 
     break;
    }
    case 2:
    {
     queue.deQueue();
     break;
    }
    case 3:
    {
     queue.display();
     break;
    }
    case 4:
    {
     term = 1;
     System.out.println("Thank you!");
     break;
    }
    default:
     System.out.println("Enter a valid options");
   }
  }
 }
}

To fully understand this code you need to figure out what actually (front + 1) % maxSize do. Take your time and do some calculation. It would be better if calculate it and figure out it by yourself.

Hint:- (front + 1) % maxSize and (rear+1) % maxSize will always return 0 or < maxSize.
Hello Today we are here with a code of Stack Implementation using Array. We had already discussed about stack. Here we use 3 methods
1. To Push the elements
2. To POP the element
3. To display the elements on the stack.

This is no complex code. What we need to remember is that we should initialize TOS as -1 initially. Most beginner users could face error on the 6th and 11th line of code. Here at first we first create a reference variable at line 6 and  create required length array in line 11.
If we use int aarray = new int[MaxSize]; in the class, it will create a zero-length array. as int MaxSize; means int MaxSize = 0;

Other are really simple algorithms. we need to check if Stack is full while pushing and need to check if stack is empty while using pop.

We need to increment TOS everytime we push a element and decrement whenever we pop a element.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.Scanner;
class Stack
{
 int TOS = -1;
 int MaxSize;
 int aarray[];
 
 Stack(int Max1Size)
 {
  this.MaxSize = MaxSize;
  this.aarray = new int[MaxSize];
 }
 void push(int a)
 {
  if(TOS == MaxSize - 1)
  {
   System.out.println("Stack is Full");
  }
  else
  {
   TOS += 1;
   aarray[TOS] = a;
   System.out.println(a +" is inserted in the Stack");
  }
  return;
  
 }
 void pop()
 {
  if (TOS == -1)
  {
   System.out.println("Stack is Empty.");
  }
  else
  {
   int item = aarray[TOS];
   TOS -= 1;
   System.out.println(item +" is poped Out from the Stack");
  }
  return;
 }
 void display()
 {
  if (TOS == -1)
  {
   System.out.println("Stack is Empty.");
  }
  else
  {
   System.out.println("Elements in Stack are:- ");
   for(int i = TOS; i >= 0; i--)
   {
    System.out.println(aarray[i]);
   }
  }
  return;
 }
}
public class StackTest
{
 public static void main(String args[])
 {
  Scanner input = new Scanner(System.in);
  System.out.println("Enter Maximum size of array");
  int MaxSize = input.nextInt();
  Stack astack = new Stack(MaxSize);
  int next = 0;
  while( next == 0)
  {
   System.out.println("\nOption:- \t To Do\n1 \t Push to stack. \n2 \t Pop from stack\n3 \t Display stack \n4 \t Exit the program");
   int select = input.nextInt();
   switch(select)
   {
    case 1:
     {
      System.out.println("Enter the element to push in the stack");
      int element = input.nextInt();
      astack.push(element);
      break;
     }
    case 2:
     {
      astack.pop();
      break;
     }
    case 3:
     {
      astack.display();
      break;
     }
    case 4:
     {
      next = 1;
      System.out.println("Thank You! :)");
      break;
     }
    default:
     {
      System.out.println("Please Enter a valid OPtion.");
      break;
     }
   }
  }
 }
}

This one of the code I had written at college in practical of DSA. Thank you :)
Please Follow How to Create Facebook Friends Day Video.
Today is facebook 14th Birthday. On that occasion facebook allow users to share video with friends. Sharing what they think about them. You can also share the facebook friends day video. There are a lots of options (award) to give to friends All of them are predefined, Facebook will create a short video for your friends. You could publish it on his/her timeline or can send him/her a private message.


History of Facebook?

On February 4, 2004, Mark Zuckerberg launched “Thefacebook”, originally located at thefacebook.com. In 2005, the company dropped “the” from its name after purchasing the domain name facebook.com for US$200,000 The domain facebook.com belonged to AboutFace Corporation before the purchase.

Mark Zuckerberg mention that he had made a lots of mistakes during the development of facebook. He mention "I’ve made dozens of technical errors and bad deals.", He also "I’m proud of what we do and grateful to be a part of something so meaningful." Facebook said there are a lots of path to go and they will work on to Improve Facebook.

Make Facebook Friends Day Video

We had already published this on Time and Update but due to some Server Error we could not serve that page. The Title is How to Create Facebook Friends Day Video.

You can make Facebook Friends Day Video just by following this link. facebook.com/friendsday. Then click in the Create options, Now select a friend and award a option that suits best. Now you can Click in next and confirm whether to send via message or Publish on his Timeline. Conform the process. You can also follow this video Guide.
      

Now it would take some time (about 30 secs ) for your video to be prepared, Then your friend and you can access that video if it was sent of message. If you posted on friends Profile it would be available to public to view.

Most Selected Awards in Facebook Friends Day

Facebook announced that they also celebrate the friends day and they will update the most selected awards among the facebook. Here is the most selected awards till now. There may be alter in ranking of the most selected awards. You can always find that on the friends day page.

Please do comment which of the award you give to most of your friends. I would select the 3rd one to my Friends as they always have my back when I don't have.
Hello, welcome back we are here with the next article of Get Started with Java Programming. Here we would be talking about Data Type, Operations, Decision Statement and loops. Java supports boolean data types as a primitive data type.

Data Type

Data type specify the the size and type of the values to be stored in the variable. Java have lots of data types which allow programmers to select appropriate data type they needed. In Java we can categorise data types into "Primitive types" and "Derived types". We will be discussing about build-in types(Primitive).

Integer Types

Integer can hold whole numbers. Java supports four type of integers, bytes, short, int, long. The size of the values that can be stored in a variables depends upon the type of integer. In the table below we specify Types size and value range:-
Type Size Minimum Value Maximun value
bytes One byte -128 127
short Two bytes -32768 32767
int Four bytes -2147483648 2147483647
long Eight bytes -9223372036854775808 9223372036854775807

Floating Point Types

floating point types can hold number combination fractional numbers. In Java there are two types of floating point integer float and double. In the table below range and size of these two types are specified. Floating points supports a special value know as Not-a-Number(NaN). NaN is used to represent the result of operation as dividing by zero. Float are of 4 bytes whereas double are of 8 bytes.

Other Types:

char:- Char is used to store character value in Java program.  This type is of 2 bytes but can hold only one single character.
boolean: In Java boolean is accepted as a primitive data type. Whenever we have to test a condition during the execution of the program this can be used. There are only two possible values of boolean type:- true or false. This use only one bit of storage.

Operators

A operation is symbol that tells the computer to perform certain mathematical or logical operations. we can classified into a numbers of categories:-
Arithmetic:- Used to conduct mathematical expressions as in algebra. +, -, *, /, % We can use Arithmetic operations on any build in data type except boolean type.
Lets Learn more about % operator:- the % operator will gives the remainder of the number. a % b will give the remender number (the remember while dividing a by b). The symbol of the value of the % will be based on the numerator.
10 % 3 == 1
10 % -3 == 1
-10 % 3 == -1
-10 % -3 == -1

Logical Operator:- && (and), ||(Or), !(Not). Logical operator will yield a value either true or false.
Var1 Var1 Var1! Var1 && Var1 Var1 || Var1
ture ture false ture ture
ture false false false ture
false ture ture false ture
false false ture false false

Relational Operator:- > , < , >= , <= , != Relation operator is used to compare two quantities. We can use these operation on selecting some task whenever some condition is satisfied.
Assignments Operator:- = , -= , += , *= , /= , %=
a +=b is similar to a = a + b
Equality:- == To show that thow of them are equal.
Unary:- ++ , -- Used for increment or decrement A = A + 1 is similar to A++
Ternary (conditional):- ?: Used as in if else condition. (Expression)?(Do this if true):(else do this);

Decision Statements

Decision statement are to make decision the the basic of the condition whether it is true or false. Java supports two discussion statements.
1. if statement
2. switch statement

if statement

if statement is used in decision making during the execution of the program. The if statement take of the following form:
if (condition)
{
    statements;
}
If the condition is true the statement will be executed else it will be skipped. Depending upon the complexity of the program if can takes various form as below:
  • if statement
  • if .. else statement
  • nested if else statement
  • else if statements 

Switch Statements

In switch statement statements are executed upon the required case are true. Switch case takes the following form.
switch (case){
case 1:
statement1;
case2:
statement2;
}
The program will check for the value of the variable case if it matches 1 statement1 will be executed if 2 statement2. we can define the default option in switch case too in case non case satisfied the statement in the default will be executed.

We can use any data types in if statements and any expression are accepted in if statements. But we can only make equality comparison on switch and only accept integer, char and Strings (allowed by Java SE 7).

Looping in Java

Java supports all the three looping namely while, do while and for loop. Loops are used when we need to execute certain part of the program repitately. Whenever a loop check the condition while entering in the loop such loop is known as entry control loop. When a loop checks the condition at exit such looping is known as exit control loop. While and for loop are entry control loop where as do while is exit control loop. We can set certain number of turns or we can set till some conditions happens.
Stack is a data structure, which is not provided by any programming language as fundamentals data type. The last element inserted will be on top of the stack. Since deletion is done from same end, last element inserted will be the first element to be removed out from the stack and so on.

A stack is ordered collection of homogeneous data elements where the insertion and deletion operations only occurs at one end. The end is often known as Top Of the Stack (TOS).

As stack is not provided by any programming language we need to create our own stak. Use of control + Z (undo) is done through the use of Stack, Reversing of the string and checking the validation and matching the parentheses in programming language in compiler are done using programming language.

How Stack Works?

Stack is a one ended operation system. There are only two operations permitted in stack, Push and pop. Push to insert in the stack where as pop to delete the element form the stack. The TOS (Top Of the Stack) always point to the top position where the next can be popped off. We can add another element on the (TOS + 1).

When ever we try to push to the stack when the stack is full then we get the error which is known as Stack Overflow. Whenever we try to pop out from the empty stack then we get an error which is known as stack underflow.

When the stack is empty TOS = -1 When we insert the first element the TOS will be on 0. When we add another element again the TOS will be 1 and so on. So when new element is inserted the TOS will be incremented. When we pop the element the TOS will reduced by one. Let say TOS is on 5 now. when we pop a element, New TOS will be 4 then when we pop again the TOS will be 3 and so on. As we will get an error when we try push to the stack which is full and try to pop from the empty stack so we should always check whether we can pop and push or not.

Stack Implementation

we can implement stack using these two ways:
Static implementation: Using array
Dynamic Implementation: Using linked list

Static Implementation

Here we use array to realize the principle of stack. In array we can insert the data and access the data. Here we use the array in a such a way that we will insert the element in the TOS and access the element from TOS. So by default when the stack is empty TOS is -1. (As array begins with 0, we make TOS to -1 for easiness). Then we insert the element in the TOS+1 location of the array. So we pass element to be added, array and the TOS when ever we want to insert data in the Stack. And in the same way we will remove a data from the stack and reduce the TOS by one, thus we pass array and TOS during pop.

Algorithm:
#define MAX=5
push(s[MAX],element,TOS)
  if TOS == MAX - 1
    display "Stack is full"
  else
    TOS = TOS+1
    s[TOS] = element
  return;

pop(s[MAX],TOS)
  if TOS == -1
    display "Stack is Empty"
    return 0
  else
    element = s[TOS]
    TOS = TOS -1
    return element

Application of Stack

It is used in recursive function calling. Function calling and returing process are in reverse order.
It is used to reverse a string.
It is used to evalutate and check the correction ness of the mathematical operation.
Implementation by word processors to perform UNDO REDO operations.
Used in parenthesis matching by compilers.

Details of the examples

How Parenthesis matching by compiler using Stack?

In every programming language there must be even numbers of parenthesis in the program. Here we will discuss how stack helps on parenthesis matching. So when we open a parenthesis the program will save that on the stack and search for next parenthesis. If it find another opening parenthesis it will add that on the stack again. And again keep looking for the parenthesis. When a closing parenthesis is found it will remove the pair (Opening and Closing) together and keep looking for parenthesis. If at the end The stack is empty there is not error in parenthesis else of the stack is not empty, there must error in parenthesis.

Stack for UNDO and REDO

Every actions will be stored in stack. so when we undo it the last command will be removed. if undo again the second last command and third last and going on..... In the same way the poped commands will be stored in another stack in case of REDO. so when we press redo we will get the last undo and the undo then after and then after.
We will be discussing about data structure. You should have knowledge in basic programming. We will be using C and Java for some example programming. Here we would discuss about Array, Structure, Pointer and Class. These are the topics we will be using throughout this article series in Data Structures.

Array

Array is primitive data member provided by C programming. Array is the collection of similar data types. Memory allocation of the array is sequential. ie. Array are stored in contiguous block of memory. Array only supports similar data type. Strings are the array of character with \0 at the end. \0 = NULL

Structure

Structure is the collection of different type of data type. In C programming Structure is the only way to create complex data type. Structure is the heterogeneous collection of data. Theoretically it will not occupy any memory unless we create the variable of that Structure. Memory allocation  of structure is sequential. We can access members of array with dot operation(.) and Arrow operation(->). Dot operation is used to access memory of structure variables. and Arrow operation is used to access members from Pointer of the structure.

1
2
3
4
5
6
struct Person
{
    char name[30];
    int age;
    char address[40];
}

Self Referencial Structure

The structure that is pointing to self is called self referential structure. Ie a member of structure is pointer to that structure
struct list

1
2
3
4
5
struct List
{
    int age;
    struct List *next;
}

Union

It is similar as of the structure. The only difference is that union only occupy the memory of the largest member data. So we car use only one data of the union at a time. Can there be pointer to union? yes they can be :)

Courses to Complete During Software Engineering

Pointer

What is pointer in a word? A pointer is a variable. A pointer is a reference variable which store memory location. All the pointer occupy same memory bits. The pointer of the floating point data and the integer data. will occupy only 2 bits of memory. What is Void Pointer and null pointer? Void pointer is the pointer that can point to any kind of data type. This make use of type casting to to this job. Null pointer os the pointer which points to non or invalid address. Remember Structure pointer can only point to structure.

float data type is of 4 bit of memory, so when pointer points to the floating point it will point the base address of the variable. Points to the starting block of the memory for that variable.

Class

A class is data type. class is user defined variable that can be used to create objects. The difference between the structure and the class is that class have methods (Behaviour) which structure does not have. When ever the object are created the members are copied to the variables but not the methods. All the objects share the same methods. What is Abstract class? The class which have pure virtual function and cannot make any object.

Abstract means hiding the implementation details. We Drive the car but it is no concern to use how all the functions in the car works.
Java is a general-purpose, Object Oriented Programming Language high level programming language. It was developed by Sun Microsystem in 1991. Originally James Gosling, Mike Sheridian, Patrick Naughton start a project named "Green Project". They were developing special software for consumer electronic devices. They name this new programming language as "Oak". The World Wide Web appeared, then they develop a web browser called "HotJava" using the new programming language they developed, which demonstrate the Power the Programming language and it become popular among the internet. They Rename "Oak" into "Java" in 1995.

To run a java code in any machine we need JRE (Java Runtime Environment). JVM is a component of JRE. JVM(Java Virtual Machine). All programming language compilers translate source code into machine code for special computer. However Java first compile the java Source code into a bytecode for a the JVM. Then java interpreter generate the machine specific code. This is why java is Platform Independent. Any code written and compiled in Linux machine could be interpreted and run on Windows machine.

A java source file Hello.java is first compiled using compiler (Javac) which will generate a bytecode Hello.class then Java Interpret(Java) will gives the output. JDK(Java Development Kit)is used for java program development. JRE will be automatically installed when JDK is installed in the system. In Windows machine we need to set environmental variables to run Java or Javac command in Command Prompt. For that Right Click in My Computer and Click properties. Then Click in Environmental Variables. Add "path" as a name and <Location of java installation> in value field in System Variables. The location should be like "c:\program files\java\jdk\bin"

We set up the Environment verialbes now we are ready to go to Run our First Program

1
2
3
4
5
6
7
8
9
class Hello
{
        public static void main(String args[])
        {
                System.out.print("Hello ");
                System.out.println("Java ");
                System.out.println("Welcome to Java");
        }
}

Java contents Packages with any prederined functions and class to use while programming in java. Packages are those refered as Class Libararies in other programming language. While Defining Identifier. Always use UpperCase first character of class and every first Letter of next word without any space. for Functtion name use first lowercase and next word's first character as a UpperCase.
Identifier Examples:-
Class Name:- Hello, HelloJava, WelcomeToJavaProgramming
Method name:- display(), displayMessage(), displayNewMail()

In the above program we use String and System class from Package java.lang We should alway import the package name before using them in our program. But java.lang is a basic package which will be automaticlly inserted.

import java.lang.String will import only that class where as import java.lang.* will import all the classes in that Package. It is better to use .* while during studying purpose but for development we will impor individual package as required.

As java is purely object oriented programming language, we need to create at least one class to run the java program. The main function is automatically called when executing the program. ie the execution of the program starts from the main function. Main function is Public, can be accessed by outer function, Static because no object is created to call the main function. void as it do not return anything. The main function is called using the class name as Hello.main()

String args[] are known as Command line arguments. We could pass arguments to the main function from command line.
Check: Java, General-purpose Programming Language

Prerequisites:- Basic Knowledge of Object Oriented Programming.
Hello there Here we Will display all the data stored in database table in html.
For this example we use the Example code of

Php Program To Connect With Database, Create Table To Connect with database, create table and insert data to the database. And From this code below we can display the stored data.

Q.Write PHP code that retrieves all the districts from database in tabular format. Pokhara University [2012 -Spring] Course: Web Technology

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!doctype html>
<html>
<head>
 <title>All the datas from Table in Database</title>
</head>
<body>
 <?php
 include "connect.php";
 $sql = "SELECT id,name,email FROM info";
 $result = $conn->query($sql);
 echo "<table border='1'>";
  echo "<tr>";
   echo "<th> Id </th>";
   echo "<th> Name </th>";
   echo "<th> Email </th>";
  echo "</tr>";
 while($row = $result->fetch_assoc()) { 
  echo "<tr>";
   echo "<td>" . $row["id"]. "</td>";
   echo "<td>" . $row["name"]. "</td>";
   echo "<td>" . $row["email"]. "</td>";
  echo "</tr>";
 }
 echo "<table>";
 ?>
</body>
</html>

Here is our info Table in Database:
Here is the Output of the Code Above

Id Name Email
1 Sagar Devkota info@devkotasagar.com.np
2 Ram Hari ram@hari.com.np
3 Mr Bean mr@bean.com.np
4 Cristiano Ronaldo Cristiano@Ronaldo.com.np
5 Tom Cruise tom@cruise.com.np
6 Raffey Cassidy Raffey@Cassidy.com.np

This is all. You can find the code in Github https://github.com/InfoDevkota/phpformmysql/tree/master (Master Branch) Issuers and pull requested are accepted.
If something is wrong or Need more clarification  Please contact me: info[at]devkotasagar.com.np.
Change the font size and color of the text using java script We use onmouseover in this example code. You can use onClick and onmouseout too.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<html>
<head>
 <title>Display a table</title>
</head>
<body>
 <p id="Hello" onmouseover="change(this)">Hello How are you doing</p>
 <script>
 function change(obj){
  obj.style.margin = "90px";
  obj.style.fontSize = obj.style.fontSize == "200%" ? "300%" : "200%";
  obj.style.color= obj.style.color=="green" ? "red" : "green"; 
 }
 </script>
</body>
</html>


Here is a Java Script to display a table. To display a table always remember to set table row in first loop and table data in second loop. The loop will horizontal as per in the table. So make the inner loop in such way that it will display data in next column. Though here is only one loop.


JavaScript Display Possibilities
  • JavaScript can "display" data in different ways:
  • Writing into an HTML element, using innerHTML.
  • Writing into the HTML output using document.write().
  • Writing into an alert box, using window.alert().
  • Writing into the browser console, using console.log().

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<html>
<head>
 <title>Display a table</title>
</head>
<body>
 <script>
 var i = 0;
 var j = 0;
 document.write("<table border='1'>");
  document.write("<tr>");
   document.write("<th> S.No </th>");
   document.write("<th> Input </th>");
   document.write("<th> Output </th>");
  document.write("</tr>");
 for(i=1;i<6;i++)
 {
  document.write("<tr>");
   document.write("<td>" + i + "</td>");
   document.write("<td>" + (i+4) + "</td>");
   document.write("<td>" + (i+4)*(i+4) + "</td>");
  document.write("</tr>");
 }
 document.write("</table>");
 </script>
</body>

For Better Understanding of the loops for table  in Java Script There is another Multiplication table below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<html>
<head>
 <title>Display a table</title>
</head>
<body>
 <script>
 var i = 0;
 var j = 0;
 document.write("<table border='1'>");
        for(i=1;i<11;i++)
        {
          document.write("<tr>");
          for(j=1;j<11;j++)
          {
            document.write("<td>"+j+"*"+i+"="+(j*i)+"</td>");
          }
          document.write("</tr>");
        }
        document.write("</table>");
 </script>
</body>

As in the above loop we Use j*i Which makes the inner loop * outer loop as outer loop will changed as 10 inner loop so will display as 1*1=1 then in next row 2*1=2 ..... 10*1=10 Got it?
If something is wrong or Need more clarification  Please contact me: info[at]devkotasagar.com.np.
Hello There Here is a simple PHP Program to connect with MySQL database. Create a Table in the database and insert data into the database through the form.

Course: Web Technology
University: Pokhara University

Check The Internet and The Web – Introduction

Here is a connect.php file. We need Server, Database Name, Username and Password for that database.
new mysqli(server, username,password,database)
Will establish a database connection.

1
2
3
4
5
6
7
8
9
10
11
12
<?php
$server = "localhost";
$username ="test2";
$password ="test2";
$dbname ="test2";
$conn =new mysqli($server,$username,$password,$dbname);
if ($conn->connect_error)
{
  die("connection error " .$conn->connect_error);
}

 ?>

Here is createdb.php Which will create a table Named info with element name and email.
Here we save the SQL query in variable sql then run it in the Connection made above as
$conn -> query($sql)

1
2
3
4
5
6
7
8
<?php
include "connect.php";
$sql ="CREATE TABLE info(
  id INT(6) AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(60) NOT NULL,
  email VARCHAR(40) NOT NULL)";
$conn-> query($sql);
 ?>

Finally we are here in index.html, Here is a form with action test2.php. Whatever we send through this form will be send to test2.php (that is what action for)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <form class="" action="test2.php" method="post">
      Name: <input type="text" name="name" value="name"/><br>
      Email: <input type="email" name="email" value="email"/><br>
      <input type="submit" name="" value="send">

    </form>
  </body>
</html>

And here is test2.php which will get the values passed from the form and store them in the Database.
$_POST["name"] will get the value from the form with name name. The SQL query

INSERT INTO info(name, email) VALUES ('$name','$email')
Will insert the value of name and email to the table info and element name and email.
1
2
3
4
5
6
7
8
<?php
include "connect.php";
$name= $_POST["name"];
echo $_POST["name"];
$email = $_POST["email"];
$sql = "INSERT INTO info(name, email) VALUES ('$name','$email')";
$conn-> query($sql);
 ?>

This is all. You can find the code in Github https://github.com/InfoDevkota/phpformmysql/tree/master (Master Branch) Issuers and pull requested are accepted.
If something is wrong or Need more clarification  Please contact me: info[at]devkotasagar.com.np.
Aello This is a Simple JS Validation example Only to understand how it works.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!doctype html>
<html>
 <head>
  <title>This is a Test JavaScript Validation page</title>
  <script>
   function check() {
    var x = document.forms["test"]["firstname"].value;
    var y = document.forms["test"]["email"].value;
    if (x == "") {
     document.getElementById('error').innerHTML = "Name must be Filled!";
     return false;
    }
    if (y == "") {
     document.getElementById('error').innerHTML = "Email must be Filled!";
     return false;
    }
    var at = y.indexOf("@");
    var dot = y.lastIndexOf(".");
    if (at < 1 || dot < 4 || at > dot ) {
     document.getElementById('error').innerHTML = "Enter a valid email";
     return false;
    }
   }
  </script>
 </head>
 <body>
  <form name="test" method="post" onsubmit = 'return check()'>
   <input type="text" name="firstname" placeholder="Enter a name"/>
   <input type="text" name="email" placeholder="Enter your mail"/>
   <input type="submit" value="Send"/>
  </form>
  <p id="error"></p>
 </body>
</html>

Hey that's not Aello! its Hello..
<Pokhara University CPP>
Functions and all types.
Constructor and Destructor
Friend Function
Operation Overloading
Type Conversion (All 3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include<iostream>
using namespace std;
const double pi = 3.14; //If we try to alter the vaule of Pi compiler will generate a error.
class Test2;
class Test{
  int num1; //This will be in private section
  int num2; //This will be in private section
  public:
    //**************************Functions***************************//
    void add3(int a, int b, int c=5){ //Default arguments If only two args are pass last will take 5 if  all 3 are passed it will add those 3 numbers
      int add = a+b+c;
      cout<<"Sum = "<<add<<endl;
    }
    void add3(double a, double b, double c){ //Funtion Overloaded This function and above function name are same but if we pass int as arguments the above will be executed if float are passed this one will be executed
      double add = a+b+c;
      cout<<"Sum = "<<add<<endl;
    }
    void ifunction(){
      cout<<"I am a inline function"<<endl;
    } // FUnction definition inside class will be a inline function
    void anotherIFunc();// this is not a inline function as it is not defined here
    //**************************Constructor Destructor***************************//
    Test(){ //I am a default constructor
      num1=0;
      num2=0;
    }
    Test(int a, int b){ //I am a parameterised constructor
      num1=a;
      num2=b;
    }
    Test(Test &a){ //I am a copy constructor as i coppy the value of passed object to new object
      num1=a.num1;
      num2=a.num2;
    }
    //Here we use A function name Test to preform different taks, which is overload hence a constructor can be Overloaded
    ~Test(){ // Will be called automaticly Cannot be Overloaded as they takes no arguments
      cout<<"I am a Destructor"<<endl;
    }
    //**************************Friend Function***************************//
    friend void iaccess(Test a){//This is a friend function as there is keyword friend
      cout<<a.num2<<endl; // this can access the mamber data at private with a object.
      //no object is required to call a friend function.
    }
    friend void friendoftwo(Test a, Test2 b);
    //**************************Operator Overloading***************************//
    void operator -(){ //TO change the sign so a unary operator As this is unary operator we dont need to pass any args, as we will get a oject when it call
      num1 = num1*(-1);
      num2 = num2*(-1);
    }
    Test operator -(Test a){// TO subtract
      Test tmp;
      tmp.num1 = num1 - a.num1;
      tmp.num2 = num2 - a.num2;
      return tmp;
    }
    void display(){
      cout<<num1<<" and "<<num2<<endl;
    }
    //**************************Type Conversion***************************//
    Test(int a){ //Basic Type to Object Type Conversion
      num1=a;
      num2=a;
    }
    operator int (){ // Object to Basic Type conversion
      return num1+num2;
    }
    /* ******* DO YOU UNDERSTAND ******/ //YOU can OBtain the Object to Object Conversion by Defining constructor in Destination class or Operator conversion function in Source Class.
};
//*****************************************************//
class Test2{
  int age; //This will be in private section
  public:
    Test2(){
      age = 0;
    }
    friend void friendoftwo(Test a, Test2 b);
};
//*****************************************************//

inline void Test :: anotherIFunc(){ //Keyword "inline" makes it a inline function.
  cout<<"I am also a inline function"<<endl;
}

void friendoftwo(Test a, Test2 b){ //We dont need the friend keyword when defining the function.
  int tmp;
  cout<<a.num1<<" and "<<b.age<<endl;
  tmp = a.num1;
  a.num1= b.age;
  b.age = tmp; //Here we swap the private data of two classes using a friend function.
  cout<<a.num1<<" and "<<b.age<<endl;
}
int main()
{
  //Constructor and Function
  Test anum(2,10);
  anum.ifunction();
  anum.anotherIFunc();
  {
    //Destructor
    Test bnum;
    //Distructor will be automaticlly called when the program goes out of this "}"
  }
  //Friend Function
  iaccess(anum);
  Test2 bnum;//bnum.age is 0 because of the default constructor
  friendoftwo(anum, bnum);
  //Operator Overloading
  Test cnum(1,2);
  -cnum;
  cnum.display();
  Test add, dnum(7,15);
  add = dnum - anum;// Here the - FUnction is called by dnum and anum is passed as argument, as num1 is of dnum and a.num1 is of anum UNDERSTND THIS :) BE suer while using Greater then Operator.
  add.display();
  // Type conversion
  Test eanum;
  eanum = 9; //Both num1 and num2 gets the value of 9.
  eanum.display();
  int f = eanum; //f will get the value of num1+ num2 of eanum;
  cout<<f<<endl;

  return 0;
}

Is there anything Please do Comment, We will Update our Post Accordingly.
Q.Design a Soccer Player class that includes three integer fields: a player's Jersey number, number of goals, numbers of assists and necessary constructor to initialize the data members. Overload the ">" Operator (Greater than). One Player is considered greater if the sum of goals plus assists is greater than that of others. Create an array of 11 Soccer players, then use the overloaded ">" operator to ranks the players based on greatest goals plus assists.

Question for you:-
What is assists actually? Please answer in comment.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
using namespace std;

class Soccer{
  int jNumber, goals, assists;
  public:
  Soccer(){
    jNumber = 0;
    goals = 0;
    assists = 0;
  };
  Soccer(int, int, int);
  bool operator > (Soccer &);
  void display();
};
Soccer :: Soccer(int j, int g, int a){
  jNumber = j;
  goals = g;
  assists = a;
}
bool Soccer :: operator > (Soccer &s){
  if(goals + assists > s.goals + s.assists){
    return true;
  }
  else{
    return false;
  }
}
void Soccer :: display(){
  cout << "Jersey Number: " << jNumber << endl;
  cout << " Goals: " << goals << endl;
  cout << " Assists: " << assists << endl;
}
int main(){
  int i,j, jn, goal, assist;
  Soccer tmp,S1[11];
  for(i = 0; i <= 2; i++){
    cout << "Enter Data For Player "<< i+1 << ":-" << endl;
    cout << "Jersey number:- ";
    cin >> jn;
    cout << "Goals:- ";
    cin >> goal;
    cout << "Assists:- ";
    cin >> assist;
    Soccer tmp(jn, goal, assist);
    S1[i] = tmp;
  }
  for( j = 0; j<=2; j++){
    for( i = j; i<=2; i++){
      if(S1[i] > S1[j])
      {
        tmp = S1[i];
        S1[i] = S1[j];
        S1[j] = tmp;
      }
    }
  }
  cout << "Best User Ranking:-"<<endl;
  for( i = 0; i<=2; i++){
    cout << i + 1 << ": " ;
    S1[i].display();
  }
  return 0;
}


Well First I overload the > operator to return a Boolean value (true if the first value is greater than second, else false) then I use a sorting algorithm to arrange the players.

If you are asked to select the Best player only. First take one player as reference and follow the sorting algorithm to assign the greater value to it. And display that player.
Thanks Pradeep :)

Here is the code by Nischal Lal Shrestha.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
// #include <iostream.h>

using namespace std;

class Soccer_player{
   private:
   int jersey_number, number_of_goals, number_of_assists;
   string player_name;
   public:
   Soccer_player(){
      cout << "Enter Player Name: " << endl;
      cin >> player_name;
      cout << "Enter Jersey Number: " << endl;
      cin >> jersey_number;
      cout << "Enter Total Number of Goals: " << endl;
      cin >> number_of_goals;
      cout << "Enter Total Number of Assists: " << endl;
      cin >> number_of_assists;
      cout << "***** Player Info Updated *****" << endl;
   }

/* This is a copy constructor, 
We will used this to make another object called Best_Player
and first_player will be copied as best player for comparing it
with other(May we don't need this constructor )
*/

   Soccer_player(Soccer_player &Player){
      player_name = Player.player_name;
      jersey_number = Player.jersey_number;
      number_of_goals = Player.number_of_goals;
      number_of_assists = Player.number_of_assists;
    }

   void display(){
      cout << "Name: " << player_name << endl;
      cout << "Jersey Number: " << jersey_number << endl;
      cout << "Total Goals: " << number_of_goals << endl;
      cout << "Total Assists: " << number_of_assists << endl;
   }

   Soccer_player operator > (Soccer_player &P){
      if (number_of_assists + number_of_goals > P.number_of_assists + P.number_of_goals)
         return *this; // Return object which is already passed as default.
      else
         return P;
   }
};

int main(){
   Soccer_player Player[3];
   Soccer_player Best_Player = Player[0]; // First Player is made best player for comparision
   for(int i = 1; i < 3; ++i)
      Best_Player = Player[i] > Best_Player;
   cout << "\n\n\nOf all the info you updated\nThe Details of Best Player: \n\n" << endl;

   Best_Player.display();
   // getch();
   return 0;
}