sign up I login
 advanced
refer a friend - earn nickels!!

Ask & Discuss Questions with Community & Experts

Moderation Team
 90 chars left    advanced
Ask iit jee aieee pet cbse icse state board community Community Discussion Question: C++......
Forum Index -> Games, Puzzles and Quizzes like the article? email it to a friend.  
Author Message
antonyajay21 (497)

Blazing goIITian

Olaaa!! Perrrfect answer. 91  [112 rates]

antonyajay21's Avatar

total posts: 319    
offline Offline
#include<iostream.h>
#include<conio.h>
void main()
{
float sal[10];
int count;
cout<<"Enter the monthly salaries of 10 employes";
for(int i=1;i<=10;i++)
{
    cin>>sal[i];
    sal[i]=sal[i]*12;
    if(sal[i]>=100000)
    count++;
}
cout<<"The number of employes getting salary"
    <<"more than one lakh are "<<count;
getch();
}


Be not afraid of growing slowly.
Be afraid only of standing still.

 this reply: 10 points  (with Olaaa!! Perrrfect answer.   in 2 votes )   [?]
 
You have to be logged on to rate
  
Aatish (2308)

Blazing goIITian

Olaaa!! Perrrfect answer. 414  [533 rates]

Aatish's Avatar

total posts: 1102    
offline Offline
// This program illustrates the basic operation of add stack, delete stack
        // and shows stack using linked list. The stack contains data of type integer.

        #include <iostream.h>
        #include <stdio.h>
        #include <conio.h>
        #include <stdlib.h>
        #include <ctype.h>
        // Declares a stack structure
        struct node
        {
            int data;
            node *link;
        };
        // Function prototype declaration for add stack, delete stack and show stack
        node *push(node *top, int val);    // Add stack
        node *pop(node *top, int &val);    // Delete stack
        void show_Stack(node *top);    // Show stack
        // Main programming logic
        void main()
        {
            node *top;
            int val;
            int choice;
            char opt = 'Y';        // To continue the do loop in case
            top = NULL;        // Initialization of Stack
            clrscr();
            do
            {
                cout << "\n\t\t Main Menu";
                cout << "\n\t1. Addition of Stack";
                cout << "\n\t2. Deletion from Stack";
                cout << "\n\t3. Traverse of Stack";
                cout << "\n\t4. Exit from Menu";
                cout << "\n\nEnter Your choice from above ";
                cin >> choice;
                switch (choice)
                {
                    case 1:
                        do
                        {
                            cout << "Enter the value to be added in the stack ";
                            cin >> val;
                            top = push(top, val);
                            cout << "\nDo you want to add more element <Y/N>? ";
                            cin >> opt;
                        } while (toupper(opt) == 'Y');
                        break;
                    case 2:
                        opt = 'Y';    // Initialize for the second loop
                        do
                        {
                            top = pop(top,val);
                            if (val != -1)
                                cout << "Value deleted from Stack is " << val;
                            cout << "\nDo you want to delete more element <Y/N>? ";
                            cin >> opt;
                        } while (toupper(opt) == 'Y');
                        break;
                    case 3:
                        show_Stack(top);
                        break;
                    case 4:
                        exit(0);
                }
            }
            while (choice != 4);
        }
        // Function body for add stack elements
        node *push(node *top, int val)
        {
            node *temp;
            temp = new node;
            temp->data = val;
            temp->link = NULL;
            if(top ==NULL)
                top = temp;
            else
            {
                temp->link = top;
                top = temp;
            }
            return(top);
        }
        // Function body for delete stack elements
        node *pop(node *top,int &val)
        {
            node *temp;
            clrscr();
            if (top == NULL )
            {
                cout<<"Stack Empty ";
                val = -1;
            }
            else
            {
                temp = top;
                top = top->link;
                val = temp->data;
                temp->link = NULL;
                delete temp;
            }
            return (top);
        }
        // Function body for show stack elements
        void show_Stack(node *top)
        {
            node *temp;
            temp = top;
            clrscr();
            cout<<"The values are \n";
            while (temp != NULL)
            {
                cout <<"\n"<< temp->data;
                temp = temp->link;
            }
        }

............................................................................................................................................................................................
There's Light at the end of every Tunnel, so KEEP MOVING....
Best of luck to all my mates....
............................................................................................................................................................................................
 this reply: 5 points  (with Olaaa!! Perrrfect answer.   in 1 votes )   [?]
 
You have to be logged on to rate
  
antonyajay21 (497)

Blazing goIITian

Olaaa!! Perrrfect answer. 91  [112 rates]

antonyajay21's Avatar

