Wednesday, 30 August 2017

11D-Prg7 Write a program to read the value of a variable of a quadratic equation and find the discriminant and give the root of the quadratic equation.

// prg7

#include<iostream.h>
#include<math.h>

main()
{
 
    float a,b,c,d,r1,r2;

    cout<<"Enter a b and c \n";
    cin>>a>>b>>c;

    d=b*b-4*a*c;
    if(d==0)
    {
Cout<<"Roots are equal\n";
r1=-b/(2*a);
        r2=r1;
cout<<"R1=R2="<<r1;
    }
    else
    if(d>0)
    {
cout<<"Roots are different\n";
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
        cout<<"Root1="<<r1;
        cout<<"Root2="<<r2;
    }

    else
    cout<<"Complex number \n";

}
    

Saturday, 19 August 2017

11-C Prg-6. Write a program to read a number and print the number of digits and the sum of the digits.

11-C Prg-6. Write a program to read a number and print the number
of digits and the sum of the digits.

Algoithim:
Input
1. n (567)

Output:
1. print the numbers (7, 6, 5)
2. sum of the digits( sum= 5+6+7=18)

Method:
1.start       //int n,sum,r;
2. Read n
3. write n
4. sum=0;
5. //logic

   do                   do
   begin  {
    r=n % 10;     r=n%10;
    write r;                 cout<<"digits="<<r;
    sum=sum+r;               sum=sum+r;
    n=n/10;                  n=n/10;
   end while(n != 0)       } while(n !=0);
6. write sum
7.stop

12th-C & D Computer Science Subject August-2017 Monthly Test Blue-print: Max Marks:35



I  Data File Handling (05 marks)

1) Text File logic writing through function. 2marks
2) Binary file logic writing through function 3marks

II Data Structure (30 Marks)

1) One Dimension function writing(logic) Application level  -2 marks
2) Two Dimension function writing(logic) Application level  -3 marks

3) One Dimension function writing(logic)(Binary search,
    Selection sort, Bubble sort and  Insertion sort) -
     Any three 2+2+2 =6 marks

4) Two Dimensional-Address Calculation
   a) Row Major (with Range)  - 3marks
   b) Column major(with Range) - 3marks
   c) Row major (without range) - 3 marks
   d) Column major(without range-finding base address and finding actual address) - 3 marks

5) Postfix expression evaluation through stack(True, False.....)(bucket form) -2marks

6)Infix expression to postfix conversion through stack(Tabular form)- 3marks

7) Postfix expression evaluation through stack(values ....)(bucket form) -2marks

                 *** End ***

Wednesday, 16 August 2017

12-C-Prog-17.Write a Program to implement Insertion Sort using a 1-D array.


17.Write a Program to implement Insertion Sort using a 1-D array.

 #include<iostream.h>
 void InsSort(int[ ], int);

int main()
 {
   int AR[50],item, n, index;
   cout<<"How many elements do u want to create array with?(max..50)..";
   cin>>n;
   cout<<"\n Enter Array elements ..\n";
   for(int i=0;i<n;i++)
    cin>>a[i];
 
   InsSort(AR, n);
   cout<<"\n \n The sorted array is as shown below \n";
   for(i=0;i<n;i++)
    cout<<AR[i]<<" ";
   cout<<endl;
   return 0;
 }

 void InsSort(int AR[ ], int size)
 {
   int t,j;
   AR[0]=INT_MIN;
   for(int i=1;i<=size;i++)
   {
     t=AR[i];
     j=i-1;
    while(t<AR[j])
    {
      AR[j+1]=t;
      j--;
     }
    AR[j+1]=t;
    cout<<"Array after pass-"<<i<<"-is";
      for(int k =1;k<=size;k++)
       cout<<AR[k]<<" ";
      cout<<endl;
   }
 }
       
 
   

12-C-Prg-16.Write a Program to implement Bubble sort using a 1-D array.


16.Write a Program to implement Bubble sort using a 1-D array.

 #include<iostream.h>
 void Bubblesort(int[ ], int);

