MENU











Saturday, 30 November 2013

OOPS ASSIGNMENT-2

OOPS ASSIGNMENT-2

1)What is a problem ? Thinking about a problem

Problem:
 Writing a program starts with a problem.



Understanding that problem is key to a good program.
After all, a program that solves the wrong problem is
likely to be of little use to you,however elegant it may be.
 What we want is a program that simply and cleanly
solves the problem we decided to solve.

A program that
 Illustrates design and programming techniques
Gives us a chance to explore the kinds of decisions that a 
programmer must make and the considerations that go into such decisions
Doesn't require too many new programming language constructs
Is complicated enough to require thought about its design
Allows for many variations in its solution
Solves an easily understood problem
Solves a problem that's worth solving
Has a solution that is small enough to completely present and completely comprehend   

Thinking about the problem:
So how do we start? Basically, think a
bit about the problem and how to solve it.
 First think about what the program should do and how you'd like to interact with it.
Later, you can think about how the program could be written to do that.
Try writing down a brief sketch of an idea for a solution, and see what's wrong with that first idea. 
 Maybe discuss the problem and how to solve it with a friend.
Trying to explain something to a friend is a marvelous way of figuring out what's  wrong with ideas,
 even better than writing them down; paper (or a computer) doesn't talk back at you and challenge your assumptions .
 Ideally, design isn't a lonely activity.
Unfortunately, there isn't a general strategy for problem solving that works for all people and all problems. 
Adopt a more than usually skeptical attitude.
 

 Stages of development:
Here is a bit of terminology for program development. 
As you work all a problem you repeatedly go through these stages:
Analysis:
 Figure out what should be done and write a description of your
(current) understanding of that. Such a description is called a set of requirements
or a specification. We will not go into details about how such requirements are developed and written down.
 'That's beyond the scope of this book, but it becomes increasingly important as the size of problems increases.
Design: 
   Create an overall structure for the system, deciding which parts
the implementation should have and how those parts should communicate.
As part of the design consider which tools - such as libraries – can help you Structure the program.
Implementation:
 Write the code, debug it, and test that it actually does what it
is supposed to do.
  


2)Write a program to implement simple caluculator ?

#include <iostream>
using namespace std;
int main()
{
    float num1,num2;
    char ch,t;
    cout<<"Enter the expression (a+b or a-b or a*b ..........)\n";
    cin>>num1>>ch>>num2;
    
    switch(ch)
    {
        case '+' :cout<<num1<<ch<<num2<<"="<<num1+num2<<endl;
                  break;
        case '-' :cout<<num1<<ch<<num2<<"="<<num1-num2<<endl;
                  break;      
        case '*' :cout<<num1<<ch<<num2<<"="<<num1*num2<<endl;
                  break; 
        case '/' :cout<<num1<<ch<<num2<<"="<<num1/num2<<endl;
                  break;
       
    }
    return 0;
}
output:
Enter the expression (a+b or a-b or a*b ..........)
5+2
5+2=7

Enter the expression (a+b or a-b or a*b ..........)
5-2
5-2=3

Enter the expression (a+b or a-b or a*b ..........)
7*10
7*10=70
Enter the expression (a+b or a-b or a*b ..........)
5/2
5/2=2.5



3)Describe briefly about completing a problem ?

loading progress:

Thursday, 14 November 2013

Oops Program

3a Program (OOPS)

a) Write a C++ program to read a sequence of double 
values into a vector. Think of eachvalue as the distance between
 two cities along a given route. Compute and int the total
distance. Find and print the smallest and greatest distance
 between two neighboring cities.
Find and print the mean distance of the neighboring cities.

Program ::

#include < iostream> #include < vector> #include < algorithm> using namespace std; int main() { double val,sum=0; vector< double>dist; cout<< "Enter the series of distances between two cities along a route \n" ; while(cin>>val&&val!=0) { dist.push_back(val); sum+=val; } cout<<"\nThe total distance is: " << sum; cout<<"\nThe max distance between two neighboring cities is " << *max_element(dist.begin(), dist.end()); cout<<"\nThe min distance between two neighboring cities is " << *min_element(dist.begin(), dist.end()); return (0); }

Output::

Enter the series of distances between two cities along a route 25.77 50.50 60.73 77.77 0 The total distance is: 214.7 The max distance between two neighboring cities is 77.77 The min distance between two neighboring cities is 25.77

Wednesday, 13 November 2013

Ds Mid1 Imp Questions

          Ds Mid1 Imp Questions 
1)Write a short notes on the following a)space complexity b)time complexity c)asymptotic notations d)Recursive algorithm 2)What is LIFO and explain its operations with examples. 3)What is a queue and explain its operations with examples. 4)Explain the procedure and write a program to convert infix expression into postfix. 5)What is a list and explain the different operations on single linked list. 6)What is the drawback of single linkedlist and explain the operations on double linkedlist. 7)a)Write a program to implement linked stacks. b)Write a program to implement linked queues. 8)What is the drawback of a queue. Explain circular queues with its operations.
                 ANSWERS 
Coming soon

Sunday, 10 November 2013

Ds Week3 Programs

Exercise 3

3c)C Program to convert infix expression into postfix expression

Aim::/*To convert infix expression into postfix expression */

Program::

#include< stdio.h> //Standard i/p,o/p header file
#include< string.h>
#include< ctype.h>
#define size 20    //The variable 'size' is defined as macro for ease initialisation & to avoid repeated referencing.
int top=-1,Stack[size];      //Global variables to work in all the functions.
char infixexp[size],postfixexp[size];

