Blogroll

Blogger news

Monday, 1 June 2015

Mirror Image(Reverse) Of A Number In C++

//Mirror Image Of Number
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num,r,sum;
cout<<"Enter Number";
cin>>num;
while(num!=0)
{
r=num%10;
cout<<r;
num=num/10;
}
getch();
}

Output:
Enter Number 12345
54321

Using New And Delete Operator In C++

/* New and delete */
#include <iostream.h>
#include<conio.h>
class item
{
int ic,qty;
float up, amt;
char nm [10];
public:
void getdata ()
{
cout<<"Enter item code";
cin>>ic;
cout<<"Enter item name";
cin>>nm;
cout<<"Enter unit price and quantity";
cin>>up>>qty;
}
    void compute ()
    {
amt=up*qty;
    }
void putdata()
{
cout<<"\nItem data";
cout<<"\nItem name="<<nm;
cout<<"\nItem code="<<ic;
cout<<"\nItem amount="<<amt;
}
};
void main()
{
clrscr();
item * optr;
char ch;
while (1)
{
optr=new item;
optr->getdata();
optr->compute();
optr->putdata();
cout<<"\nWant to enter model detail press y";
cin>>ch;
if(ch=='y'||ch=='Y')
continue;
else
break;
}
delete optr;
getch();
}

Output:

Enter item code=101
Enter item name=Cheetos
Enter unit price and quantity=30 5

Item data
Item name=Cheetos
Item code=101
Item amount=150
Want to enter model detail press y

Sunday, 7 December 2014

Program For Dynamic Implementation Of Stack

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct Node
{
int Data;
struct Node *next;
}*top;

void popStack()
{
struct Node *temp, *var=top;
if(var==top)
{
top = top->next;
free(var);
}
else
printf("\nStack Empty");
}

void push(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (top == NULL)
{
top=temp;
top->next=NULL;
}
else
{
temp->next=top;
top=temp;
}
}

void display()
{
struct Node *var=top;
if(var!=NULL)
{
printf("\nElements are as:\n");
while(var!=NULL)
{
printf("\t%d\n",var->Data);
var=var->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}

int main(int argc, char *argv[])
{
int i=0;
clrscr();
top=NULL;
printf(" \n1. Push to stack");
printf(" \n2. Pop from Stack");
printf(" \n3. Display data of Stack");
printf(" \n4. Exit\n");
while(1)
{
printf("Choose Option:");
scanf("%d",&i);
switch(i)
{
case 1:
{
int value;
printf("Enter a value to push into Stack:");
scanf("%d",&value);
push(value);
break;
}
case 2:
{
popStack();
display();
break;
}
case 3:
{
display();
break;
}
case 4:
{
struct Node *temp;
while(top!=NULL)
{
temp = top->next;
free(top);
top=temp;
}
exit(0);
}
default:
{
printf("\nwrong choice for operation");
}
}
}
getch();
a}

Wednesday, 3 December 2014

To Print Stars In Different Manner

#include<stdio.h>
#include<conio.h>
void up();
void down();
void main()
{
int f;
clrscr();
printf("===::  DUSHYANT MAINWAL  ::===\n\n");

do
{
printf("\n\nEnter your opinion:\n1. Upward\n2. Downword\n3. Quit\n");
scanf("%d",&f);
switch(f)
{
case 1: up();
break;
case 2: down();
break;
case 3: break;
default: printf("Invalid Choice\n");
}
}
while(f!=3);
getch();
}
void up()
{
int n,i,j,k,s,m=1;
printf("\nEnter how many stars you want in First line\n");
scanf("%d",&n);
s=n;
for(k=1;k<=s;k++)
{
for(i=1;i<=n;i++)
{
printf(" *");
}
printf("\n");
for(j=1;j<=m && j<=s;j++)
{
printf(" ");
}
m=m++;
n=n--;
}
}
void down()
{
int n,i,j,m=1,k,s;
printf("\nEnter how many star you want in last line\n");
scanf("%d",&n);
s=n;
for(k=1;k<=s;k++)
{
for(i=1;i<=n;i++)
{
printf(" ");
}
for(j=1;j<=m && j<=s;j++)
{
printf(" *");
}
printf("\n");
n=n--;
m=m++;
}
}