total posts: 319    
offline Offline
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int num=2,pro;
clrscr();
for(num=0;num<=7;num++)
{
     pro=pow(2,num);
     if(pro==129)break;
     cout<<pro<<"\t";
}
getch();
}


Be not afraid of growing slowly.
Be afraid only of standing still.

 this reply: 5 points  (with Olaaa!! Perrrfect answer.   in 1 votes )   [?]
 
You have to be logged on to rate
  
antonyajay21 (497)

Blazing goIITian

Olaaa!! Perrrfect answer. 91  [112 rates]

antonyajay21's Avatar

total posts: 319    
offline Offline
        /*Program to print the smallest number*/
#include<iostream.h>
#include<conio.h>
void main()
{
int max=0,num[10],smallest=0;
clrscr();
cout<<"Enter the number of elements";
cin>>max;
for(int i=0;i<max;++i)
{
    cin>>num[max];
}
smallest=num[0];
for(int j=0;j<max;++j)
{
    if(num[j]<num[0])
    smallest=num[j];
}
cout<<smallest;
getch();
}

Be not afraid of growing slowly.
Be afraid only of standing still.

 this reply: 10 points  (with Olaaa!! Perrrfect answer.   in 2 votes )   [?]
 
You have to be logged on to rate
  
antonyajay21 (497)

Blazing goIITian

Olaaa!! Perrrfect answer. 91  [112 rates]

antonyajay21's Avatar

total posts: 319    
offline Offline
#include<iostream.h>
#include<conio.h>
void main()
{
int n,pro;
clrscr();
cout<<"Enter the beginning number of the table";
cin>>n;
for(int i=1;i<=10;i++)
{
    pro=n*i;
    cout<<"The product of "<<n<<"*"<<i<<"="<<pro<<"\n";
}
getch();
}


Be not afraid of growing slowly.
Be afraid only of standing still.

 this reply: 5 points  (with Olaaa!! Perrrfect answer.   in 1 votes )   [?]
 
You have to be logged on to rate
  
Aatish (2308)

Blazing goIITian

Olaaa!! Perrrfect answer. 414  [533 rates]

Aatish's Avatar

total posts: 1102    
offline Offline
// Addition and deletion of new books using linked list
        # include<iostream.h>
        # include <conio.h>
        class  NODE
        {
            public:
                int bookno;
                NODE *link;
        };
        class LINKLIST
        {
            private:
                NODE *first,*last,*temp;
            public:
                void NCREATE(int);    // Create a linked list with n nodes
                void insertatk(int);    // Inserting at kth position
                void display();    // Display the linked list
        };
        void LINKLIST::NCREATE( int n)
        {
            first = new NODE;
            cout << "\n Enter the book number ";
            cin >> first->bookno;
            first->link = NULL;
            temp = first;
            for(int i =1;i<n;i++)
            {
                last = new NODE;
                cout << "\n Enter the book number ";
                cin >> last->bookno;
                last->link = NULL;
                temp->link = last;
                temp = last;
            }
        }
        void LINKLIST::insertatk(int j)    // Function to insert the node at kth position
        {
            int i = 0;
            NODE *newnode,*back;
            newnode = new NODE;
            cout<< "\nEnter the data value ";
            cin>>newnode->bookno;
            newnode->link = NULL;
            temp = first;
            while (i < (j-1))
            {
                back = temp;
                temp = temp->link;
                i++;
            }
            back->link = newnode;
            newnode->link = temp;
        }
        void LINKLIST::display()    //Function to display the link list
        {
            temp = first;
            cout<< "\n The linked list is \n";
            while (temp != NULL)
            {
                cout<< "\n"<<temp->bookno;
                temp = temp->link;
            }
            getch();
        }
        void main()
        {
            int ch,n,k;
            char ch1 = 'y';
            LINKLIST    list;
            clrscr();
            cout << "\n Enter how many nodes in the list ";
            cin >> n;
            list.NCREATE(n);
            do
            {
                clrscr();
                cout<< "\n1. For insert ";
                cout << "\n2. For display ";
                cout << "\n3. For quit ";
                cout << "\nEnter your choice ";
                cin>>ch;
                switch (ch)
                {
                    case 1:
                        cout << "\nEnter the position at which insertion is required ";
                        cin >> k;
                        list.insertatk(k);
                        break;
                    case 2 :
                        list.display();
                        break;
                }
            } while (ch != 3);
        }

............................................................................................................................................................................................
There's Light at the end of every Tunnel, so KEEP MOVING....
Best of luck to all my mates....
............................................................................................................................................................................................
 this reply: 5 points  (with Olaaa!! Perrrfect answer.   in 1 votes )   [?]
 
You have to be logged on to rate
  
antonyajay21 (497)

Blazing goIITian

Olaaa!! Perrrfect answer. 91  [112 rates]

