Tuesday 30 August 2011

You are required to write a program which takes two 3x3 matrix A and B containing 09 elements each and sort all these 18 elements in descending order and put it in one dimensional array and then display it.

Follow the following steps to code this program

1. Take two two-dimensional arrays as A[3][3]and B[3][3] and  one-dimensional array C[] to keep the result.

2. Prompt the user to enter the elements of first matrix

3. Prompt the user to enter the elements of second matrix

4. Now take first element of first matrix and check in both matrix weather it is greatest or any other number is the greatest and put the greatest number at the first index of the one dimensional array. Follow this procedure for other elements and at the end one dimensional array would be in descending order

5. Display this one-Dimensional sorted array on the screen


Following is the sample program structure



   2 3 5                2 8 7

A= 6 5 9             B= 0 1 1

   1 0 2                4 7 9



Output should be like this


Please enter the Elements of First Matrix:

Please enter the Elements of second Matrix:
 Sorted Values from Both the Matrices are:             

    ------------------------------------------------
     9 9 8 7 7 6 5 5 4 3 2 2 2 1 1 1 0 0
    ------------------------------------------------
Answer

#include<iostream.h>
// ---------- declaration of user defined function for merging and sorting array -----------
//user defined function for merging the arrays into one array
void merge(int [][3], int [][3], int[]);
//  user-defined function for sorting the merged array
void sort(int[], int);

//--------------    Start of the main function   -------------------
main()
{
   
 int A[3][3],B[3][3];   // declaration of 2D arrays
 int C[18];  // declaration of 1D array to store the values after merging


// prompting the user to enter the elements of first array 
 cout<<"Please enter the Elements of 1st Matrix\n\n";

 for(int row=0;row<3;row++)
 {
         for(int col=0;col<3;col++)
         {
                 cout <<"Enter the element for row "<<row+1 << ", column " <<col+1 <<":\t";
                 cin>>A[row][col];
         }
 }


 // prompting the user to enter the elements of second 2d array 
  cout<<"\n\nPlease enter the Elements of 2nd Matrix\n\n";

 for(int row=0;row<3;row++)
 {
         for(int col=0;col<3;col++)
         {
                 cout <<"Enter the element for row "<<row+1 << ", column " <<col+1 <<":\t";
                 cin>>B[row][col];
         }
 }

   cout<<"\n\nElements of 1st Matrix are:\n\n";

 for(int row=0;row<3;row++)
 {
         for(int col=0;col<3;col++)
         {
                 cout<<A[row][col];
                 cout<<"\t";
                
         }
        
         cout<<endl;
 }

    cout<<"\n\nElements of 1st Matrix are:\n\n";

 for(int row=0;row<3;row++)
 {
         for(int col=0;col<3;col++)
         {
                 cout<<B[row][col];
                 cout<<"\t";
                
         }
        
         cout<<endl;
 }
 //  calling user defined function for merging arrays
  merge(A, B, C);
 
 
 //  calling user defined function for sorting the resultant array
  sort(C, 18);

 
 // displaying the elements of sorted array on screen
  cout<<"\n\nSorted Values from Both the Matrices are:\n\n";
 
  for(int i=0; i<18; i++)
  {
     
       cout<<C[i];
       cout<<"\t";
       
  }

  cout<<endl<<endl;

  //  function to halt the output screen
 system("pause");

}

// function definition for merging the arrays
void merge(int Array1[][3], int Array2[][3], int mergeArray[])
{
     int insert = 0;
    
    
     for(int row=0; row<3; row++)
     {
          for(int col=0; col<3;col++)
          {
                 mergeArray[insert]=Array1[row][col];
                 insert++;
          }
     }
    
    

     for(int row=0; row<3; row++)
     {
         for(int col=0; col<3; col++)
         {
                 mergeArray[insert]=Array2[row][col];
                 insert++;
         }
     }
    

}
void sort(int Array[], int size)
{
      for(int row=0; row<size; row++)
  {
         for(int col=row; col<size; col++)
         {
                 if(Array[row]<Array[col])
                 {
                          int t;            
                          t = Array[row];
                          Array[row] = Array[col];
                          Array[col] = t;
                 }
         }
  }
    
}
   
 
 