int main()
 {
   int AR[50],item, n, index;
   cout<<"How many elements do u want to create array with?(max..50)..";
   cin>>n;
   cout<<"\n Enter Array elements ..\n";
   for(int i=0;i<n;i++)
    cin>>a[i];
 
   Bubllesort(AR, n);
   cout<<"\n \n The sorted array is as shown below \n";
   for(i=0;i<n;i++)
    cout<<AR[i]<<" ";
   cout<<endl;

 }
 void Bubblesort(int AR[], int size)
 {
   int t,ct=0;
   for(int i=0; i<size; i++)
   {
     for(int j=0; j<(size-1); j++)
     {
       if(AR[j]>AR[j+1])
        {
          t=AR[j];
          AR[j]=AR[j+1];
          AR[j+1]=t;
         }
      }
      cout<<"Array after iteration-"<<++ct<<"-is:";
      for(int k=0;k<size;k++)
       cout<<AR[k]<<" ";
      cout<<endl;
    }
 }

12-C Prog-13 Linear Search using 1-D Array


//PROG 13 LINEAR SEARCH
#include<iostream.h>
#include<conio.h>

int Lsearch(int AR[],int size,int item)
 { for(int i=0;i<size;i++)
  { if(AR[i]==item)
    return i;
  }
 return -1;
 }

void main()
{
int AR[50],ITEM,N,index;
cout<<"\nEnter Desired Array Size: ";
cin>>N;
cout<<"\nEnter Array Elements: ";
for(int i=0;i<N;i++)
{
cin>>AR[i];
}
cout<<"\nEnter Element to be searched for : ";
cin>>ITEM;
index=Lsearch(AR,N,ITEM);
if(index==-1)
cout<<"\nSOrry!! Given Element could not be found.";
else
cout<<"\nElement found at index : "<<index<<", Position :"<<index+1;
getch();
}

12C Program-15 Write a program to implement Selection Sort using 1-D Array


//Progr-15 selection sort
#include<iostream.h>
clrscr();
void selsort(int[],int);
int main()
{int ar[60],item,n,index;
cout<<"how many elements you want to create with array?";
cin>>n;
cout<<"\nenter array elements...";
for(int i=0;i<n;i++)
cin>>ar[i];
selsort(ar,n);
cout<<"\n\nthe stored array is nas shown below...\n";
for(i=0;i<n;i++)
cout<<ar[i]<<"  ";
cout<<endl;
return 0;
}
void selsort(int ar[],int size)
{
int small,pos,tmp;
for(int i=0;i<size;i++)
{small=ar[i];
pos=i;
for(int j=i+1;j<size;j++)
{ if(ar[j]<small)
{small=ar[j];
pos=j;}
}
tmp=ar[i];
ar[i]=ar[pos];
ar[pos]=tmp;
cout<<"\narray after pass-"<<i+1<<"-is:";
for(j=0;j<size;j++)cout<<ar[j]<<" ";
}}



12-C Prog-21-Linked Queue Insertion and Deletion Program


#include<iostream.h>

#include<process.h>
struct Node
{int inf;
Node*next;
}
*front, *newptr,*save,*ptr,*rear;
Node *Create_New_Node(int);
void Insert(Node*);
void Display(Node*);
void DelNode_Q();
int main()
{ front=rear=NULL;
int inf;
char ch='y';
while(ch=='y'||ch=='y')
{
cout<<"enter informtion for the new node...";
cin>>inf;
newptr=Create_New_Node(inf);
if(newptr==NULL)
{ cout<<"\n Cannot create new noe!! Aborting!!\n ";
  exit(1);
}
Insert(newptr);
cout<<"\n press Y to enter more nodes,Nto exit...\n";
cin>>ch;
}//while end
do
{ cout<<"\n The linked -queue now is ( front ...to..rear):\n ";
  Display(front);
  cout<<"want to delete first noe?(y/n)...";
  cin>>ch;
  if(ch=='y'||ch=='Y')
  DelNode_Q();
} while (ch=='y'||ch=='Y');
  return 0;
}//main en
  Node *Create_New_Node(int n)
  { ptr=new Node;
  ptr->inf=n;
  ptr->next=NULL;
  return ptr;
  }
  void Insert(Node *np)
  {
     if(front==NULL)
       {front=rear=np;}
     else
       {rear->next=np;
       rear=np;}
  }
  void DelNode_Q()
  {
   if ( front==NULL)
    cout<<"UNDERFLOW!!\n";
   else
   {ptr=front;
    front=front->next;
    delete ptr;
   }
  }
  void Display(Node*np)
  {
    while(np!=NULL)
     { cout<<np->inf<<" ";
       np=np->next;
     }
    cout<<"!!\n";
  }

