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

Monday, November 6, 2017

C++ programming language part- 78 More about Linked List


More about Linked List

A Linked list with a function which is able to display a menu with the options add end delete record.

Program 50_4
//linkedList node.demo
            class node          // node is just a class name
            { public:
              char name[10];
              int age;
              node *next;

            void accept()
            { cout<>name;
              cout<>age;     }

            void display()
            { cout<
            };




            class list
            { node *start;

            public:
            list()
            { start=NULL; } // Constructor, so start will carry NULL
            void add_node()
            {node *fresh;
              fresh=new node;
              fresh->accept();
              fresh->next=start;
              start=fresh; }

            void delete_node()
            { node *temp;
               temp=start;
               start=start->next;
               delete temp;     }
            void traversal()
            {  node *temp;
                for(temp=start;temp!=NULL;temp=temp->next)     
                temp->display();    }  };

            main()
            { list L;
               char choice;
               do
            {
             L.add_node();
             cout<
             cin>>choice;
             }while (choice=='y' ||choice=='Y') ;
            L.traversal();
            int i=0,j=0;
            cout<
            cin>>i;
            cout<
            for(j=0;j
            L.delete_node();
            L.traversal();
            }


 


Ex: 4_1 arithmetic assign operator.

Programming Logic and Technique:
{ int p=10;
display " Type a number ";
accept p;
p+=5;
display "Aftter using arithmetic operator(+=)the value will be "<

 
Program Ex_4_1
//Ex_4
#include 
void main()
{
int p=10;
cout<<" Type a number "<
cin>>p;
p+=5;
cout<<"After using arithmetic operator(+=)the value will be "<
}


Ex: 9_1 Identify a number to define whether that is even or odd or zero.



C++ programming language part- 79 Programming Logic and Technique


Programming Logic and Technique:
int a;
display " Type a number";
accept a;
if((a!=0)&&(a%2==0)) display " The number is Even";
else {   if(a==0) {display " The number is Zero "; }
if(a%2!=0) { " The number is Odd ";  }}
Or
if((a!=0)&&(a%2==0)) display " The number is Even";
else {   if(a==0) { display " The number is Zero "; }
else display " The number is Odd "; }
            Or
if((a!=0)&&(a%2==0)) display " The number is Even";
else if(a==0) display" The number is Zero ";
else display " The number is Odd ";
Or
if((a!=0)&&(a%2==0)) display " The number is Even";
else if(a==0) display " The number is Zero ";
else if(a%2!=0) display " The number is Odd ";

Program Ex_9_11
#include
void main()
{
int a;
cout<<" Type a number, please "<
cin>>a;
if((a!=0)&&(a%2==0))
cout<<" The number is Even"<
else
{
            if(a==0)
            {
            cout<<" The number is Zero "<
            }
            if(a%2!=0)
            {
            cout<<" The number is Odd "<
            }
}
}


Program EX_9_12
#include
void main()
{
int a;
cout<<" Type a number, please "<
cin>>a;
if((a!=0)&&(a%2==0))
cout<<" The number is Even"<
else
{
            if(a==0)
            {
            cout<<" The number is Zero "<
            }
            else
            cout<<" The number is Odd "<
}
}


Program Ex_9_13
#include
void main()
{
int a;
cout<<" Type a number, please "<
cin>>a;
if((a!=0)&&(a%2==0))
cout<<" The number is Even"<
else if(a==0)
            cout<<" The number is Zero "<
            else
            cout<<" The number is Odd "<
}


Program Ex_9_14
#include
void main()
{
int a;
cout<<" Type a number, please "<
cin>>a;
if((a!=0)&&(a%2==0))
cout<<" The number is Even"<
else if(a==0)
            cout<<" The number is Zero "<
else if(a%2!=0)
            cout<<" The number is Odd "<
}


Program Ex_9_2
#include
void main()
{
        char type;
            int size;
            cout<<" Type the color of your Television(B/C) ? ";
            cin>>type;
           
        if (type=='B')
            cout<<"You will get 5% discount "<
            else
             cout<<"Color?, type size in inches ";
             cin>>size;
            {
            if(size==14)
            cout<<"You will get 10% discount "<
            else
            cout<<"You will get 15% discount "<
            }
}


Program Ex_9_3
#include
void main()
{
            int p;
            cout<<" Type your year,please "<
            cin>>p;
            if(((p%4==0)&&(p%100!=0))||(p%400==0))
            cout<<"The Year is Leap year"<
            else
            cout<<"The Year is not leap Year";
}



Program Ex_9_4_1
#include
void main()
{
            int p1,p2,p3;
            cout<<" Type first  number, please "<
            cin>>p1;
            cout<<" Type second number, please "<
            cin>>p2;
            cout<<" Type first  number, please "<
            cin>>p3;
            if(p1>p2)
               {
               if(p1>p3)
               cout<<"The largest number is "<
               else
               cout<<"The largest number is "<
               }
            else
        {
               if(p2>p3)
               cout<<"The largest number is "<
               else
               cout<<"The largest number is "<
            }
        }
Alternate

Program 9_4_2
#include
void main()
{
            int p1,p2,p3;
            int high;
            cout<<" Type first  number, please "<
            cin>>p1;
            cout<<" Type second number, please "<
            cin>>p2;
            cout<<" Type first  number, please "<
            cin>>p3;
            if(p1>p2)
            high=p1;
            else
            high=p2;
            if(p3>high)
        cout<<"The largest number is "<
            else
            cout<<"The largest number is "<
}

Program Ex_9_5
#include
void main()
{
            int p1,p2,reminder;
            cout<<" Type first  number, please "<
            cin>>p1;
            cout<<" Type second number, please "<
            cin>>p2;

            if(((p2!=0)&&(p2>0))&&(p2>p1))
            {
            reminder=p1%p2;
            }
            else
            cout<<"Sorry man! ";
}




           

C++ programming language part- 81 Programming Logic and Technique:


Programming Logic and Technique:
{ char string1[10], string2[10];           //array of size 10 defined
               int i,j;
                        display "type a string "
                        accept string1;
              for(i=0;string1[i]!='\0';i++);
                i--;
                        display " The reverse string is ";
              for(j=0;i>=0;j++,i--)
            {
                 string2[j]=string1[i];
            }
                 string2[j]='\0';
                 display<


Program Ex_19_1
            //reverse string (arraydemo.c)
            #include
            #include
            void main()
            {
            clrscr();   // To clean the screen
            char a1[10],a2[10];//array of size 10 defined
            int i,j;
                        cout<<"type a string "<<"\n";
            cin>>a1;
            for(i=0;a1[i]!='\0';i++);
                i--;
                        cout<<" The reverse string is "<
            for(j=0;i>=0;j++,i--)
            {
                 a2[j]=a1[i];//
            }
                 a2[j]='\0';
                 cout<

        }