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;
}

Zero Duplicates


Write a program that will read in a list of numbers and will then print out the same list except numbers that have already been printed will be printed as a zero instead.

Input Format: 
Input consists of n+1 integers where n is the number of elements in the list. The first integer corresponds to n. The remaining n integers correspond to the elements in the list. 
Assume that the maximum value of n is 100. 

Output Format: 
Output consists of n integers on separate lines.

Sample Input : 
5
2
3
4
3
6
Sample Output: 
2
3
4
6

Code:
  #include<stdio.h>
int main(){
  int n,a[100],i,c,j;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  
  for(i=0;i<n;i++)
  {
    c=0;
    for(j=0;j<i;j++)
    {
      if(a[i]==a[j]){
        c=1;
        break;
      }
    }
    if(c==1)
      printf("0\n");
    else
      printf("%d\n",a[i]);
  }
  
  return 0;
}

The Next Palindrome


A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K, write the value of the smallest palindrome larger than K to output. 

Input 
The first line contains an integer, which corresponds to K. Assume that K is less than 200000. 

Output
Output consists of a single integer, which corresponds to the smallest palindrome larger than K.

Sample Input 1:
808

Sample Output 1:
818

Sample Input 2:
2133

Sample Output 2:
2222

Code:
  #include<stdio.h>
int main()
{
  long int num,pa=0,rem,temp;
  scanf("%ld",&num);
  while(num!=pa){
    num=num+1;
    temp=num;
    pa=0;
    while(temp!=0){
      rem=temp%10;
      pa=rem+pa*10;
      temp=temp/10;
    }
  }
  printf("%ld",pa);
  return 0;
}