12-C Prog-20 Stack Linked list Pushing and Poping


#include<iostream.h>

#include<conio.h>

#include<stdlib.h>

#include<process.h>

struct Node

{

   int info;

   Node *next;

} *top,*newptr,*save,*ptr;

Node *Create_New_Node(int );

void push(Node *);

void display(Node *);

void pop();

int main()

{

   clrscr();

   top=NULL; //in the begining linked stack is empy, thus pointers are NULL

   int inf;  char ch='y';

   while(ch=='y'||ch=='Y')

   {

     cout<<"\n Enter information for the new node....";

     cin>>inf;

     newptr=Create_New_Node(inf);

     if(newptr==NULL)

     {

    cout<<"\n cannot create new node \n";

    exit(1);

     }

     push(newptr);

     cout<<"\n Press y to enter more nodes, N to exit()....";

     cin>>ch;

   }// while end.

   do

   {

     cout<<"\n The stack now is : \n";

     display(top);

     cout<<"want to pop an element ? (y/n)";

     cin>>ch;

     if(ch=='y'||ch=='Y')

     pop();

    }

    while(ch=='y'||ch=='Y');

    return 0;

  }//main end


  Node *Create_New_Node(int n)

  {

    ptr= new Node;

    ptr->info=n;

    ptr->next=NULL;

    return ptr;

  }

  void push(Node *np)

  {

    if(top == NULL) top=np;

    else

    {  save =top; top=np;

       np->next=save;

    }

  }

  void pop()

  {

    if(top==NULL) cout<<"Underflow";

    else

    {

      ptr=top; top=top->next;

      delete ptr;

     }

  }

  void display(Node *np)

  {

    while(np != NULL)

    {

      cout<<np->info<<"->";

      np=np->next;

    }

    cout<<" !!! \n";

  }

//12C Program-19 Array Queue Insertion and Deletion


//12D Program-19 Array Queue Insertion and Deletion

#include<iostream.h>

// #include<stdlib.h>

#include<process.h>

#include<conio.h>


int Remove(int []);

int Insert(int [], int);

void Display(int [], int, int);


const int size = 50;

int Queue[size],front=-1,rear=-1;


int main()

{

   int Item,res; char ch='Y';

   clrscr();


   while( ch=='y'||ch=='Y')

   {

     cout<<"\n  Enter Item for Insertion\n";

     cin>>Item;

     res=Insert(Queue,Item);

     if(res==-1)

       {

     cout<<"Overflow \n";exit(1);

    }

      cout<<"\n Now the Queue(front....to....rear)is: \n";

      Display(Queue,front,rear);

      cout<<"\n Want to insert more elements?(y|n)...";

      cin>>ch;

   }


     cout<<"Now deletion of elements begins,,,\n";

     ch='Y';

     while(ch=='y'||ch=='Y')

     { res=Remove(Queue);

       if( res==-1)

       {cout<<"Underflow!!!Aborting!!\n";   exit(1);

       getch();

       }

       else

       {  cout<<"\n Element deletion is: "<<res<<endl;

      cout<<"now the Queue(front...to...back) begins:";

      Display(Queue,front,rear);

       }

       cout<<"\nwant to delete more elements ?(y/n)....\n";cin>>ch;

     }

     return 0;

  }//main end


  int Insert(int Queue[], int ele)

  {

     if(rear == size-1) return -1;

     else

     if(rear==-1)

     {

      front=rear=0;

      Queue[rear]=ele;

     }

     else

     {

    rear++;

    Queue[rear]=ele;

     }

     return 0;

   }

   int Remove(int Queue[])

   {

     int ret;

     if(front==-1) return -1;

     else

     {

       ret=Queue[front];

       if(front == rear) front=rear=-1;

       else

       front++;

     }

     return ret;

   }

  void Display(int SQueue[],int front,int rear)

  {

     if(front==-1) return;

     for(int i=front;i<rear;i++)

    cout<<Queue[i]<<"<-";

     cout<<Queue[rear]<<endl;

  }