Consider the following sequence of numbers: [ 20, 25, 3, 4, 14, 15, 18, 12, 9, 2, 16, 19, 17 ]


  • Construct Binary Search Tree (BST)                                                                      

  • Perform In-order, Pre-order and Post-order traversal                                      

  • Delete 15 from the above constructed BST                                                    

Solution

Construct Binary Search Tree (BST)                                                             


Perform In-order, Pre-order and Post-order traversal                                 
In-order:
2, 3, 4, 9, 12, 14, 15, 16, 17, 18, 19, 20, 25
Pre-order:
20, 3, 2, 4, 14, 12, 9, 15, 18, 16, 17, 19, 25
Post-order:
2, 9, 12, 17, 16, 19, 18, 15, 14, 4, 3, 25, 20
Delete 15 from the above constructed BST                                                    

As 15 has only one sub-tree, that is right sub-tree, so we will apply 2nd case of deletion.


The Josephus problem is the following mass suicide "game": n people, numbered 1 to n, are sitting in a circle. Starting at person 1, a handgun is passed. After m passes, the person holding the gun commits suicide, the body is removed, the circle closes ranks, and the game continues with the person who was sitting after the corpse picking up the gun. The last survivor is tried for n - 1 counts of manslaughter. Thus, if m = 0 and n = 5, players are killed in order and player 5 stands trial. If m = 1 and n = 5, the order of death is 2, 4, 1, 5.


Write a C++ program to solve the Josephus problem for general values of m and n using circular linked list data structure.

Input:

  • Number of People: n
  • Number of Passes: m

Output:

  • Order in which people are removed
  • The survivor



Sample Run:

Enter total number of People playing the game: 10

Enter number of Passes: 3

----------------------------------------------------

Game Started!

----------------------------------------------------

à Person removed: 4

à Person removed: 8

à Person removed: 2

à Person removed: 7

à Person removed: 3

à Person removed: 10

à Person removed: 9

à Person removed: 1

à Person removed: 6

----------------------------------------------------

ààà The survivor is : 5

----------------------------------------------------


Choose the adjective modifiers, adverb modifiers and dangling modifiers from the given paragraph.

Elizabeth, who just wanted a quick lunch to reach her office to attend an urgent meeting, quickly dropped her fork on the dining table. She had to drive the car speedily to reach her office in time. She saw an accident driving down the road which made her a bit more upset. When she reached her office, freshly painted, John, the painter, left the room to dry. She opened the door lazily, put her purse on the table and sat in the chair.

Solution:

Adjective modifiers: quick, urgent, more,

Adverb modifiers: quickly, fast, speedily, lazily,freshly

Dangling modifiers: driving down the road, freshly painted

Suppose you are the Networking Adminitrator of a multinational company. Your boss wants you to develop an interface which can be used to communicate with all the staff simultaneoulsy. Write a Feasibility Report in order to convey the possibilty and importance of the assigned project.


Students are supposed to write according the given superstructure. Generally reports can be written in memo or letter format.



Introduction



Identify a problem or goal that is significant from the point of view of your employer or client



Criteria



Criteria often address one or more of the following questions:

  • Will the course of action really do what’s wanted?

  • Can we implement it?

  • Can we afford it?

  • Is it desirable?






Method of obtaining facts



Assure your readers that your facts form a sound basis for your decision-making. The source of your facts will depend upon the nature of your study:

  • Library research

  • Calls to manufacturers

  • Interviews

  • Meetings with other experts in your organization

  • Surveys

  • Laboratory research






Overview of alternatives [optional]



You may sometimes need to provide extensive background information or otherwise explain the alternative to your readers.



Evaluation



The heart of a feasibility report is the detailed evaluation of the course or courses of action, you studied



