July 2011 Master of Computer Application (MCA) – Semester 2 MC0066 – OOPS using C++ – 4 Credits

(Book ID: B0681 & B0715)

Assignment Set – 1 (40 Marks)
Answer all Questions Book ID: B0681 Each Question carries ten Marks

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. #include<iostream.h> #include<conio.h> #include<process.h> void main() { clrscr(); int a[10][10],b[10][10],p[10][10],r,c,m,n,i,j,s; cout<<"Enter number of rows of first matrix: "; cin>>r; cout<<"Enter number of columns of first matrix: "; cin>>c; cout<<"Enter number of rows of second matrix: "; cin>>m; cout<<"Enter number of columns of second matrix: "; cin>>n; if (c!=m) cout<<"\nMatrices cannot be multiplied", getch(), exit(0); clrscr(); cout<<"Enter elements of first matrix...\n\n"; for (i=0;i<r;i++) for (j=0;j<c;j++) cin>>a[i][j];

i++) for (j=0.i++) { for (j=0. } cout<<"\n".. cout<<"\n".i<m. cout<<"1st matrix.j++) cout<<" "<<a[i][j].s++) p[i][j]+=a[i][s]*b[s][j].j++) cout<<" "<<b[i][j].j<n..j++) cin>>b[i][j].i++) { for (j=0. cout<<" "<<p[i][j].. } getch().i<m.\n". for (i=0.. #include <iostream> #include <string> using namespace std.i<r.j<n. for (i=0. for (i=0. Please note that palindrome is one which remains the same if you reverse the characters in the string.j++) { p[i][j]=0. clrscr(). } cout<<"\nProduct.. For example “MADAM”.i++) { for (j=0. Write a program to check whether a string is a palindrome or not.\n". for (s=0. } cout<<"2nd matrix.j<n. } 2.s<c.\n\n".cout<<"Enter elements of first matrix. int main() { . cout<<"\n".j<c.i<r. for (i=0....\n".

float. cout << "Enter word :". i++) { if (str[i] == str[x-i]) { continue. Three variables: custnum of type int . What is structure in C++? Define a structure named product with elements productcode. return 0. Variables can be of any type: int . cin >> str. } else { cout<<"Not a palidrome"<<endl.char str[100]. } } cout << "Indeed Palidrome"<<endl. Write a C++ program that implements the structure and enables to store atleast 100 product data. return 0. int x = strlen(str)-1. unitprice and qtyinhand.salary of type int. 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. for(int i = 0. commission . i <= x. char etc. Structure is a collection of variables under a single name. 3. description.

}.of type float are structure members and the structure name is Customer. cout <<"Enter year: ". mystr). cout <<"\nYou have entered:\n". cout << pmovie->title. it is seen that variables of different types such as int and float are grouped in a single structure name Customer. This structure is declared as follows: In the above example. pmovie->title). movies_t * pmovie.pmovie = &amovie.cout <<" ("<< pmovie->year <<")\n". After declaring the structure. int main () { string mystr. #include <iostream> #include <string> #include <sstream> using namespacestd. (stringstream) mystr >> pmovie->year. structmovies_t { string title. movies_t amovie.getline (cin. cout <<"Enter title: ". declaring structures does not mean that memory is allocated. Arrays behave in the same way. . the next step is to define a structure variable. getline (cin. int year.

return0. it’s not like a switch statement where you need a break after each case to prevent the remaining ones from executing. although sometimes there is no identifier because it’s not needed in the handler the exception type gives you enough information to deal with it. within the try block. just like a function argument. and so on) may be used inside the handler. This is the exception handler. Notice that. try { // code that may generate exceptions } catch(type1 id1) { // handle exceptions of type1 } catch(type2 id2) { // handle exceptions of type2 } // etc. the Exception handling mechanism goes hunting for the first handler with an argument that matches the type of the exception.) Only the matching catch clause executes.. and there’s one for every exception type you want to catch. Then it enters that catch clause. . the thrown exception must end up someplace. If an exception is thrown. } Structure declaration gives a skeleton or template for the structure. Book ID: B0715 4. a number of different function calls might generate the same exception. but you only . and the exception is considered handled. What is the purpose of exception handling? How do you infer from the phrase. The identifier (id1. Of course. (The search for handlers stops once the catch clause is finished. Each catch clause (exception handler) is like a little function that takes a single argument of one particular type. Exception handlers immediately follow the try block and are denoted by the keyword catch: . “Throwing an exception”?. The handlers must appear directly after the try block. id2.

Write a program which accepts a number from the user and generates prime numbers till that number 2. July 2011 Master of Computer Application (MCA) – Semester 2 MC0066 – OOPS using C++ – 4 Credits (Book ID: B0681 & B0715) Assignment Set – 2 (40 Marks) Answer all Questions Each Question carries ten Marks Book ID: B0681 1. Also implement push and pop operations for the stack. Implement a class stack which simulates the operations of the stack allowing LIFO operations.need one handler. 4. What are allocators? Describe the sequence container adapters. Write about the following with the help of suitable programming examples: A) Throwing an Exception B) Catching an Exception . Book ID: B0715 3.

Sign up to vote on this title
UsefulNot useful