MENU











Monday, 23 December 2013

week 12 oops

Week 12 solutions

12a) Write a C++ program to display the contents of a text file.


File: hello.txt
               Hello
**** Welcome to C++ programming ****


Program:
#include<iostream>
#include<fstream>
using namespace std;
int main()
{ 
       ifstream in("hello.txt");
       cout<<in.rdbuf(); //rdbuf() function outputs all the contents of the file
       return 0;
}
output:
               Hello
**** Welcome to C++ programming ****


12 b) Write a C++ program that counts the characters, lines and words in the text file.

file:wish.txt
Hello
Welcome to C++ programming
happy coding

program:

#include<iostream>
#include<fstream>
#include<cctype>
using namespace std;
int main()
{
       int data,count=0,words=0,lines=0;
       ifstream file;
       file.open("wish.txt",ifstream::in);
       char c=file.get();
       cout<<"\nContents of the file\n";
       while(!file.eof())
       {
           cout<<c;
      
           if(isalnum(c))
              count++;
           if(isspace(c))
              words++;
           if(c=='\n')
              lines++;
           c=file.get();
       }
      lines++,words++;
      file.close();
      cout<<"\n\n Characters :"<<count;
      cout<<"\n Lines :"<<lines;
      cout<<"\n Words :"<<words;
      return(0);
}

output:
Hello
Welcome to C++ programming
happy coding

characters:37
Lines:3
words:7



12 c) Write a C++ program that produces the sum of all the numbers in a file of whitespace
separated integers.

File:num.txt
1 2 3 4 5 6 7 8 9 10

program:

#include<iostream>
#include<fstream>
using namespace std;
int main(void)
{
     int sum=0;
     ifstream file("num.txt");
     int x;
     while(!file.eof())
     {
          file>>x;
          cout<<x<<" ";
          sum+=x;
     }
     file.close();
     cout<<"\nSum of all integers is "<<sum;
}

output:
1 2 3 4 5 6 7 8 9 10
Sum of all integers is 55

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



Sunday, 27 October 2013

Week 6 Programs

Week 6

6c) Write a C++ program that writes out the Fibonacci series. Find the largest Fibonacci number that fits in an int.

Aim::To display fibonacci series and to print the largest fibonacci number that fits in an int

Program::

#include< iostream>
using namespace std;
int main()
{
       int i=0,n;
       int fib[100]={0};
       int temp[40],t=-1;
       cout<<"Enter the range to print the fibonacci serries \n";
       cin>>n;
       for(i=0;i<100;i++)
       {
           if(i<2)
          fib[i]=i;
           else
          fib[i]=fib[i-1]+fib[i-2];
          if(fib[i]<0)
            {
            t++;
            temp[t]=i-1;    
            }
       }
       cout<<"The fibonacci series is \n";
       for(i=0;i< n;i++)
       {
            cout<< fib[i]<<"\t";
       }
cout<<"The largest fibonacci number that fits in an intis f[ " << temp[0]<<"]="<< fib[temp[0]];
   
}

Output::

Enter the range to print the fibonacci serries 
10
The fibonacci series is 
0	1	1	2	3	5	8	13	21	34 
The largest fibonacci number that fits in an int is f[46]=1836311903

Ds week3 Programs

Exercise 3

b) Consider a payment counter at which the customer pays for the items purchased. Every time a customer finished paying for their items, he/she leaves the queue from the front. Every time another customer enters the line to wait, they join the end of the line. Implement the application for this problem.

Aim::/*To implement queue at payment counter*/

Program::