Conclusions



Your conclusions are your overall assessment of the feasibility of the courses of action



Recommendations



It is customary to end a feasibility report by answering the decision-maker’s question “What do you think we should do?”

Make the following statements considerate:

  1. When we travel on company expense, we will not receive approval for first class fare.

  2. We don’t refund if the returned item is soiled or non-salable.

  3. It is impossible to open an account for you today.

  4. We are delighted to announce 8% interest on saving accounts.

  5. We take pride to offer four different majors i.e. accounting, management, industrial management, and economics in The School of Management.

Answer

  1. When you travel on company expense, your approved fare is of tourist class.


  2. Your money will be refunded immediately if the returned item is clean and resalable.


  3. You will be able to open your account by tomorrow.


  4. You will be happy to receive 8% interest on your saving accounts.


  5. In the School of Management, you can major in accounting, management, industrial management, and economics.

    Make the following statements concise:

    1. Legislators are already in the process of reviewing the statutes.


    2. This policy has a tendency to isolate some communities.


    3. In my opinion, this wasteful policy ought to be revoked.


    4. There were many factors that influenced his decision to become a teacher.


    5. They played a football game that was exhaustive.

    Answer

    1. Legislators are already reviewing the statutes.


    2. This policy tends to isolate some communities.


    3. This wasteful policy ought to be revoked.


    4. Many factors influenced his decision to become a teacher.


    5. They played an exhaustive football game.

      Monday 29 August 2011

      Write a short paragraph on the topic of your choice, using at least FIVE transitional markers.

      Answer

      Frequently used transitional markers are given below and students can write any paragraph of their choice making use of at least five of them. Any accurate transitional marker other than the mentioned ones will also be considered correct.

      Correct organization of a business message is important for both the audience and the communicator? Explain.

      Answer


      A good organization of a message will:

      1. Improve productivity. ( See the next page)

      By arranging the ideas in a logical and diplomatic way, you will increase the chances of satisfying the audience’s needs.

      2. Boost understanding.

      Audience will understand exactly what you mean

      3. Increase acceptance.

      Audience will comparatively believe the information/message conveyed.

      4. Save audience’ time.

      Well organized messages contain relevant information, so the audience does not waste time with superfluous information.

      Make the following statements considerate

      1. We are delighted to announce that we are opening a new store in Karachi.

      2. We don’t accept your claim of purchased goods but we have replacement for other goods.

      3. As our meeting venue is not finalized, we can call you at any other place.

      4. Our manager will be busy in the meeting on Monday, so he cannot meet you this time.

      5. The flights are cancelled, we are sorry that we will not be able to entertain you due to air smoke in Europe.

      Answer
      1. It will be happy news for you that you will find our new store in Karachi. 


      2. Your claim for purchased goods is accepted with replacement for other goods.


      3. You will be informed about the meeting place later.


      4. Your appointment with the manager is scheduled on Tuesday due to an important meeting on Monday


      5. As soon as the air space is clear in Europe, the new schedule of flights will be announced.


        You are required to write a program of class rectangle named CRectangle which should draw two rectangles by using iTop, iRight, iBot, and iLeft. Then program should calculate the area of both. Number of rectangles should be displayed to user by using static variable counter which would keep track of increment or decrement of rectangles. Dynamically Create another rectangle by using copy constructor and increment in counter should be displayed on screen. Decrement in static variable counter (after de-allocating memory which was dynamically allocated) should be displayed again on screen.

        Detailed Description:

        Sample Output

        Area of rectangle 1 is 6400

        Area of rectangle 2 is  5600

        The number of rectangles is 2          

        After using copy constructor, total number of rectangles is 3

        The number of rectangles is 2


        1. The class should have 4 members: iTop, iRight, iBot, and iLeft, all of type int.

        2. Area of both rectangles should be calculated by using iTop, iRight, iBot, and iLeft.

        3. It should have a default constructor and a copy constructor.

        4. It should have a destructor.

        5. It should contain all required getters and setters.

        6. It should contain a static member, iRefCount, which keeps track of the number of CRectangle objects. Increment it in the constructor, and decrement it in the destructor.

        Hint:

        CRectangle would implement rectangles by using left, right, top and bottom and calculate their areas to compare.

        Answer
        using namespace std;
        #include <iostream>
        #include <conio.h>
        class CRectangle {
            private:

         int   iLeft;                                                                    // Class members
         int   iTop;       
         int   iRight;     
         int   iBottom;    
         static int iRefCount;                                                        // Static variables   
        public:

         CRectangle::CRectangle (int l = 0, int t = 0, int r = 1, int b = 1);        // Constructors
         CRectangle::CRectangle (CRectangle& rect);
         CRectangle::~CRectangle ();


         int GetLeft() // Getters
            {
                return iLeft;
                    }                
         int GetTop() 
                    {
                return iTop;
                    }
         int GetRight() 
                    {
                return iRight;
                    }
         int GetBottom()
                    {
               return iBottom;
                    }

         void SetLeft(int iValue)                              // Setters
                    {
                iLeft = iValue;
                    }              
                   
            void SetTop(int iValue) 
                    {
                iTop = iValue;
                    }
               
         void SetRight(int iValue) 
                    {
               iRight = iValue;
                    }
                   
         void SetBottom(int iValue) 
                    {
               iBottom = iValue;
                    }
         int Area() 
                 {
                  return((iRight - iLeft) * (iBottom - iTop));
                  }

         static int GetRefCount()
                 {
                  return iRefCount;
                 }
        };
        int CRectangle::iRefCount = 0;                                  // Static variables
        CRectangle::CRectangle (int l ,int t , int r , int b)         // Default constructor
        {
         iLeft = l;
         iTop = t;
         iRight = r;
         iBottom = b;

         iRefCount++;
        }
        CRectangle::CRectangle (CRectangle& rect)                        // Copy constructor.
        {
         iLeft = rect.iLeft;
         iTop = rect.iTop;
         iRight = rect.iRight;
         iBottom = rect.iBottom;
         iRefCount++;
        }
        CRectangle::~CRectangle ()
        {
         iRefCount--;
        }
        int main()
        {
         CRectangle rect1(80, 120, 160, 200);
         CRectangle rect2(100, 140, 180, 210);
         int iArea = rect1.Area();                           // Calc area and output.
         cout << "Area of rectangle 1 is " << iArea << endl;
         iArea = rect2.Area();
         cout << "Area of rectangle 2 is " << iArea << endl;


         cout << "The number of rectangles is " << rect1.GetRefCount() << endl;    // Output total number of rectangles.


         CRectangle* pRectangle = new CRectangle();                               // Dynamically create a new instance of CRectangle.

         cout << "After using Copy constructor, total number of rectangles is " << rect1.GetRefCount() << endl;   // Output total number of rectangles.
         
         delete pRectangle;                                                       // Delete the rectangle object.


         cout << "The number of rectangles is " << rect1.GetRefCount() << endl;  // Output total number of rectangles.
         pRectangle = NULL;
            getch();
         return 0;
        }


        You are required to create a class in C++ named Price with the following Data members, Data members should be publicly declared.


        DetailedDescription:

        The Price class presents Price in Rupees and Paisa. For instance, Price (10, 80) means 10 rupees and 80 paisas. The Price class should have the following features as described in detailed descriptions:




        Constructors



        Class Price must have



        • Default constructor, which must set Rupees and Paisas to zero.




        • Parameterized constructor that receives two parameters of type int and initializes its private data: Rupees and Paisas with them. Note that if Paisas are 100 or greater than 100 then also convert it in Rupees.


        Member Functions

        • Create a function named Print()that displays the price of object in terms of rupees and paisas.


        Operator overloading

        • A member function that overloads the + Operator to add two objects of Price.




        There should be an overloaded + operators:



        • Add two objects and return Price object. Note that Paisas should not exceed 100.

        • Add first number into second objects and return Price object. Note that paisas should not exceed 100.






        Output of your program should be as follows:



        Price is 10 rupees and 60 paisas



        Price is 12 rupees and 80 paisas



        After Addition



        Price is 23 rupees and 40 paisas


        Answer

        #include <iostream.h>
        #include <stdlib.h>
        //definition for class Price
        class Price {         
             
              private:             
                      // private portion will contain no data member or function
                     
              public:
                 
                      int rupees, paisas;   //declaration for private data members of Price class
                     
              //prototypes for member functions and constructors of class
             
                      Price();                  // default constructor for class
                     
                      Price(int, int);           //parameterized constructor for class 
                      
                      Price operator +(Price &);         // + operator overloading function
                          
                      void Print();             // function prototype for printing price on screen
                     
        };              // class body ends here
        // definition for default constructor of class
        Price::Price()
        {
                      rupees = 0;
                      paisas = 0;
        }
        // definition for parameterized constructor of class
        Price::Price(int r, int p)
        {
                         if(p >= 100)   // condition to check if value of member paisa is great than 100 or not
                         {
                              paisas = p % 100;           // this will convert paisas into rupees if paisas are greater than 100
                              rupees = r + (p/100);       // if value of paisa is 100 or more then increment value of rupee by 1
                         }                
                         else
                         {
                              rupees = r;
                              paisas = p;
                         }                                   
        }
        // Function definition for overloading + operator 
        Price Price::operator + (Price &p)
        {
              Price temp;       // declaring a temporary variable for strong the result of addition
             
              temp.rupees = rupees + p.rupees;     // adding rupees value of both Price object in the rupees value of temporary object of Price       
             
              temp.paisas = paisas + p.paisas;     // adding paisas value of both Price objects in the paisas value of temporary object of Price
             
              if(temp.paisas >=100)                // checking if value of paisas after addition is greater than 100 or not
              {
                            
                             temp.rupees = temp.rupees + temp.paisas / 100;  // these statements below will convert paisas into rupees if value of paisas is greater than hundred
                             temp.paisas = temp.paisas % 100;                    
             
              }  
             
              cout<<"After Addition: "<<endl<<endl;    
             
              return temp;                              // returning the temporary object of type Price back to the calling function.
        }               
        // function definition to display the information about object on screen.
        void Price::Print()
        {
             cout<<"Price is "<<rupees <<" rupees and "<<paisas <<" paisas";    // statament to print price information on screen
             cout<<endl<<endl;   
        }
        // definition of main() function starts here
        main()
        {
              // declaring and initializing three objects of 'Price'
             
              Price P1(15, 80), P2(12, 50);        // parameterized constructor will be called here
             
              // default constructor Price object will be called here
              Price P3;       
             
              // displaying the information about the objects on the screen
              P1.Print();
              P2.Print();
             
              P3 = P1 + P2; // statement for calling overloading function for '+' operator     
             
              P3.Print();   // displaying information on the screen
              system("pause");    // function to halt the display screen
        }



        You are required to write a program which will calculate the salary of an employee according to his/her grade assigned by the employer. You must declare a class named CalSalary whose private data members will be employee ID, employee name and employee grade. Also write a constructor, setter and getter functions for all private data members and a function that will calculate the salary.


        Detailed Description:

        • Employee ID and grade should be of type integer. Employee name should be of type string.

        • Constructor should initialize employee ID and grade with value zero and employee name with value NULL.

        • For assigning or extracting values from private data members, you must use getter and setter functions.

        • Declare a public member function named calculate which will calculate the net salary of the employee according to his/her grade.

        • Formula for calculating actual salary is (Basic Salary) + 45% of basic salary.

        • If the grade of employee is 17, then the basic salary is 15,000.

        • If the grade is 18, then the basic salary is 20,000 and if grade is 19 then the basic salary is 25,000.




        Sample Output 1



        Please enter employee ID : 001

        Please enter employee name : Mohammad Ali

        Please enter employee grade : 17



        The net salary of Mohammad Ali is 21750







        Sample Output 2



        Please enter employee ID : 2

        Please enter employee name : Aslam Khan

        Please enter employee grade : 19



        The net salary of Aslam Khan is 36250



        Answer

        #include <iostream.h>   
        #include <cstring>
        #include <conio.h>
        //Class will calculate salary of an employee according to his grade
        class CalSalary{ 
            private:
                char name[30];          // character string for storing employee name
                int empID;              // employee's ID
                int grade;              // empoyee's grade 
           
            public:
                CalSalary();                // default constructor
               
                //getter methods for all private data members of class
                int getID();
                int getGrade();
                char* getName();
               
                //setter methods for all private data members of class
                void setName(char[]);
                void setID(int);
                void setGrade(int);
               
                //This function will calculate salary of employee on basis of his grade
                void calculate();
        };

          //Definition of default constructor which initializes employee name with Null and id and grade with zero
          CalSalary::CalSalary()
              {
                  strcpy(name, "");
                  empID = 0;
                  grade = 0;
                 
              }   

           int CalSalary::getID()  // Getter method for private member ID
              {
                  return empID;    // returning employee's ID
              
              }
           int CalSalary::getGrade()  // getter mehtod for private member Grade
              {
                  return grade;     // returning employee's grade
              
              }

            char* CalSalary::getName()  // getter mehtod for private member Name
              {
                  return name;     // returning employee's name
              
              }
           void CalSalary::setID(int id)   // setter method for private member ID
              {
                  empID = id;      // Setting id equal to the parameter given to setID()
              
              }

           void CalSalary::setGrade(int GRADE)    // Setter method for grade
              {
                  grade = GRADE;       // Setting grade equal to the parameter given to setGrade()
              
              }
           void CalSalary::setName(char NAME[])   // Setter method for private member name, taking a character array as argument
              {
                  strcpy (name, NAME);    // strcpy function is used to copy the character array in parameter to the private member name
              
              }
          
         
         
           void CalSalary::calculate()  // This function will calculate employee's salary
              {
                  int basic = 0;   // This variable represents basic salary of employee
                 
                  if(grade == 17)  // If employee's grade is 17 then setting basic salary = 15000
                    {
                      basic = 15000;
                    }       
                  if(grade == 18)  // If employee's grade is 18 then setting basic salary = 20000
                    {
                      basic = 20000;
                    }       
                  if(grade == 19)  // If employee's grade is 19 then setting basic salary = 25000
                    {
                      basic = 25000;
                    }       
              
             
              // Salary is calculated as basic salary + ( 45% of basic salary)
              cout << endl << "Net salary of " << getName() << " is Rs." << (basic + (basic * 45 / 100));
            }


        int main()
         {
           CalSalary obj1;  // creating an object of class CalSalary
           int Grade, id;
           char Name[30];       
            // Taking input from user for employee ID
            cout << "Please enter employee ID : ";
            cin >> id;
           
            cin.ignore();
            /* cin.ignor function is used here because when user enters value of ID and presses enter,
             the following statements like gets(Name) will consider the Enter character as input for character string Name
              and will by-pass these lines of code. cin.ignor() function will ignor the enter character so that
               user may enter his/her desired value of employee's name */

            cout << "Please enter employee name : ";  //Taking input from user for employee's Name
            gets(Name);
         
            cout << "Please enter employee grade : "; // Taking input from user for employee's Grade
            cin >> Grade;
         
               while(Grade<17 || Grade>19)   //Here we are putting a check on user's input for grade, which must be 17 - 19
                 {
                  cout << "Please enter employee grade again (between 17 - 19) : ";
                  cin >> Grade;
                 }
         
        // Using setter functions for setting the employee's name, Id and grade equal to user's input
           obj1.setName(Name); 
           obj1.setID(id);
           obj1.setGrade(Grade);
         
           obj1.calculate();  // calculating salary of employee and displaying on console
         
           getch();
         }