antonyajay21's Avatar

total posts: 319    
offline Offline
        /*Program to add two matrices*/
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5][5],b[5][5],c[5][5],row,column,i,j,k,l;
clrscr();
cout<<"Enter the rows of the matrices\n";
cin>>row;
cout<<"Enter the columns of the matrices\n";
cin>>column;
cout<<"Enter the elements of the first matrix";
for(i=1;i<=row;i++)
{
    cout<<"\n";
    for(j=1;j<=column;j++)
    {
    cout<<"Enter the "<<i<<"\t"<<j <<"element";
    cin>>a[row][column];
    }
}
cout<<"Enter the elements of the second matrix";
for(k=1;k<=row;k++)
{
    cout<<"\n";
    for(l=1;l<=column;l++)
    {
    cout<<"Enter the "<<k<<"\t"<<l<<" element";
    cin>>b[row][column];
    }
}
cout<<"The sum of the matrices is\n";
for(int x=1;x<=row;x++)
{
    cout<<"\n";
    for(int y=1;y<=column;y++)
    {
    c[row][column]=a[x][y]+b[x][y];
    cout<<c[row][column];
    }
}
getch();
}


Be not afraid of growing slowly.
Be afraid only of standing still.

 this reply: 5 points  (with Olaaa!! Perrrfect answer.   in 1 votes )   [?]
 
You have to be logged on to rate
  
antonyajay21 (497)

Blazing goIITian

Olaaa!! Perrrfect answer. 91  [112 rates]

antonyajay21's Avatar

total posts: 319    
offline Offline
  /*Program to find the vowels,consonants,words in a sentence*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
char sent[100];
int vowels=0,consonants=0;
clrscr();
cout<<"Enter any sentence\n";
gets(sent);
for(int i=0;sent[i]!='\0';i++)
{
    if(sent[i]=='a'||sent[i]=='e'||sent[i]=='i'||sent[i]=='o'
       ||sent[i]=='u')
    vowels++;
    else
    if(sent[i]!=' ')
    consonants++;
}
cout<<"The number of vowels in the sentence are "<<vowels<<endl;
cout<<"The total number of consonants are "<<consonants<<endl;
getch();
}


Be not afraid of growing slowly.
Be afraid only of standing still.

 this reply: 5 points  (with Olaaa!! Perrrfect answer.   in 1 votes )   [?]
 
You have to be logged on to rate
  
Aatish (2308)

Blazing goIITian

Olaaa!! Perrrfect answer. 414  [533 rates]

Aatish's Avatar

total posts: 1102    
offline Offline
// Program to find the occurrence of character in the string using pointers
#include<iostream.h>
#include<string.h>
#include<conio.h>
# include <stdio.h>
//CLASS DECLARATION
class strn
{
    char *a;
    char ch;
    int i;
    public:
        void read();       //MEMBER FUNCTIONS
        void find();
};    //END OF CLASS
void strn::read()
{
    cout << "\n\t";
    cout << "\n\tEnter the first string ";
    gets(a);              //TO READ THE STRING
}
void strn::find()
{
    i = 0;
    int count = 0;
    cout << "\n\t Enter the character ";
    cin >> ch;
    while (*(a+i) != '\0')
    {
        if (*(a + i) == ch)
            count++;
        i++;
    }
    cout << "\n\tThe number of times "<< ch << " occur in " << a << " is " << count;
}
//M A I N     P R O G R A M
void main()
{
    strn x;        //DECLARATION OF OBJECT
    clrscr();
    cout << "\n\n\n\t ";
    x.read();          //CALLING MEMBER FUNCTIONS
    x.find();
    getch();
}  //E N D    O F    M A I N


............................................................................................................................................................................................
There's Light at the end of every Tunnel, so KEEP MOVING....
Best of luck to all my mates....
............................................................................................................................................................................................
 this reply: 10 points  (with Olaaa!! Perrrfect answer.   in 2 votes )   [?]
 
You have to be logged on to rate
  
antonyajay21 (497)

Blazing goIITian

Olaaa!! Perrrfect answer. 91  [112 rates]

antonyajay21's Avatar

total posts: 319    
offline Offline
# include <iostream.h>
# include <conio.h>
void main()
{
 clrscr();
 float p,t,s;
 cout<<"enter p,t";
 cin>>p,t;
  t>=10 ? cout<< (p*t*8)/100 : cout<<(p*t*12)/100;
 cout<< "\n the si is"<<s;
 getch();
}


Be not afraid of growing slowly.
Be afraid only of standing still.

 this reply: 5 points  (with Olaaa!! Perrrfect answer.   in 1 votes )   [?]
 
You have to be logged on to rate
  
antonyajay21 (497)

Blazing goIITian