//12-C Program-18 Stack implementation using Array:Insertion and Deletion


//12-D Program-18 Stack implementation using Array:Insertion and Deletion

#include<iostream.h>

#include<process.h>

int pop(int [], int &);

int Push(int [], int&, int);

void display(int [], int);

const int size=1;

int main()

{

  int Stack[size],Item,top=-1,res;

  char ch='y';

  while(ch=='y'|| ch=='Y')

  {

    cout<<"\n Enter ITEm for insertion :";

    cin>>Item;

    res=Push(Stack,top,Item);

    if(res==-1)

    {

      cout<<"Overflow !!! \n";

      exit(1);

    }

    cout<<"The stack now is:\n";

    display(Stack,top);

    cout<<"\n want to insert more elements ?(y/n)";

    cin>>ch;

  }

  cout<<"Now deletion of elements begins ...\n";

  ch='y';

  while(ch=='y' || ch=='Y')

  {

    res=pop(Stack,top);

    if(res==-1)

    {

      cout<<"Underflow \n";

      exit(1);

    }

    else

    {

      cout<<"\n Element deleted is:"<<endl;

      cout<<"\n The stack now is :\n";

      display(Stack,top);

    }

    cout<<"\n want to delete more elements ?\n";

   cin>>ch;

  }

   return 0;

 }

 int Push(int Stack[], int & top, int ele)

 {

    if(top == size-1) return -1;

    else

    {

       top++;

       Stack[top]=ele;

    }

    return 0;

 }

 int pop(int stack[], int &top)

 {

    int ret;

    if(top == -1) return -1;

    else

    {

      ret = stack[top];

      top--;

    }

    return ret;

 }

 void display(int stack[], int top)

 {

    if(top==-1) return;

    cout<<stack[top]<<"<-"<<endl;

    for(int i=top-1;i>=0;i--)

      cout<<stack[i]<<endl;

 }


Monday, 7 August 2017

//12-C Prog-11. write a programe to illustrate use of this pointer

//12-C Prog-11. write a programe to illustrate use of this pointer
#include<iostream.h>
#include<conio.h>
#include<stdio.h>

class sample
{
  int code;
  char str[20];
  public:
   void Insert();
   void Display();
};
void sample :: Insert()
{
  cout<<"\n Enter the code";
  cin>>this->code;
  cout<<"\n Enter string ";
  gets(this->str);
}
void sample::Display()
{
  cout<<"\n code="<<this->code;
  cout<<"\n string="<<this->str;
}

void main()
{
   clrscr();
   sample o;
   o.Insert();
   o.Display();
   getch();
}

12-C Prg-4 Class Hotel program

/* Define a class Hotel with following description private members RNo. of int, name of string, tariff(float), nod (number of days) of int. Cal() function to calculate and return amount as number of days.
if the value of  nod*tariff > 1000 then amount= 1.05* nod *tariff.
  */

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class hotel
{
int rno ;
float amount;
char name[50];
float tarrif;
int nod;
void calc() ;
public:
void checkin();
void checkout();
};
void hotel::calc ()
{ if(nod*tarrif>=1000)
{amount=1.05*nod*tarrif;
cout << "\nThe amount is " ;
cout << amount ;
getch() ;
}
else
{
amount=nod*tarrif;
cout<<"\n amount is:";
cout << amount ;
getch() ;
}

}
void hotel::checkin()
{

cout<<"\n enter room no.";
cin>>rno;
cout<<"\n enter name :";
gets(name);
cout<<"enter tariff :";
cin>>tarrif;
cout<<"\n entet the no. of days:";
cin>>nod;

}
void hotel:: checkout()
{

cout<<"\nthe room no is"<<rno;
cout<<"\n the name is:";
puts(name);
cout<<"\n tariff is:"<<tarrif;
cout<<"\n no. of days is:"<<nod;
calc();
}
void main ()
{
clrscr ();
hotel x ;
x.checkin();
x.checkout();
}