know yourselves. information, computer, 7 wonders, various.

Monday, November 6, 2017

C++ programming language part- 73 Look here is a program with a class and overload the ==,>,< and += operators


Look here is a program with a class and overload the ==,>,< and += operators.

Program 49_3
            class fps_distance
            {private:
              char str[20];
              public:
                        fps_distance(char st[20]);
                        fps_distance();
                        int operator==(fps_distance &);
                        int operator>(fps_distance &);
                        int operator<(fps_distance &);
                        void operator+=(fps_distance &);
                        fps_distance operator+(fps_distance &);
                        void display(void);
            };

            fps_distance::fps_distance(char st[20])
            {          strcpy(str,st);    }

            fps_distance::fps_distance()
            {          strcpy(str,"nova");  }

            int fps_distance::operator == (fps_distance & Fps2)
            {          return ((strcmp(str,Fps2.str)==0)?1:0);  }

            int fps_distance::operator >(fps_distance & Fps2)
            {          return ((strcmp(str,Fps2.str)>0)?1:0);    }


            int fps_distance::operator <(fps_distance &Fps2)
            {          return ((strcmp(str,Fps2.str)<0 nbsp="" o:p="">

            void fps_distance::operator+=(fps_distance &Fps2)
            {          (strcat (str,Fps2.str));                }
            fps_distance fps_distance::operator+(fps_distance &Fps2)
            {          char st[20];
                        strcpy(st,str);
                        strcat(st,Fps2.str);
                        return(fps_distance(st));
            }

            void fps_distance::display(void)
            {          cout<<"\nstring is  "<

            void main()
        {              fps_distance W1("NOVA"),W2("nova"),W3("Dhaka");
            clrscr();
            if(W1==W2)
                        cout<< "equal ";
            else
                        if(W1>W2)
                        cout<<" first is grater";
                        if(W1
                        cout<<"first is less";
                        W1+=W2;
            W1.display();

            W1=W2+W3;

            W1.display();  }    




C++ programming language part- 74 Linked List


Linked List

A linked list is a chain of structures in which each structure contains of data as well as pointer, which stores the address of the next logical structure in the list. We will discuss about some programs allow the user to create a linked list in reverse. An element in a linked list is called a node. Each node has two parts: the first part contains the information and second part is a pointer, which contains the address of next node. A linked list is identified by a collection of nodes, and, a pointer called start, which has the address of the first node of the list. The operation that can be performed on linked lists are: Insertion of Node, Deletion of Node, Traversal of list.
The class definition and operation for list is as follows:
class list
{ private:
node *start;      // data type is node
  public:
list()                 //  The constructor
void add_node();
void delete_node();
void traversal();  };

Inserting a Node

This involves adding a new node to the linked list. The following sequence performs the insertion of a node in the beginning of the list:
Step 1: Allocate memory for a new node
Step 2: Accept data for the Information part of the node
Step 3: Modify the content of the Start pointer so that it points to the new node
Step 4: modify the content of the next node.
The add_node() function is defined as follows:

Void list::add_node()
{
node *Fresh;
Fresh = new node;
Fresh->add_word();      // member function of class node
Fresh->next=start;
start=Fresh


Traversing a list
In order to display the contents of a list, you have to traverse the list. The following sequence performs the traversal of a list to display the Information part of each node.
Step 1: Set a temporary pointer (Temp) to start
Step 2: Repeat step 2 and 4 until Temp is not equal to NULL
Step 3: Print the Information part of the node pointed to by Temp
Step 4: Advance the pointer Temp so that points to the next node
The traversal() function is defined as follows:
void list::traversal()
{
node *Temp;
for(Temp=Start;Temp!=NULL;Temp=Temp->Next)
       {
Temp->display_node() // member function of node class
       }


}










C++ programming language part- 75 Representing a Node


Representing a Node

Program 50_1
            //linkedList node.demo
            class node
            {
            char name[10];
            public:
            void accept()
            {
            cout<
            cin>>name;
            }
            void display()


            {
            cout<
            }
            };
            main()
            {
            node L;
            L.accept();
                        //L.accept();
                        //L.display();
            L.display();
            }