#include< stdio.h> //Standard i/p,o/p header file
voidfill();     //prototype of function enque
void delete();   
void display();  
int queue[20],remv[20],temp[20];   //Declaration of array
int  f=-1,r=-1;     //f-front,r-rear intialisation
int int h,i,n,t,j;       //h-for switch case,n-for size of queue
int  main()      //main function 
{
 printf("Enter the size of queue : ");
 scanf("%d",&n);
 while(h!=4)
 {
  printf(" 1-for insert\n 2-for delete \n 3-for display \n 4-for exit \n Enter ur choice: ");
  scanf("%d",&h);
  switch(h)
  {
   case 1:fill(); //calling function
   break;
   case 2:delete();
   break;
   case 3:display();
   break;
   case 4:
   break;
   default:printf("Invalid entry \n");
  }
 }
}
void fill()
{
      j=0;
      if(r==n-1)
      {
            printf("Queue is full \n");
            display();
            printf("wait for sometime to send another person \n");
      }
 else
 {
            r++;
            if(f< 0||queue[r-1]< n)
            queue[r]=queue[r-1]+1;
            else if(queue[r-1]>=n ||queue[r-2]>=n)
            {
                 queue[r]=remv[j];
                 j++; 
                 f--;
            }
            printf("Filled position is %d \n",queue[r]);
 }
}
void  delete()
{
            if(r==-1)
            printf("Queue is empty deletion not possible\n");
            else
            {
                 f++;
                 remv[f]=queue[0];
                 printf("The removed position is %d \n",remv[f]);
                // printf("%d \t %d",f,remv[f]);
                 t=r;
            } 
            for(i=0;i<=t;i++)
            {
                  queue[i]=queue[i+1];
            }
              r--;
}
void  display()
{ 
 
            printf("\n The filled positions  in the queue are \n");
            if(r==-1)
            printf(" Null \n");
            else
            {
                   t=r;
                   for(i=0;i<=t;i++)
                   printf("%d \t",queue[i]);
                   printf("\n");
            }
             printf("\n Th1e vacant positions  in the queue are \n");
             if(r==n-1)
             printf(" Null \n");
  
             else
             {
                   temp[0]=queue[r];
                   i=-1;
                   for(j=1;j< n-r;j++)
                   {
                          temp[j]=temp[j-1]+1;
                          if(temp[j]>n)
                          {
                             i++;
                             printf("%d \t",remv[i]);
                          }
                          if(temp[j-1]<=n-1)   
                          {
                             printf("%d\t ",temp[j]=temp[j-1]+1);
    
                          }
                  }
             }
 printf("\n");  
}

output::

Enter the size of queue : 7
 1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 1
Filled position is 1 
 1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 1
Filled position is 2 
 1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 1
Filled position is 3 
 1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 1
Filled position is 4 
 1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 3

 The filled positions  in the queue are 
1 	2 	3 	4 	

 Th1e vacant positions  in the queue are 
5	 6	 7	 
 1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 2
The removed position is 1 
1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 2
The removed position is 2 
1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 2
The removed position is 3 
1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 2
The removed position is 4 
1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 3

 The filled positions  in the queue are 
 Null 

 Th1e vacant positions  in the queue are 
1	 2	 3	 4	 5	 6	 7	 
 1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice:4


Ds Week2 programs

Exercise 3

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) 
    { 
        print f("\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



Wednesday, 16 October 2013

Week 6 programs

Week 6

6b) Write a C++ program that reads a series of numbers and stores them in a vector. After the user inputs all the numbers he wishes to, ask how many of the numbers the user wants to sum. For an answer N, print the sum of the first N elements of the vector. For example “Please enter some numbers (press "0" at prompt to stop):” 12 23 13 24 15 “Please enter how many of the numbers you wish to sum, starting from the first:” 3 “The sum of the first 3 numbers : 12 23 and 13 is 48”

Aim::To find the sum of first "n" numbers in vector

Program::

#include< iostream>
#include< vector>
using namespace std;
int main()
{
       
	vector< int>vector;
        int myint=1;
        int i,n,sum=0;
   	cout<<"Please enter some numbers(enter 0 to stop) \n";
        while(myint!=0)
        {
             cin >>myint;
             if(myint!=0)
             vector.push_back(myint);
        }   
  	cout<<"Enter how many numbers you wish to sum \n";
    	cin>>n;
    	cout<<"The sum of first "<< n<< " numbers:";
    	for(i=0;i< n;i++)
    	{
        	sum+=vector[i];
        	cout<< vector[i] <<"\t";
    	}
    	cout<< " is "<< sum;

}

Output::

Please enter some numbers(enter 0 to stop) 
12 23 13 24 15 0
Enter how many numbers you wish to sum 
3
The sum of first 3 numbers:12	23  13  is 48

It assignment 1

Information Theory

Assignment-1

1)What is entropy ?give an example and what are the properties of entropy ?

