Thursday, December 1, 2016

Objective Questions in >= Swift2.2 @iPhone - Set E

Q.41: What will be the output
var temp = 30
if temp >= 34 {
    print("It's Cold")
}
else
{
print("It's Normal")
}
A.      Compile Time Error
B.      It’s Cold
C.      It’s Normal
D.      None

Q.42: What will be the output
let temp = 90
if temp <= 32 {
    print("It's very cold.")
} else if temp >= 86 {
    print("It's really warm.")
} else {
    print("It's Normal")
}
A.      Compile Time Error
B.      It’s very cold
C.      It’s really warm
D.      It’s Normal

Q.43: What will be the output
let char: Character = "B"
switch char {
case "A":
    print("The first letter of the alphabet")
case "B":
    print("The second letter of the alphabet")
case "Z":
    print("The last letter of the alphabet")
default:
    print("Some other character")
}
A.      The first letter of the alphabet
B.      The second letter of the alphabet
C.      The last letter of the alphabet
D.      Some other character

Q.44: What will be the output
let char: Character = "b"
switch char
{
case "b", "B":
    print("The letter is B")
default:
    print("Not B")
}
A.      Compile Time Error
B.      The letter is B
C.      Not B
D.      None of the above

Q.45: Which is not a proper function in Swift
                A. func humtum( name : String ) -> String {   
                      some code      …… 
                      return  “Hello”}
                B. func humtum( name : String ) {   
                      some code      …… 
                      }
                C. func humtum() -> String {   
                      some code      …… 
                      return  “Hello”
      }
                D. humtum( name : String ) -> String {   
                      some code      …… 
                      return  “Hello”}

Q. 46: func humtum( name : String ) -> String {                  
let display = “ Hello “ + name
                      return  display  }
                Which is proper calling statement for given function
A.      HHumtum( name : “Ravi”) 
B.      humtum()
C.      humtum( name : “Godara”)
D.      None

Q.47: func  add ( num1 : Int , num2 : Int ) -> Int
                {
                let ans = num1 + num2;
        return ans;
  }
Which is proper calling statement
A.      add ( num1 : 5 ,num2 : 10)
B.      add (5 , 10)
C.      add ( num1 : 5 ,  10)
D.      None of the above

Q.48:  func  add ( num1 : Int , num2 : Int ) -> Int
                {
                let ans = num1 + num2;
return ans;
       }
print( add ( num1 : 5 ,num2 : 10) )
What will be the output
A.      5
B.      15
C.      10
D.      Compile Time Error

Q.49: class Area
                {
                var  width  = 1 0
                var height  =  15
                }
Which is the proper syntax to create instance of given               class
A.      let object = new Area()
B.      let object = Area()
C.      object = new Area()
D.      None of the Abvove

Q.50: In the example given in Q.49
           Which is the proper syntax to access properties
A.      object->width
B.      object(width)
C.      object.width
D.      None of the above

Answers: C    C    B     B     D      C     A     B     B     C  
      





Tuesday, November 29, 2016

Placement Practice Set - Logical Small Questions

Prime Number:

A prime number that doesn’t have factors. Like  2  3  5  7  11  13   17……
Just see the logic how to check a given number is prime or not
// number is a variable to be checked
// count is a integer variable
// flag is used to check condition initially should be 0
   
  for(count=2; count<=number/2; count++)
    {
        if( number % count = = 0)
        {
            flag = 1;
            break;
        }
    }

    if (flag = = 0)
        printf("prime number");
    else
        printf("not a prime number");

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Factorial of a given number

  A.   Using loop

int main()
{
  int count , fact = 1,num;
  printf("Enter Number: ");
  scanf("%d",&num);
  for(count = 1; count < = num; count++)
  {    
  fact = fact * count;
  }
  printf("Factorial of %d is: %d",num,fact);
  return 0;
}

  B.    Using Recursion  -
           Recursion is function which calls itself , Calling itself 
           stops at a particular condition.
         int fact(int n);   // Function Declaration
         int main()
        {
         int num, result;
         printf("Enter  num: ");
         scanf("%d", &num);
         result = fact(num);      // Function Calling
         printf("Factorial of %d is %d", num, result);
         return 0;
        }
     int fact(int n)                // Function Definition
      {
       if (n <= 0)
       {
          return 1;
       }
      else
      {
          return (n * fact(n - 1));
      }  
 }


Sunday, November 27, 2016

Objective Questions in Swift2.2 @iPhone - Set D

Q.31: What will be the output of
               let a = 10
               var b = 5
               b = a
               print(b)
A.         10
B.         5
C.         Error
D.         None

Q.32: What will be the output
         var  x  = -9 % -4
        print(x)
A.         -1
B.         1
C.         0
D.        Error

Q.33: What will be the output
           let  x = -9
           let y =-x
           print(y)
A.         -9
B.         9
C.         0
D.        Error

Q.34:  What will be the output
   for index in 1…4
  {   
  print(index*5)
 }
A.         5,10,15,20
B.         5
C.         20
D.        None

Q.35: What will be the output
                      let allow = true
                      if !allow
                      {
                      print("Allowed")
                      }
                      else
                      {
                      print("Not Allowed")
              }
A. Allowed
B. Not Allowed
C. Error
D. None


Q.36: What will be the output
                      let yes = true
                      let no = false
                      if yes && no
                      {
                       print("Allowed")
                      }
                      else
                      {
                     print("Not Allowed")
             }
A. Allowed
B. Not Allowed
C. Error
D. None

Q.37: What will be the output
                      let yes = true
                      let no = false
                      if yes || no
                      {
                      print("Allowed")
                      }
                      else
                      {
                     print("Not Allowed")
              }
A. Allowed
B. Not Allowed
C. Error
D. None

Q.38: What will be the output
                   var str  = String()
                   if str.isEmpty
                      {
                      print("Nothing")
                      }
                      else
                      {
                      print("Something")
              }
A. Nothing
B. Something
C. Error
D. None

Q.39: What will be the output
                      for char in "Godara".characters
                      {
                       print(char)
              }
A. Run 5 Times
B. Run 4 Times
C. Run 6 Times
D. Compile Time Error

Q.40: What will be the output
                      let name = "Ravi Godara"
                      print(name[name.startIndex])
A. Compile Time Error
B. a
C. R
D. G


Answers  A   A   B    A   B    B   A    A     C    C