Blogger news

Followers

Friday, September 27, 2013
Design,develop,and execute a program in C++ to create a class called OCTAL, which has the characteristics of an octal number, Implement the following operations by writing an appropriate constructor and an overloaded operator +.
<![if !supportLists]>1.       <![endif]>OCTAL h=x;where x is an integer
<![if !supportLists]>2.       <![endif]>Int y=h+k; where h is an OCTAL object and k is an integer.
Display the OCTAL result by overloading the operator<<. Also display the values of h and y.

#include<iostream.h>
#include<conio.h>

class octal
{
  int onum;

  public:
                octal(int);
                friend ostream& operator<<(ostream&,octal&);
                int operator+(int);
};

octal::octal(int x)
{

  //decimal to octal conversion
  int base=1,rem;
  onum=0;
  while(x>0)
  {
    rem=x%8;
    x=x/8;
    onum=onum+rem*base;
    base=base*10;
  }
}

ostream& operator<<(ostream& dout,octal& h)
{
  dout<<h.onum;
  return dout;
}

octal::operator+(int k)
{
  //conversion from octal to conversion
  int rem,base=1,dnum=0,y;

  while(onum>0)
  {
   rem=onum%10;
   onum=onum/10;
   dnum=dnum+rem*base;
   base=base*8;
   y=dnum+k;
  }

 return(y);
}

void main()
{

 int x,k,y;
 clrscr();

 cout<<"enter the value of x \n";
 cin>>x;
 octal h=x;
 cout<<"the value of h is"<<h<<endl;
 cout<<"enter the value of k \n";
 cin>>k;
 y=h+k;
 cout<<"value of y="<<y;
 getch();
}
Screenshot:
Thursday, September 26, 2013
Design, develop and execute a program in C to Evaluate a valid postfix expression using stack. Assume that the postfix expression is read as a single line consisting of non-negative single digit operands and binary arithmetic operators. The arithmetic operators are +(add),-(subtract),*(multiply) and / (divide)

#include<stdio.h>
 #include<conio.h>
 #include<ctype.h>
 #include<math.h>

 char postfix[20];
 int top=-1;
 float value[20],stack[20];
 float eval();

 void push(float);
 float pop();

 void main()
 {
  int i=0;
  float result;
  clrscr();

  printf("enter a valid postfix expression\n");
  scanf("%s",postfix);
  while(postfix[i]!='\0')
  {
    if(isalpha(postfix[i]))
    {
     printf("enter the value of %c\n",postfix[i]);
     scanf("%f",&value[i]);
    }
   i++;
  }
  result=eval();
  printf("the value of the expression is %.2f\n",result);

  getch();
 }

 float eval()
 {
  int i=0;
  float op1,op2,result;

  while(postfix[i]!='\0')
  {
    if(isalpha(postfix[i]))
      push(value[i]);
    else
    {
      op2=pop();
      op1=pop();

      switch(postfix[i])
      {
                case'+':
                       push(op1+op2);
                       break;
                case'-':
                       push(op1-op2);
                       break;
                case'*':
                       push(op1*op2);
                       break;
                case'/':
                       push(op1/op2);
                       break;
      };
    }
   i++;
  }
 result=pop();
 return result;
}

void push(float value)
{
  top=top+1;
  stack[top]=value;
  return;
}


float pop()
{
  return stack[top--];
}
Screenshot:
#include<iostream.h>
 #include<conio.h>

 class student
 {
   protected:
     int rollno;
   public:
    void getroll()
    {
      cout<<"enter the roll no"<<endl;
      cin>>rollno;
    }
 };
 class marks:public student
 {
   protected:
     int marks;
  public:
     void getmarks()
     {
       cout<<"enter the marks"<<endl;
       cin>>marks;
     }
     void display()
     {
      getroll();
      cout<<"roll no:"<<rollno<<endl<<"marks:"<<marks;
     }
 };


 void main()
 {
   marks b;
   clrscr();
   b.getmarks();
   b.display();
   getch();
 }

Screenshot:


#include<iostream.h>
 #include<conio.h>

 class test
 {
   int x;
   int temp;
   public:
     void operator -();
     void read();
     void display();
 };
  void test::operator-()
  {
    x=-x;
  }
  void test::read()
  {
   x=20;
   temp=x;
  }
  void test::display()
  {
   cout<<"temp="<<temp<<endl;
   cout<<x<<endl;
  }

 void main()
  {
    test b;
    clrscr();
    b.read();
    -b;
    b.display();

    getch();
  }
Screenshot:
#include<iostream.h>
 #include<conio.h>
 class add
 {
  int a,b,c;
  public:
   add(int x,int y)
   {
     a=x;
     b=y;
     c=a+b;
     cout<<"result="<<c<<endl;
   }

};


 void main()
 {
  clrscr();
  add(10,20);



 getch();
  }
Screenshot:



Wednesday, September 25, 2013
 #include<iostream.h>
 #include<fstream.h>
 #include<conio.h>

 void main()
  {

   clrscr();
   int i;
   ofstream outf("SACHIN TENDULKAR");
   cout<<"enter the value"<<endl;
   cin>>i;
   outf<<i;
   outf.close();

   ifstream inf("SACHIN TENDULKAR");
   inf>>i;
   cout<<i;

   inf.close();

   getch();

   }

Design,develop and execute the c++ program according to the below instructions:
  An employee class is to contain following datamembers and memer functions:
data member:
   empolyee_number
   employee_name
   basic_salary
   all_alavances
    it(income tax)
    net_salary
member functions:
   to read data of an emplyee
   to calculate salary
   to print value of all data memebers
hints:
all_alavances=120% of basic salary
it=30% of gross salary
net salary=basic salary+all_alavances-income tax
gross salary=basic salary+all_alavances



---------
 #include<iostream.h>
 #include<conio.h>
 #define MAX 2
 class employee
 {
   int employee_number;
   char employee_name[15];
   int basic_salary;
   int all_alavances;
   int it;
   int net_salary;

   public:

       void read()
       {
     cout<<"enter the employee number"<<endl;
     cin>>employee_number;
     cout<<"enter the employee name"<<endl;
     cin>>employee_name;
     cout<<"enter the basic salary"<<endl;
     cin>>basic_salary;
     }
     void calc()
     {
       int gross;
       all_alavances=(basic_salary*120)/100;
       gross=basic_salary+all_alavances;
       it=(gross*30)/100;
       net_salary=gross-it;
       cout<<"calaculated"<<endl;
     }
     void print()
     {
      cout<<employee_number<<"\t"<<employee_name<<"\t"<<basic_salary<<"\t"<<all_alavances<<"\t"<<it<<"\t"<<net_salary<<endl;
     }
 };

 void main()
 {
   int i;
   employee a[MAX];

   clrscr();

   for(i=0;i<MAX;i++)
   {
     a[i].read();
     a[i].calc();

   }

   cout<<"employee number|empolyee name|basic salary|all alavances|income tax"<<"\t"<<"net_salary"<<endl;
   for(i=0;i<MAX;i++)
   {
    a[i].print();
   }
getch();
}






Sunday, September 15, 2013


Design,develop and execute a program in C to execute a validpostfix expression using stack. Assume that the postfix expression isread as a single line consisting of non-negative single digit operandsand binary arithematic operators.The arithematic operators are +(add),-(subtract),*(multiply) and /(add).


CLICK HERE TO DOWNLOAD PROGRAM FILE NOW!

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void infix_postfix(char[],char[]);
char s[30];
int top=-1;
void push(char elem)
{
 s[++top]=elem;
 }
 char pop()
 {
 return(s[top--]);
 }

void main()
{
char infix[20];
char postfix[20];
clrscr();
printf("Enter a valid infix expression\n");
gets(infix);
infix_postfix(infix, postfix);
printf("The postfix expression is\n");
puts(postfix);
getch();
}

void infix_postfix(char infix[],char postfix[])
{

 int j;
 int i;

 char symbol,x;

 push('#');
 j=0;
 for(i=0;i<strlen(infix);i++)
 {

  symbol=infix[i];
  switch(symbol)
  {
   case'(':
  push(symbol);
   break;
   case ')':

    while(s[top]!='(')
    {
    postfix[j++]=pop();
    }
    x=pop();
    break;
   case'/':
   case'*':
   case'+':
   case'-': while(isp(s[top])>=icp(symbol))
   {
     postfix[j]=pop();
     j++;
    }
   push(symbol);
    break;


   default:
   postfix[j++]=symbol;
   break;
   }
   }
   while(s[top]!='#')
   {
    postfix[j++]=pop();
    }

   postfix[j]='\0';
   }

int isp(char symbol)
{
switch(symbol)
{
case '/':
case '*':return (3);
case '+':
case '-':return (2);
case ')':
case '(':return (1);


case '#':return (-1);
default :return (0);
}
}
int icp(char symbol)
{
switch(symbol)
{
case'/':
case'*':return (3);
case'+':
case'-':return (2);
case'#':return (-1);
default:return (0);
}
}

 ------

/*Program Ends*/


CLICK HERE TO DOWNLOAD PROGRAM FILE NOW!
Monday, September 2, 2013
#include<stdio.h>
#include<conio.h>

void main()
{
int sum,num1,num2;
clrscr();
num1=10;
num2=4;
sum=num1+num2;
printf("%d",sum);

getch();
}
#include<stdio.h>
#include<conio.h>

void main()
{
  int i,a[i],m;
  clrscr();
   printf("enter the limit of array\n");
   scanf("%d",&m);
   printf("enter your array elements\n");
  
   for(i=0;i<m;i++)
  {
    scanf("%d",&a[i]);
  }
  printf("your array elements...\n");
  
   for(i=0;i<m;i++)
  {
    printf("%d\n",a[i]);
  }
 
getch();
}