Ans::

Entropy::

		The average amount of information conveyed is called as entropy
			H(X) = 
		where p(x) is probability of particular random variable in a random space x and
log p(x) is the self information for that paricular random variable.

Properties of entropy::

2)What is chain rule ?explain with relative entropy,entropy and mutual information ?


Ans::

friends answer is there in our facebook group

/Click here for the ans

3)State and prove krafts inequality theorem and explain optimal codes ?

Ans::

Kraft inequality: 
			For any instantaneous code (prefix code) over an alphabet of size D, the
codeword lengths *** must satisfy the inequality

Conversely, 
	given a set of codeword lengths that satisfy this inequality, there exists an instantaneous
 code with these word lengths. 
Proof::
	Consider a D-ary tree in which each node has D children. 

Let the branches of the tree represent the symbols of the codeword. 

The prefix condition on the codewords implies that no codeword is an ancestor 
of any other codeword on the tree. Hence, each codeword eliminates its descendants
as possible codewords. 

Let lmax be the length of the longest codeword of the set of codewords. 

Consider all nodes of the tree at level lmax.

Some of them are codewords, some are descendants of codewords, and some are neither. 

A codeword at level li has **** descendants at level lmax Each of these descendant sets must be disjoint.

Also,the total number of nodes in these sets must be less than or equal to Dlmax. 

Hence, summing over all the codewords, we have 

{
**************
}

Conversely,
given any set of codeword lengths ***** which satisfy the Kraft inequality,
we can always construct a tree and we have instantaneous code at each level


Optimal codes ::

4)Explain arithmetic code with an example ?

5)What is shannon fano elias code ?

Wednesday, 9 October 2013

Week 6 programs

Week 6
6a) Write a C++ program that uses functions.

I) to swap two integers II) to swap characters III) to swap two reals

Aim::To implement the swap functions by integer,character,real

Program::

#include< iostream >
using namespace std;
void swap(int a,int b)
{
   	cout<<"\nBefore swapping of integers:\nA="<< a<<"\nB="<< b;
	int c=a;
	a=b;
	b=c;
	cout<<"\nAfter swapping of integers:\nA="<< a<<"\nB="<< b;
}
	
voidswap(char a,char b)
{
	cout<<"\nBefore swapping of characters:\nA="<< a<<"\nB="<< b;
	char c=a;
	a=b;
	b=c;
	cout<<"\nAfter swapping of characters:\nA="<< a<<"\nB="<< b;
}

voidswap(float a,float b)
{
	cout<<"\nBefore swapping of reals:\nA="<< a<<"\nB="<< b;
	float c=a;
	a=b;
	b=c;
	cout<<"\nAfter swapping of realss:\nA="<< a<<"\nB="<< b;
}


int main()
{
	int a,b;
	cout<<"Enter two integers :";
	cin>>a>>b;
	swap(a,b);
	char c1,c2;
	cout<<"\nEnter two characters :";
	cin>>c1>>c2;
	swap(c1,c2);
	float f1,f2;
	cout<<"\nEnter two real numbers :";
	cin>>f1>>f2;
	swap(f1,f2);
}

Output::


Enter two integers :
7 17
Before swapping of integers:
A=7
B=17
After swapping of integers:
A=17
B=7

