Wednesday, July 29, 2015

complex questions

1.        The following code represents complex numbers in java. There are some blanks in the code. Please fill in the blanks.

class Complex
{
                int iReal,iImaginary;
            // insert zero parameter constructor and initialize iReal,iImaginary to 0.
               
                



               
           //  insert one parameter constructor to initialize the iReal,iImaginary with the parameter
 






           //  insert two parameter constructor to initialize the iReal,iImaginary with the two parameters passed
            





             Complex addComplex(Complex C1,Complex C2) // function to add the complex numbers
                {
                                Complex CTemp=new Complex();
                                CTemp.iReal=C1.iReal+C2.iReal;
                                CTemp.iImaginary=C1.iImaginary+C2.iImaginary;
                                return CTemp;
                }
           Complex subComplex(Complex C1,Complex C2) // function to subtract the complex numbers
           {
 


          


    
          }

}

class Complexmain
{
                public static void main(String[] a)
                {
                                Complex C1, C2, C3;

                        // create C1 with one parameter constructor
                       // create C2 with two parameter constructor
                            // create C3 with Zero parameter constructor
 




                    

                                C3=C3.addComplex(C1,C2); //function call

                                //Display the results
                                System.out.println("---Sum---");
                                System.out.println("Real :" + C3.iReal);
                                System.out.println("Imaginary :" + C3.iImaginary);
                }
}



2. Write a program to calculate the age of a person when birth date is provided as input.  R COJ 02 Age Calculator
3. Write a program to print the calendar for any given month and year. If no month and year are specified, print the calendar for the current month.


No comments:

Post a Comment