Thursday, September 25, 2014

WAP defining a class named complex with two data members real and imaginary. Use necessary member functions for input/output and define a member function that adds the two complex objects and return object. Also display the result using a member function display ().

#include
#include
#include
#include

class complex
{
            long float real,img,c1,c2,c3;
            public:
            complex add(complex c1,complex c2);
            void input()
            {
                        cout<<"Enter Real number:";
                        cin>>real;
                        cout<<"Enter Imaginary Number:";
                        cin>>img;
            }
            void output(complex c3)
            {
                        cout<<"The sum is:"<
            }
};

            complex complex:: add(complex c1,complex c2)
            {
                        complex c3;
                        c3.real=c1.real+c2.real;
                        c3.img=c1.img+c2.img;
                        return c3;
            }
void main()
{
            clrscr();
            complex c1,c2,c3;
            c1.input();
            c2.input();
            c3=c3.add(c1,c2);
            c3.output(c3);
            getch();

}

WAP to read name, roll no, address and phone number of each student in you class using structure. Store the information in file so that you can recover the information later. While recovering the information from the file sort the information alphabetically according to the name.

#include
#include
 struct rec
            {
          int roll;
          char name[50];
          char add[20];
          long ph;
   }student[15];

void main()
{
   struct rec;
   int n,i,j;
   clrscr();
   printf("\n enter the no. of students: ");
   scanf("%d",&n);
   for(i=0; i
   {
      printf("\n enter roll no of student: ");
      scanf("%d",&student[i].roll);
      printf("\n enter name of student: ");
      scanf("%s",&student[i].name);
      printf("\n enter address of student in C: ");
      scanf("%s",&student[i].add);
      printf("\n enter phone of student in C: ");
      scanf("%ld",&student[i].ph);
   }
   for(i=0;i
   {

   printf("\n the records in ascending order are as follows: ");
   printf("\n roll \t\tname\t\taddress\t\tphone no");
   for(i=0; i
   {

      printf("\n  %d\t\t%s",student[i].roll,student[i].name);
      printf("\t\t  %s",student[i].add);
      printf("\t\t%ld",student[i].ph);
   }
   getch();

}

WAP to find the average expenditure of a company for each month of each year and average over the range of years specified. Use arrays to construct a table, display the table of expenditure and find the sum and average.

#include
#include
void main()
{
            int i,n,j,b=0,a[12][12],c=0,d=0,e=0;
            clrscr();
            printf ("\t************* EXPENDITURE OF THE COMPANY **************\t");
            printf ("\n How many years???");
            scanf ("\t %d",&n);
            for (i=1;i
            {
                        printf ("\n \n");
                        printf ("\n ----For the %d year----\n \n",i);
                        b=0;
                        for (j=1;j<13 j="" o:p="">
                        {
                                    printf ("Enter the expenditure for %d month::Rs.\t",j);
                                    scanf ("\t %d",&a[i][j]);
                                    b=b+a[i][j];
                        }
                        printf ("\n Total Expenditure of the whole year:Rs.\t%d",b);
                        c=b/12;
                        printf ("\n Average Expenditure of the year:Rs.\t%d",c);
                        e=e+b;
            }
            printf ("\n \n");
            printf ("\n Total Expenditure of %d years:Rs.\t%d",n,e);
            d=e/n;
            printf ("\n Average Expenditure of %d years:Rs.\t%d",n,d);
            getch();

}

WAP in C++ to illustrate the use of manipulators with arguments.

#include
#include
#include
void main()
{
            float num=2.2435612333;
            cout<
   getch();

}

WAP in C++ to print the value of global variable within the local scope by the use of scope resolution operator.

#include
#include
#include
int s=90;
void main()
{
            int s=50;
   cout<<"value of local variable: "<
   getch();

}

WAP in C++ to print the following output using manipulators : LODGING 2000 CLOTHING 800 TRAVELLING 2500

#include
#include
#include
void main()
{
   long p1=2000, p2=800, p3=2500;
   cout<
   getch();

   }

WAP in C++ to calculate the factorial if entered number using

a.       While loop


#include
#include
void main()
{
            int n,fact=1,i;
   cout<<"enter a number: ";
   cin>>n;
   i=1;
   while(i<=n)
   {
            fact=fact*i;
      i++;
   }
   cout<
   getch();

}

b.    Do-while loop


#include
#include
void main()
{
            int n,fact=1,i;
   cout<<"enter a number: ";
   cin>>n;
   i=1;
   do{

            fact=fact*i;
      i++;
   } while(i<=n);
   cout<
   getch();
}

c.       For loop


#include
#include
void main()
{
            int n,fact=1,i;
   cout<<"enter a number: ";
   cin>>n;
   for(i=1; i<=n; i++)
            fact=fact*i;
   cout<
   getch();
}

WAP in C++ to show an input number is even or odd without the use of modulus operator.

#include
#include
void main()
{
            int n,i,d=0;
   cout<<"enter a number: "<
   cin>>n;
   d=n;
   for(i=0;i
   {
            d=d-2;
      }
   if(d==0)
            cout<<"No. is even";
   else
            cout<<"No. is odd";
   getch();

}