Beruflich Dokumente
Kultur Dokumente
1.Write a program in C++ for matrix multiplication. The program should accept the dimensions of both the matrices to be multiplied and check for compatibility with appropriate messages and give the output. A:
#include<stdio.h> #include<conio.h> #include<malloc.h> void main() { int row_size1,col_size1,row_size2,col_size2; int **A,**B,**C; int i,j,e; printf("Enter the number of rows and columns in the first matrix:"); scanf("%d %d",&row_size1,&col_size1); printf("Enter the number of rows and columns in the second matrix:"); scanf("%d %d",&row_size2,&col_size2); A=(int**)malloc(row_size1*sizeof(int*)); for(i=0;i<col_size1;i++) { A[i]=(int*)malloc(col_size1*sizeof(int)); } B=(int**)malloc(row_size2*sizeof(int*)); for(i=0;i<col_size2;i++) { B[i]=(int*)malloc(col_size2*sizeof(int)); } C=(int**)malloc(row_size1*sizeof(int*)); for(i=0;i<col_size2;i++) { C[i]=(int*)malloc(col_size2*sizeof(int)); } if(col_size1!=row_size2) { printf("The matrices are not conformable "); }
else { printf("Enter the elements of the first matrix:"); for(i=0;i<row_size1;i++) for(j=0;j<col_size1;j++) scanf("%d",&A[i][j]); printf("Enter the elements of the second matrix:"); for(i=0;i<row_size2;i++) for(j=0;j<col_size2;j++) scanf("%d",&B[i][j]); for(i=0;i<row_size1;i++) { for(j=0;i<col_size2;j++) { C[i][j]=0; for(e=0;e<row_size2;e++) { C[i][j]=C[i][j]+(A[i][e]*B[e][j]); } } } printf("The required matrix is"); for(i=0;i<row_size1;i++) { for(j=0;j<col_size2;j++) printf("%d ",C[i][j]); printf("\n"); } }
2.Write a program to check whether a string is a palindrome or not. Please note that palindrome is one which remains the same if you reverse the characters in the string. For example MADAM. A:
#include <iostream> #include <string> using namespace std; int main() { char str[100]; cout << "Enter word :"; cin >> str; int x = strlen(str)-1; for(int i = 0; i <= x; i++)
{ if (str[i] == str[x-i]) { continue; } else { cout<<"Not a palidrome"<<endl; return 0; } } cout << "Indeed Palidrome"<<endl; return 0; }
3.What is structure in C++? Define a structure named product with elements productcode, description, unitprice and qtyinhand. Write a C++ program that implements the structure and enables to store atleast 100 product data.
A : A structure is a collection of variables under a single name. Variables can be of any type: int,
float, char etc. The main difference between structure and array is that arrays are collections of the same data type and structure is a collection of variables under a single name. Declaring a Structure: The structure is declared by using the keyword struct followed by structure name, also called a tag. Then the structure members (variables) are defined with their type and variable names inside the open and close braces "{"and "}". Finally, the closed braces end with a semicolon denoted as ";" following the statement. The above structure declaration is also called a Structure Specifier. #include <iostream>
int main() {
struct students { char name[10]; //name of student int SSN; // social security number char cardtype[10]; float balance; } for ( i = 0; i <= 10; i++ ) { std::cout << "Enter student name\n"; std::cin >> name[ i ]; std::cout << "Enter social security number\n"; std::cin >> SSN;
4. What is the purpose of exception handling? How do you infer from the phrase, Throwing an exception?
recognizing when a process has failed to the point where it cannot be economically handled by the software portion of the process.
Throwing an Exception
If you encounter an exceptional situation in your code that is, one where you dont have enough information in the current context to decide what to do you can send information about the error into a larger context by creating an object containing that information and throwing it out of your current context. This is called throwing an exception. Heres what it looks like: throw myerror(something bad happened); myerror is an ordinary class, which takes a char* as its argument. You can use any type when you throw (including built-in types), but often youll use special types created just for throwing exceptions. The keyword throw causes a number of relatively magical things to happen. First it creates an object that isnt there under normal program execution, and of course the constructor is called for that object. Then the object is, in effect, returned from the function, even though that object type isnt normally what the function is designed to return. A simplistic way to think about exception handling is as an alternate return mechanism, although you get into trouble if you take the analogy too far you can also exit from ordinary scopes by throwing an exception. But a value is returned, and the function or scope exits. Any similarity to function returns ends there because where you return to is someplace completely different than for a normal function call. (You end up in an appropriate exception handler that may be miles away from where the exception was thrown.) In addition, only objects that were successfully created at the time of the exception are destroyed (unlike a normal function return that assumes all the objects in the scope must be destroyed). Of course, the exception object itself is also properly cleaned up at the appropriate point. In addition, you can throw as many different types of objects as you want. Typically, youll throw a different type for each different type of error. The idea is to store the information in the object and the type of object, so someone in the bigger context can figure out what to do with your exception.
(Book ID: B0681 & B0715) Assignment Set 2 (40 Marks) 1.Write a program which accepts a number from the user and generates prime numbers till that number A:
#include <stdio.h> Void main() { int no,counter,counter1,check; clrscr(); printf(<PRIME NO. SERIES>); printf(\n\n\n\t\t\tINPUT THE VALUE OF N: ); scanf(%d,&no); printf(\n\nTHE PRIME NO. SERIES B/W 1 TO %d : \n\n,no); for(counter = 1; counter <= no; counter++) { check = 0; //THIS LOOP WILL CHECK A NO TO BE PRIME NO. OR NOT. for(counter1 = counter-1; counter1 > 1 ; counter1) if(counter%counter1 == 0) { check++; // INCREMENT CHECK IF NO. IS NOT A PRIME NO. break; } if(check == 0) printf(%d\t,counter); } getch(); }
2.Implement a class stack which simulates the operations of the stack allowing LIFO operations. Also implement push and pop operations for the stack. A:
#include #include void push(int st[],int data,int &top); void disp(int st[],int &top); int pop(int st[],int &top); int flg=0; int top=-1,tos=-1; int st[50]; void push(int st[],int data,int &top) { if(top==50-1) flg=0; else {
flg=1; top++; st[top]=data; } } int pop(int st[],int &top) { int pe; if(top==-1) { pe=0; flg=0; } else { flg=1; pe=st[top]; top--; } return(pe);
} void disp(int st[],int &top) { int i; if(top==-1) { printf("\nStack is Empty"); } else { for(i=top;i>=0;i--) printf("\t%d",st[i]); } } void main() { int dt,opt; int q=0; clrscr(); printf("This Program Is Used to Perform PUSH & POP operations On Stack"); printf("\n\n\tMain Menu........."); printf("\n\n1.Push"); printf("\n\n2.Pop"); printf("\n\n3.Exit"); do { printf("\n\n\tEnter Your Choice 1-3:"); scanf("%d",&opt); switch(opt) { case 1: printf("\nEnter the Element to be Push:"); scanf("%d",&dt);
push(st,dt,tos); if(flg==1) { printf("\nAfter Inserting the Element, Stack is:\n\n"); disp(st,tos); if(tos==50-1)
else printf("\nStack Overflow Insertion Not Possible"); break; case 2: dt=pop(st,tos); if(flg==1) { printf("\n\tData Deleted From the Stack is:%d\n",dt); printf("\n\tAfter Deleting the Element from the stack is:\n\n"); disp(st,tos); } else printf("\nStack Empty,Deletio Not Possible:"); break; case 3: q=1; break; default:printf("\nWrong Choice Enter 1-3 Only"); } }while(q!=1); }
OUTPUT Main Menu......... 1.push 2.pop 3.exit Enter your choice 1-3:1 Enter the element to be push:4 After inserting the elements,stack is: 4 Enter your choice 1-3:1 Enter the element to be push:7 After inserting the elements,stack is: 74 Enter your choice 1-3:1 Enter the element to be push:4
3. What are allocators? Describe the sequence container adapters. A : Allocators are one of the most mysterious parts of the C++ Standard library. Allocators are rarely
used explicitly; the Standard doesn't make it clear when they should ever be used. Today's allocators are substantially different from those in the original STL proposal, and there were two other designs in between all of which relied on language features that, until recently, were available on few compilers. The Standard appears to make promises about allocator functionality with one hand and then take those promises away with the other. The most important fact about allocators is that they were intended for one purpose only: encapsulating the low-level details of STL containers' memory management. You shouldn't invoke allocator member functions in your own code, unless you're writing an STL container yourself. You shouldn't try to use allocators to implement operator new[]; that's not what they're for. If you aren't sure whether you need to use allocators, then you don't. An allocator is a class with member functions allocate and deallocate, the rough equivalents of malloc and free. It also has helper functions for manipulating the memory that it allocated and typedefs that describe how to refer to the memory names for pointer and reference types. If an STL container allocates all of its memory through a user-provided allocator (which the predefined STL containers all do; each of them has a template parameter that defaults tostd::allocator), you can control its memory management by providing your own allocator.
Sequence Adapters
The vector, list, and sequences cannot be built from each other without loss of efficiency. On the other hand, stacks queue can be elegantly and efficiently implemented using those three basic sequences. Therefore, stack and queue are defined not as separate containers, but as adaptors of basic containers. A container adapter provides a restricted interface to a container. In particular, adapters do not provide iterators; they are intended to be used only through their specialized interfaces. The techniques used to create a container adapter from a container are generally useful for nonintrusively adapting the interface of a class to the needs of its users.
4. Write about the following with the help of suitable programming examples: A) Throwing an Exception B) Catching an Exception A: A) Throwing an Exception
If you encounter an exceptional situation in your code that is, one where you dont have enough information in the current context to decide what to do you can send information about the error into a larger context by creating an object containing that information and throwing it out of your current context. This is called throwing an exception. Heres what it looks like: throw myerror(something bad happened); myerror is an ordinary class, which takes a char* as its argument. You can use any type when you throw (including built-in types), but often youll use special types created just for throwing exceptions. The keyword throw causes a number of relatively magical things to happen. First it creates an object that isnt there under normal program execution, and of course the
constructor is called for that object. Then the object is, in effect, returned from the function, even though that object type isnt normally what the function is designed to return. A simplistic way to think about exception handling is as an alternate return mechanism, although you get into trouble if you take the analogy too far you can also exit from ordinary scopes by throwing an exception. But a value is returned, and the function or scope exits. Any similarity to function returns ends there because where you return to is someplace completely different than for a normal function call. (You end up in an appropriate exception handler that may be miles away from where the exception was thrown.) In addition, only objects that were successfully created at the time of the exception are destroyed (unlike a normal function return that assumes all the objects in the scope must be destroyed). Of course, the exception object itself is also properly cleaned up at the appropriate point. In addition, you can throw as many different types of objects as you want. Typically, youll throw a different type for each different type of error. The idea is to store the information in the object and the type of object, so someone in the bigger context can figure out what to do with your exception.
B) Catching an Exception
To see how an exception is caught, you must first understand the concept of a guarded region. This is a section of code that might produce exceptions and is followed by the code to handle those exceptions.
July 2011 Master of Computer Application (MCA) Semester 2 MC0067 Database Management System (DBMS and Oracle 9i) 4 Credits (Book ID: B0716 & B0717)
Assignment Set 1 (40 Marks)
1. Write about:
A: Linear Search
Linear searching is a way to find if a certain element (number , string , etc. ) is in a specified array. The array can be in any order, or be completely jumbled and this search will find the element if it is there. If the element is found we can return the index where the element is located in the array. If the element is not found we can return -1. We can assume no array will ever have an negative number as an index. Our approach will be to check every element in the array to see if it is what we are looking for. We will use a loop to cycle through the array. Here goes:
int findElement(int yourArray[], int tobefound, int length)// method to find index of specified element { int notfound = -1; int counter; for( counter = 0; counter<length; counter++ ) { if(tobefound == yourArray[counter])//check if we found the number we are looking for { return counter; } }//end for loop //if we got this far we must not have found the number return notfound; }
Collision Chain
In computer science, a hash table or hash map is a data structure that uses a hash function to map identifying values, known as keys (e.g., a person's name), to their associated values (e.g., their telephone number). Thus, a hash table implements an associate array. The hash function is used to transform the key into the index (the hash) of an array element (the slot or bucket )where the corresponding value is to be sought. Ideally, the hash function should map each possible key to a unique slot index, but this ideal is rarely achievable in practice (unless the hash keys are fixed; i.e. new entries are never added tothe table after it is created). Instead, most hash table designs assume that hast collisionsdifferent keys that map to the same hash valuewill occur and must be accommodated in some way.
2. Write about:
Collision Chain
A:
Integrity Rules
These are the rules which a relational database follows in order to stay accurate and accessible.These rules govern which operations can be performed on the data and on the structure of thedatabase. There are three integrity rules defined for a relational databse,which are:-
Distinct Rows in a Table - this rule says that all the rows of a table should be distinct toavoid in ambiguity while accessing the rows of that table. Most of the modern databasemanagement systems can be configured to avoid duplicate rows.
Entity Integrity (APrimary Key or part of it cannot be null) - this rule says that 'null'is special value in a relational database and it doesn't mean blank or zero. It means theunavailability of data and hence a 'null' primary key would not be a complete identifier.This integrity rule is also termed as entity integirty.
Referential Integrity - this rule says that if a foreign key is defined on a table then avalue matching that foreign key value must exist as th e primary key of a row in someother table. The following are the integrity rules to be satisfied by any relation. No Component of the Primary Key can be null. The Database must not contain any unmatched Foreign Key values. This is called thereferential integrity rule. Unlike the case of Primary Keys, there is no integrity rule saying that no component of the foreign key can be null.
which appear in the first BUT NOT in the second. Product .The product of two tables is a third which contains all of the records in the first one added to each of the records in the second Intersection. The intersection of two tables is a third tables which contains the records which are common to both Join. The join of two tables is a third which contains all of the records in the first and the second which are related. Divide. Dividing a table by another table gives all the records in the first which have values in their fields matching ALL the records in the second. The eight relational algebra operators are. 1.SELECT To retrieve specific tuples/rows from a relation. 2.PROJECT To retrieve specific attributes/columns from a relation. 3.PRODUCT To obtain all possible combination of tuples from two relations. 4.UNION To retrieve tuples appearing in either or both the relations participating in the UNION. 5.INTERSECT To retrieve tuples appearing in both the relations participating in the INTERSECT. 6.DIFFERENCE To retrieve tuples appearing in the first relation participating in the DIFFERENCE but not the second. 7.JOIN To retrieve combinations of tuples in two relations based on a common field in both the relations.
Linear Search
Linear searching is a way to find if a certain element (number , string , etc. ) is in a specified array. The array can be in any order, or be completely jumbled and this search will find the element if it is there. If the element is found we can return the index where the element is located in the array. If the element is not found we can return -1. We can assume no array will ever have an negative number as an index. Our approach will be to check every element in the array to see if it is what we are looking for. We will use a loop to cycle through the array. Here goes:
int findElement(int yourArray[], int tobefound, int length)// method to find index of specified element { int notfound = -1; int counter; for( counter = 0; counter<length; counter++ ) { if(tobefound == yourArray[counter])//check if we found the number we are looking for { return counter; } }//end for loop //if we got this far we must not have found the number return notfound; }
Collision Chain
In computer science, a hash table or hash map is a data structure that uses a hash function to map identifying values, known as keys (e.g., a person's name), to their associated values (e.g., their telephone number). Thus, a hash table implements an associate array. The hash function is used to transform the key into the index (the hash) of an array
element (the slot or bucket )where the corresponding value is to be sought. Ideally, the hash function should map each possible key to a unique slot index, but this ideal is rarely achievable in practice (unless the hash keys are fixed; i.e. new entries are never added tothe table after it is created). Instead, most hash table designs assume that hast collisionsdifferent keys that map to the same hash valuewill occur and must be accommodated in some way.
3. Discuss the correspondences between the ER model constructs and the relational model constructs. Show how each ER model construct can be mapped to the relational model, and discuss any alternative mappings A : There is almost a one-to-one correspondence between the ER constructs and the relational ones.
The two major distinctions are: In a relational schema, relationships are represented implicitly through primary and foreign keys of participating entities. In a relational schema, columns of relations cannot be multivalued or composite. Composite attributes are replaced with their simple component ones, and multivalued attributes are stored in a separate relation. ER Construct entity 1:1 or 1:N relationship M:N relationship n-ary relationship type simple attribute composite attribute multivalued attribute value set key attribute Mapping Algorithm table Foreign key (or a table to capture the relationship) "relationship" table and 2 foreign keys "relationship" table and 'n' foreign keys column set of simple component columns table and foreign key domain primary (or secondary) key Relational Construct
We can translate an ER schema to a relational schema by following a nine-step algorithm based on the one given in Elmasri and Navathe 1994. The algorithm attempts to minimize the need for joins and NULL values when defining relations (Steps 2, 4, and 5). For each strong entity type E Create a new table. Include as its columns, all the simple attributes and simple components of the composite attributes of E. Identify the primary key and the alternate keys. For each weak entity W that is associated with only one 1:1 identifying owner relationship Identify the table T of the owner entity type. Include as columns of T, all the simple attributes and simple components of the composite attributes of W. For each weak entity W that is associated with a 1:N or M:N identifying relationship, or participates in more than one relationship
Create a new table T. Include as its columns, all the simple attributes and simple components of the composite attributes of W. Form the primary key of T as follows: In the case of a 1:N owner relationship, by including as a foreign key in T, the primary key of the owner entity. The primary key of T is the combination of W's partial key and the foreign key. In the case of an M:N owner relationship, by creating a new column that will hold unique values. (In this case, the association between the weak entity and its owner entity will be specified in Step 6.) For each binary 1:1 relationship type R Identify the tables S and T of the participating entity types. Choose S (preferably the one with total participation). Include as foreign key in S, the primary key of T. Include as Columns of S, all the simple attributes and simple components of the composite attributes of R. For each binary 1:N relationship type R Identify the table S (at the N-side) and T of the participating entities. Include as a foreign key in S, the primary key of T. Include as columns of S, all the simple attributes and simple components of composite attributes of R. For each N-ary relationship (including binary N:M relationship) type R Create a new table T. Include as columns of T, all the simple attributes and simple components of composite attributes of R. Include as foreign keys, the primary keys of the participating (strong or weak) entity types. Specify as the primary key of T, the list of foreign keys. For each multivalued attribute A Create a new table T. Include as columns of T, the simple attribute or simple components of the attribute A. Include as foreign key, the primary key of the entity or relationship type that has A. Specify as the primary key of T, the foreign key and the columns corresponding to A. For each specialization with disjoint subclasses Create a new table Ti for each subclass Si. Include as columns of Ti, the simple attributes and simple component attributes of the superclass. Include as columns of Ti, the simple attributes and simple component attributes specific to Si.
Identify the primary key. For each specialization with overlapping subclasses Create a new table O for the superclass. Include as columns of O, the simple attributes and the simple component attributes of the superclass. Identify its primary key and alternate keys. Create a new table Ti for each subclass Si. Include as columns of Ti, the simple attributes and simple component attributes specific to Si. Include as a foreign key in Ti (to be part of the primary key of Ti), the primary key of O.
4. Define the following terms: disk, disk pack, track, block, cylinder, sector, interblock gap, read/write head. A: Disk:
Disk s are used for storing large amounts of data. The most basic unit of data on the disk is a single bit of information. By magnetizing a area on disk in certain ways, one can make it represent a bit value of either 0 or 1. To code information, bits are grouped into bytes. Byte sizes are typically 4 to 8 bits, depending on the computer and the device. We assume that one character is stored in a single byte, and we use the terms byte and character interchangeably. The capacity of a disk is the number of bytes it can store, which is usually very large. Small floppy disks used with microcomputers typically hold from 400k bytes to 1.5 Mbytes; hard disks for micros typically hold from several hundred Mbytes up to a few G bytes. Whatever their capacity, disks are all made of magnetic material shaped as a thin circular disk and protected by a plastic or acrylic cover. A disk is single-sided if it stores information on only one of its surface and double-sided if both surfaces are used.
Disk Packs:
To increase storage capacity, disks are assembled into a disk pack, which may include many disks and hence many surfaces. A Diskpack is a layered grouping of hard disk platters (circular,rigid discs coated with a magnetic data storage surface). Disk pack is the core component of a hard disk drive. In modern hard disks, the disk pack is permanently sealed inside the drive. In many early hard disks,the disk pack was a removable unit, and would be supplied with a protective canister featuring a lifting handle.
Sector:
A fixed size physical data block on a disk drive. A track usually contains a large amount of information; it is divided into smaller blocks or sectors. The division of a track into sectors is hard-coded on the disk surface and cannot be changed. One type of sector organization calls a portion of a track that subtends a fixed angle at the center as a sector. Several other sector organizations are possible, one of which is to have the sectors subtend smaller angles at the center as one moves away, thus maintaining a uniform density of recording.
Read/write Head:
A tape drive is required to read the data from or to write the data to a tape reel. Usually, each group of bits that forms a byte is stored across the tape, and the bytes themselves are stored consecutively on the tape. A read/write head is used to read or write data on tape. Data records on tape are also stored in blocks-although the blocks may be substantially larger than those for disks, and interblock gaps are also quite large. With typical tape densities of 1600 to 6250 bytes per inch, a typical interblock gap of 0.6 inches corresponds to 960 to 3750 bytes of wasted storage space
1. Explain the purpose of Data Modeling. What are the basic constructs of E-R Diagrams? A:
1.Data modeling
in is the process of creating a data model by applying formal data model descriptions using data modeling techniques. Data modeling is the act of exploring data-oriented structures. Like other modeling artifacts data models can be used for a variety of purposes, from high-level conceptual models to physical data models. Data modeling is the formalization and documentation of existing processes and events that occur during application software design and development. Data modeling techniques and tools capture and translate complex system designs into easily understood representations of the dataflows and processes, creating a blueprint for construction and/or re-engineering.
Relationship:
A relationship captures how two or more entities are related to one another. Relationships can be thought of as verbs, linking two or more nouns. Examples: an owns relationship between a company and a computer, a supervises relationship between an employee and a department, a performs relationship between an artist and a song, a proved relationship between a mathematician and a theorem.
Attributes:
Entities and relationships can both have attributes. Examples: an employee entity might have a Social Security Number (SSN) attribute; the proved relationship may have a date attribute.
2. Write about:
A: