Tuesday, 17 May 2016

Sub Queries MCQ


  1. The SQL _______ Query is used to delete the existing records from a table.

  2.         DELETE
            REMOVE
            DELETIT

  3. Subqueries that return more than one row can only be used with multiple value operators, such as the IN operator.
    state True or False:

  4.         True
            False

  5. Which one of the following sorts rows in SQL?

  6.         SORT BY
            ALIGN BY
            ORDER BY
            GROUP BY

  7. We can test for the nonexistence of tuples in a subquery by using the _____ construct.

  8.         EXISTS
            NOT EXISTS
  9. Subquery is usually added in the WHERE Clause of the SQL statement.
    state True or False:

            True
            False

Thursday, 14 April 2016

SQL MCQ Questions

  1. Which of the following creates temporary relation for the query on which it is defined ?
  2.         With
            From
            Where
            Select
  3. The EXISTS keyword will be true if:
  4.         Any row in the subquery meets the condition only.
            All rows in the subquery fail the condition only.
            Both of these two conditions are met.
            Neither of these two conditions is met.
  5. Which of the following relational algebra operations do not require the participating tables to be union-compatible?
  6.         Union
            Insertion
            Difference
            Join
  7. Which of the following operations need the participating relations to be union compatible?
  8.         Union
            Insertion
            Difference
            All the above
  9. Select name from instructor where salary <=100000 and salary >=90000;
    This query can be replaced by which of the following ?
  10.         Select name from instructor where salary between 90000 and 100000;
            Select name from employee where salary <= 90000 and salary>=100000;
            Select name from employee where salary between 90000 and 100000;
            Select name from instructor where salary between 100000 and 90000;
  11. Select __________
    from instructor
    where dept name= ’Comp. Sci.’;
    Which of the following should be used to find the mean of the salary ?
  12.         Mean(salary)
            Count(salary)
            Avg(salary)
            Sum(salary)
  13. Aggregate functions are functions that take a ___________ as input and return a single value
  14.         Collection of values
            Single value
            Aggregate value
            Both a & b

Saturday, 19 March 2016

DBMS Questions


  1. A table is the primary unit of physical storage of data in a database.State True or False.
  2.         True
            False

  3. Which one of the following is a large database from which information can be extracted and analyzed?
  4.         Database
           Sysbase
           Datawarebase
           DBMS

  5. Which one of the following data model resembles like a tree structure?
  6.         Network model
            Database model
            Relational model
            Hierarchical model

  7. Which of the given option is true regarding the database?
  8.         Data Sharing
            Data concurrency
            All the listed options
            Data Integrity
            Data security

  9. DBMS can replace a file processing system. State True or False.
            True
            False

  10. What is the advantage of minimizing the data redundancy?
            Avoid inaccuracies and inconsistencies in the data
            Save Time in processing the data
            All the above
  11.        To free up the storage space

  12. Which of the following are the types of data models
            All of the listed option
            Network Model
            Hierarchial Model
            Relational Model

  13. Database system is used to restrict the user from unauthorized access.State True or False
            True
            False

  14. Which one of the following is true about RDBMS?
      1. It has relations data integrity
      2. It can maintain many users at the same time
      3. It doesn’t support client/server based application
      4. It is a relational database system
      5. It cant maintain many user at the same time.
            1,3
            2,4
            3,4,5
            1,2,4
            4,5

  15. What is the main component of DBMS?
            Data Modelling
            Data Dictionary
            OLAP Database
            Data Sharing

  16. In which form does the data gets stored in the database?
            Electronic form
            Rich text form
            Non Electronic form
            None of the listed options

  17. Which of the given term refers to Data about the data?
            Data Abstraction
            Views
            Metadata
            Program

  18. DBMS controls redundancy.State True or False.
            False
            True

  19. DBMS helps us to?
      1. Define Schemas and Subschemas in a database and establish relationships between different data elements
      2. Enter Data Into Database
      3. Manipulate and Process Data
      4. None of the listed options
            1&2
            1&3
            4
            1&2&3

  20. The traditional storage of data which is organized by the customers by storing it in separate folders. This is the example of which type of database system?
            Object oriented
            Hierarchical
            Relational
            Network

  21. Arena is married to Vasu and she has a unique SSN. This is an example of a (an):
            Unary Relationship
            Binary Relationship
            Hierarchical Relationship
            Ternary Relationship

  22. In DBMS, what will be the outcome when we map a multivalued attribute for any entity from the ER model to the relational model?
            None of the above
            Many relations, one for each of the distinct values of the attribute
            A column in the relation that represents the entity E
            One relation that contains a foreign key and a column for the attribute

  23. The efficient performance of the database is based on which of the following factors?
      1. Database Design
      2. Application Design
      3. Network Speed
      4. None of the listed option
           1,2,3
            1,3
            1,2
            4

  24. There are two tables Customers and Orders. The customers table would include information about the names , addresses and phone numbers of customers, the order table would include information about the products ordered , the customers,order dates and sales prices ,the Sales manager wants to view only the number of orders placed by each customer on a given date, A Finance Manager in the same company can group the table entries to view only the names and addresses of customers with pending payments.This Grouping of data is possible in?
           Hierarchical Database
            Relational Databse
            Network Database
            Object Oriented Database

Note: If any of the answer is wrong please post a comment. I will update it.

Decipher my Ciphertext


In the language of cryptography, ciphertext refers to a message encoded with a particular key. Plaintext refers to the original, unencoded text. In this problem, both the ciphertext and the key are simply strings of upper-case characters. The ciphertext is generated from the plaintext by “adding” corresponding characters of the plaintext and the key together. If the plaintext is shorter than the key, only some of the key will be used. Similarly, if the plaintext is shorter than the key, the key will be used multiple times.

For example, to encode the plaintext “HELLO” with the key “CAT”:
Plaintext: HELLO
Key: CATCA
Ciphertext: KFFOP

And to encode the plaintext “DOG” with the key “FIDO”:
Plaintext: DOG
Key: FID
Ciphertext: JXK

To add two letters together, use the following convention: A=1, B=2, …, Z=26. If the sum of two letters is greater than 26, subtract 26 from the sum. For example: A + E = 1 + 5 = 6 = F, and D + X = 4 + 24 = 28 = 2 = B.

Given a ciphertext/key pair, determine the corresponding plaintext.

Input Format :
Input will consist of pairs of lines, with the first line being the ciphertext and the second line being the key. Both will consist of only uppercase letters.
Output Format:
For each ciphertext/key pair, print the corresponding plaintext message.

Example:
Sample Input:
HELLO
CAT

Sample Output:
KFFOP

Code:
  #include<stdio.h>
#include<string.h>
int main()
{
  char p[50]={0},key[50]={0};
    int x=0;
  char c[50]={0};
  int i,l1,l2;
  scanf("%s",p);
  scanf("%s",key);
  l1=strlen(p);
  l2=strlen(key);
  if(l1<=l2)
  {
    goto END;
  }
  else if(l1>l2)
  {
    for(i=l2;i<l1;i++)
    {
      key[i]=key[x];
      x++;
    }
    //printf("\n%s",key);
    goto END;
  } 
  END:
  for(i=0;i<l1;i++)
  {
    p[i]=(int)p[i]-64;
    key[i]=(int)key[i]-64;
    c[i]=p[i]+key[i];
    if(c[i]>26)
      c[i]=c[i]-26;
    c[i]=c[i]+64;
    printf("%c",c[i]);
  }
  return 0;
}
    
  

Fibonacci Roots


The first two terms in the Fibonacci sequence are 0 and 1, respectively, and each subsequent term is the sum of the previous two. Using this definition to calculate the first several terms in the sequence, we get

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Let us define the Fibonacci roots of a positive integer n to be the two smallest consecutive Fibonacci numbers whose sum is greater than or equal to n.

Input Format: 
Input consists of a single integer which corresponds to n.
Assumption: 
Assume that n is less than or equal to 2000.
Output Format: 
Output consists of integers, separated by a space.
Sample Input 1 : 
31
Sample Output 1: 
13 21
Sample Input 2 : 
89
Sample Output 2: 
34 55

Code:
  #include<stdio.h>
int main(){
  int a=0,b=1,c=0,n;
  scanf("%d",&n);
  while(1){
    c=a+b;
    if(c>=n)
      goto END;
    a=b;
    b=c;
  }
  END: printf("%d %d",a,b);
  return 0;
}

Vowel or Consonant


Write a program to determine whether the input character is a vowel or consonant.

Input and Output Format: 
Input consists of a single character. Output consists of a string --- “Vowel” / “Consonant” / “Not an alphabet”
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output 1: 
Enter a character
a
Vowel
Sample Input and Output 2: 
Enter a character
Z
Consonant

Sample Input and Output 3: 
Enter a character
#
Not an alphabet

Code:
  #include<stdio.h>
int main(){
  char in;
  char arr[11]={'a','e','i','o','u','A','E','O','U','I'};
    int i,flag=0,con=0;
  printf("Enter a character\n");
  scanf("%c",&in);
  if(((in>='a') && (in<='z'))||((in>='A')&&(in<='Z')))
  {
    for(i=0;i<10;i++)
    {
      if(in==arr[i]){
        flag++;
        break;
      }
      else
        con++;
    }
  }
  else 
    printf("Not an alphabet\n");
  
  if(con)
    printf("Consonant");
  if(flag)
    printf("Vowel");

  
  
  return 0;
}

Anagrams


Write a program to find whether the 2 given strings are anagrams or not. Anagrams are words or phrases made by mixing up the letters of other words or phrases,

Input and Output Format: 
Input consists of 2 string. Assume that all characters in the string are lowercase letters or spaces and the maximum length of the string is 100.
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output 1: 
Enter the first string
anitha
Enter the second string
amphisoft
anitha and amphisoft are not anagrams

Sample Input and Output 2: 
Enter the first string
the eyes
Enter the second string
they see the eyes and they see are anagrams

Code:
  #include<stdio.h>
#include<string.h>
int main(){
  char s1[200],s2[200];
  int first[26]={0},second[26]={0},c=0,i,flag=0;
    //int l,l1;
  printf("Enter the first string\n");
  gets(s1);
  printf("Enter the second string\n");
  gets(s2);
  
    while(s1[c]!='\0')
    {
      first[s1[c]-'a']++;
      c++;
    }
    c=0;
    while(s2[c]!='\0')
    {
      second[s2[c]-'a']++;
      c++;
    }
    for(i=0;i<26;i++){
      if(first[i]!=second[i])
        flag=1;
    }
      
  if(flag==0)
    printf("%s and %s are anagrams",s1,s2);
  else
    printf("%s and %s are not anagrams",s1,s2);
  
  return 0;
}