Enter two characters :
h n
Before swapping of characters:
A=h
B=n
After swapping of characters:
A=n
B=h

Enter two real numbers :
7.7 8.8
Before swapping of reals:
A=7.7
B=8.8
After swapping of reals:
A=8.8
B=7.7

Sunday, 6 October 2013

Week 2 Programs

Week 2

a) Write a C++ program to convert centigrade into Fahrenheit. Formula:C=(F-32)/1.8

AIM:To convert temperature into centigrade

Program::

#include< iostream >
using namespace std;
int main()
{
    float c,f;
   cout<<"Enter the temperature in fahrenheit"<< endl;
    cin>>f;
    c=(f-32)/1.8; //c=5(f-32)/9;
   cout<< "Temperature in centigrade is " << c;
}

Output::

Enter the temperature in fahrenheit
212
Temperature in centigrade is 100

Wednesday, 2 October 2013

Week 1 Programs

Week 1

1a) Write a C++ program to display “Hello, Welcome to C++ Programing”

AIM:To display “Hello, Welcome to C++ Programing

Program::

#include < iostream.h >
#include < string.h >
int main()
{
cout<< "\"Hello,welcome to c++ programming\"\n";
}

Output::

Hello,welcome to c++ programming

1b) Write a C++ program to print details name, rollnumber in a single and two lines.

AIM:To display name, rollnumber in a single and two lines

#include < iostream >
#include < cstring >
using namespace std ;
int main()
{
char Name[20];
int roll;
cout << "Enter Your name:\n ";
cin>>Name;
cout << "Enter Your roll number:\n ";
cin>>roll;
cout <<"Name:" << Name;
cout<<"Roll Number:" << roll;
cout<<"Name:" << Name << endl;
cout<<"Name:" << Name << endl <<"Roll Number:" < }

1c) Write a C++ program to print name by reading, assigning and initializing to a variable with an appropriate prompt

AIM:To display name by reading and assigning

#include < iostream >
#include < cstring >
using namespace std ;
int main()
{
char Name[20];
char Name1[20]=programmer007; cout << "Enter Your name:\n ";
cin>>Name;
cout <<"Name:" << Name < cout<<"Name1:" << Name << endl;
}

Output::

Enter your name
Programmer
Name:Programmer
Name1:Programmer 007


1d) Write a C++ program to print your personal details name, surname(single character), totalmarks, gender(M/F), result(P/F) by taking input from the user

AIM:To display personal details

#include < iostream >
#include < cstring >
using namespace std ;
int main()
{
char Name[20];
char s;
int m;
char g;
char r;
cout << "Enter Your name:\n ";
cin>>Name;
cout << "Enter Your Sur name:\n ";
cin>>s;
cout << "Enter your total marks:\n ";
cin>>m;
cout << "Enter Your gender (M/F):\n ";
cin>>g;
cout << "Enter your result(P/F):\n ";
cin>>r;
cout <<"Name:" << Name << endl;
cout <<"SurName:" << s << endl;
cout <<"Total marks:" << m << endl;
cout <<"Gender:" << g << endl;
cout <<"Result:" << r << endl;
}

Output::

Enter your name
Programmer
Enter your Surname name
C
Enter your Total marks
77
Enter your Gender
M
Enter your result
P
Name:Programmer
Sur Name:C
Total marks:77
Gender:M
Result:P


Saturday, 14 September 2013

Happy Engineer's Day
In India, Engineer's day is celebrated on September 15. This day is celebrated in the honor of Sir Mokshagundam Visvesvaraya(1861-1962) On His Birthday.For his contribution to engineering field he was awarded the Indian public's highest honour , the Bharat Ratna, in 1955 along with Mr Bhagwan Das(1869–1958),Independence activist, author and Mr Jawaharlal Nehru(1889–1964),first Prime Minister of India.
Happy Engineer's Day