void push(char ch)      //push() fuction.....
{
    Stack[++top]=ch;
}

char pop()                                //pop() function.....
{
    retun(Stack[top--]);
}

int precedence(char op)       //To know the precedence of operators.....
{
    if(op=='+'||op=='-')
        retun 1;
    else if(op=='*'||op=='/'||op=='%')
        retun 2;
    else if(op=='(')
        retun 3;
    else
        retun 0;
}

int main()                                //main() function 
{
    int i=0,j=0,l;
    char ch;
    printf("\n\nPlease enter Infix Expression to convert into Postfix: ");
    scanf("%s",infixexp);
    l=strlen(infixexp);
    for(i=0;i<=l;i++)
    {
        if(isalpha(infixexp[i]))        //Checking alphabets.....
        {
            postfixexp[j++]=infixexp[i];
        }
        else if(precedence(infixexp[i]))    //Checking operators either to push into the Stack or to add it to Postfix Expression.....
             {
                while(Stack[top]!='(' && precedence(infixexp[i])<=precedence(Stack[top]))
                {
                    postfixexp[j++]=pop();
                }
                push(infixexp[i]);
            }
            else if(infixexp[i]==')')        //Operator is closed paranthesis pop all the operators until open paranthesis.....
                 { 
                    while(Stack[top]!='(')
                    {
                        postfixexp[j++]=pop();
                    }    
                    if(top<0)                
                    {
                        printf("\n\nDue to wrong paranthesis.....Infix is wrong......");
                    }    
                    pop();
                }
    }
    
    while(top>-1)
    {
        ch=pop();
        if(ch!='(')
        {
            postfixexp[j++]=ch;
        }
        else
        {
            printf("\n\nforget to place closed paranthesis in Infix Expresssion......");
            break;
        }
    
    }
    
    postfixexp[j]='\0';
    
    printf("\n\nConverted Postfix Expression is : ");
    for(i=0;iint.....
        printf("%c ",postfixexp[i]);
    print>f("\n\n");
}


output::

gcc postfix.c -o postfix
./postfix

Please enter Infix Expression to convert into Postfix: a+b*c


Converted Postfix Expression is : a b c * + 


./postfix


Please enter Infix Expression to convert into Postfix: a*b+c


Converted Postfix Expression is : a b * c + 


./postfix

Please enter Infix Expression to convert into Postfix: a+b*c/(d-e)


Converted Postfix Expression is : a b c * d e - / + 



Ds Week2 programs

Exercise 2

2c)Implement stack operations using pointers

Aim::/*To implement stacks using pointers*/

Program::

#include< stdio.h> //Standard i/p,o/p header file
#define max 100
int  arr[max],top=-1; 
int  *stack=arr; 
 
/*Inserting the elements using push function*/ 
void  push(int  ele) 
{ 
     *stack=ele; 
    printf("\n\nElement %d is pushed......\n\n",ele); 
    stack++; 
    top++; 
} 
 
/*Removing the elements using pop function*/ 
void  pop() 
{ 
    if(top==-1) 
    { 
        printf("\n\nStack is empty....."); 
    } 
    else 
    { 
        printf("\n\nPoped element : %d",*(stack-1)); 
        stack--; 
        top--; 
    } 
} 
 
/*Displaying the elements */ 
void  display() 
{ 
     int  t; 
     if(top==-1) 
        printf("\n\nStack is empty....."); 
    else 
    { 
        printf("\n\nStack elements are : "); 
        for(t=top;t>=0;t--) 
        { 
                printf("%d ",*(stack-(t+1))); 
        } 
    } 
      
} 
int  main() 
{ 
    int  num1=0,num2=0,i,ch; 
    while(1) 
    { 
            printf("\n\t\t MENU "); 
            printf("\n[1]Push Function\n[2] Pop Function\n[3] Elements present in Stack\n[4] Exit\n"); 
            printf("\n\tEnter your choice: "); 
         
            scanf("%d",&ch); 
        switch(ch) 
        {  
                  case 1: printf("\n\tEnter the element to be pushed:"); 
                       scanf("%d",&num1); 
                       push(num1); 
                       break; 
                  case 2: pop(); 
                       break; 
                  case 3: display(); 
                       break; 
                  case 4: break; 
                  default: printf("\nYour choice is invalid.\n"); 
                             break; 
        } 
     
   } 
}

output::

gcc pointers.c -o pointers
./pointers

		 MENU 
[1]Push Function
[2] Pop Function
[3] Elements present in Stack
[4] Exit

	Enter your choice: 1

	Enter the element to be pushed:8


Element 8 is pushed......


		 MENU 
[1]Push Function
[2] Pop Function
[3] Elements present in Stack
[4] Exit

	Enter your choice: 1

	Enter the element to be pushed:2


Element 2 is pushed......


		 MENU 
[1]Push Function
[2] Pop Function
[3] Elements present in Stack
[4] Exit

	Enter your choice: 1

	Enter the element to be pushed:17


Element 17 is pushed......


		 MENU 
[1]Push Function
[2] Pop Function
[3] Elements present in Stack
[4] Exit

	Enter your choice: 3


Stack elements are : 8 2 17 
		 MENU 
[1]Push Function
[2] Pop Function
[3] Elements present in Stack
[4] Exit

	Enter your choice: 4