Ticker

6/recent/ticker-posts

Class 10 Computer Engineering Object oriented Programming 2073 Solved Question Paper

 

SEE 2073

Group A

1.       What is loop?

àLoop is a programming structure that repeats the sequence of instructions until a specific condition is met.

 

2.       For what purpose default argument are used in C++?*

à The default arguments are used to automatically assign a value for the argument if the caller of the function doesn't provides.

 

3.       What is destructor?

à A destructor is a special function which is invoked automatically whenever an object is going to be destroyed.

 

4.       How would you convert basic type to class type in C++?*

àI would convert basic type to class type by using constructor or using operator overloading.

 

5.       What is file?
à A file is an object on a computer that stores data, information, settings, or commands used with a computer program.

 

Group B

6.       Give an example of character constant and a string constant.*

à

 

7.       How do you add comment in C++ program? Explain.

à I can add comment in C++ program using // (double slash). Comment start with a double slash symbol and terminate at the end of the line. A comment may start anywhere in the line, and whatever follows till the end of the line is ignored. Note that there is no closing symbol. The double slash comment is basically a single line comment. Single line comments can be written as follows:

// This is an example of

 // C++ program to illustrate

 // some of its features

The C comment symbols /*,*/ are still valid and are more suitable for multiline comments. The following comment is multiline comment:

/* This is an example of C++ program to illustrate some of its features */

 

8.       Why don’t good programmer prefer 'goto' statement?

àGood programmer don’t prefer goto statement because it makes difficult to trace the control flow of the program, making the program hard to understand and hard to modify.

 

9.       WAP in C++ to add three integer using function.

à

#include<iostream>

using namespace std;

void add(){

                int a,b,c,s;

                cout<<"Enter the three numbers : ";

                cin>>a>>b>>c;

                s=a+b+c;

                cout<<"The sum of "<<a<< " , "<<b<<" and "<<c<<" is "<<s;

}

int main(){

                add();

                return 0;

}

 

10.   Can you swap the content of two variable using pass by value? Explain with an example.

àYes I can swap the content of two variable using pass by value.

Example:

 #include<iostream>

using namespace std;

void swap(int, int); 

int main() 

    int a, b; 

    cout<<"Enter values for a and b: "; 

                cin>>a>>b;

    cout<<"Before swapping: a ="<<a<<" and b = "<<b; 

    swap(a, b); 

    return 0; 

void swap(int x, int y) 

    int temp; 

    temp = x; 

    x    = y; 

    y    = temp; 

    cout<<"\nAfter swapping: a =" <<x<<" and b = "<<y; 

   

}

Output:

Enter values for a and b:

20

50

Before swapping: a = 20 and b = 50

After swapping: a = 50 and b = 20

 

We ask the user to enter values for variable a and b. We pass the user entered values to swap() function. Since we are passing the values to the function, its called Call by value method.

Values of a and b are copied into local variables of swap() that is x and y. We take a local variable temp inside swap() function. We assign the value of x to temp. Then we assign the value of y to x. And finally we assign the value of temp to y. This swaps the values of variable x and y.

Since swap() method doesn’t return anything, we print the values of x and y inside swap() method itself.

 

11.   Describe the syntax of class constructor in C++.

àSyntax of Default constructor:

                Class_name(){

//constructor body

}

Syntax of Copy constructor:

                Class_name(parameters){

//constructor body

}

Syntax of copy constructor:

                Class_name( class_name &old_object){

//constructor body

}

 

12.   WAP to find area and perimeter of the rectangle.

à

#include<iostream>

using namespace std;

int main(){

                int l,b,a,p;

                cout<<"Enter the length and breadth of the rectangle :";

                cin>>l>>b;

                a=l*b;

                p=2*(l+b);

                cout<<"The area of the rectangle : "<<a<<endl;

                cout<<"The perimter of the rectangle: "<<p;

                return 0;

}

 

13.   How will you initialize an array? Explain with example.

à I will initialize an array using following syntax:

Data_type array_name[size]={element1, element2, …….elementN};

Example: int x[6] = {19, 10, 8, 17, 9, 15};

 

14.   WAP in C++ to compare two strings object using standard string class.

à

#include<iostream>

#include<string.h>

using namespace std;

int main(){

                string s1,s2;

                cout<<"Enter first string:";

                getline(cin,s1);

                cout<<"Enter second string:";

                getline(cin,s2);

               

                int a= s1.compare(s2);

                if(a==0){

                                cout<<"Strings are equal";

                }

                else{

                                if(a<0){

                                                cout<<"First is smaller than second";

                                }

                                else{

                                                cout<<"First is greater than second";

                                }

                }

                                return 0;

}

 

15.   Explain the term 'nameless temporary objects' in the context to operator overloading.*

à

 

16.   If the base class contains the function getdata(), and the derived class doesn’t contain function with this name. Can an object of derive class access the member function getdata()? Explain.

à An object of derive class access the member function getdata() of the base class if the function is  marked with either public or protected access specifier. If the function getdata() is marked with private access specifier, then only the object of base class can access it.

 

17.   What are the input stream and output stream in C++? Explain.

à In C++ input and output is performed in the form of sequence of bytes or more commonly known as streams. The stream in which the direction of flow of bytes is from device (for example: Keyboard) to the main memory is called input stream. The stream in which the direction of flow of bytes is from the main memory to device (for example: Keyboard) is called output stream.

 

18.   Write the declarator for main () that enable command line arguments.*

à

 

Group C

19.   WAP in C++ display the output following pattern.

à

1 2 3 4 5

1 2 3 4

1 2 3

1 2

1

Program:

#include<iostream>

using namespace std;

int main(){

                int i,j;

                for(i=5;i>=1;i--){

                                for(j=1;j<=i;j++)

                                cout<<j<<" ";

                                cout<<endl;

                }

return 0;

}

 

20.   Difference between call by value and call by reference with an example.

à

·         Call By Value:  In this parameter passing method, values of actual parameters are copied to function’s formal parameters and the two types of parameters are stored in different memory locations. So any changes made inside functions are not reflected in actual parameters of the caller. Example:

 #include<iostream>

using namespace std;

void swap(int, int); 

int main() 

    int a, b; 

    cout<<"Enter values for a and b: "; 

                cin>>a>>b;

    cout<<"Before swapping: a ="<<a<<" and b = "<<b; 

    swap(a, b); 

cout<<"\nAfter swapping in main function: a =" <<a<<" and b = "<<b; 

    return 0; 

void swap(int x, int y) 

    int temp; 

    temp = x; 

    x    = y; 

    y    = temp; 

    cout<<"\nAfter swapping in swap function: a =" <<x<<" and b = "<<y; 

   

}

Enter values for a and b: 4 5

Before swapping: a =4 and b = 5

After swapping in swap function: a =5 and b = 4

After swapping in main function: a =4 and b = 5

 

 

·         Call by Reference: in this, both the actual and formal parameters refer to the same locations, so any changes made inside the function are actually reflected in actual parameters of the caller.

Example:

#include<iostream>

using namespace std;

void swap(int &, int &); 

int main() 

    int a, b; 

    cout<<"Enter values for a and b: "; 

                cin>>a>>b;

    cout<<"Before swapping: a ="<<a<<" and b = "<<b; 

    swap(a, b); 

cout<<"\nAfter swapping in main function: a =" <<a<<" and b = "<<b; 

    return 0; 

void swap(int &x, int &y) 

    int temp; 

    temp = x; 

    x    = y; 

    y    = temp; 

    cout<<"\nAfter swapping in swap function: a =" <<x<<" and b = "<<y; 

   

}

Ouput:

Enter values for a and b: 4 5

Before swapping: a =4 and b = 5

After swapping in swap function: a =5 and b = 4

After swapping in main function: a =5 and b = 4

 

 

21.   Explain about default copy constructor in C++ with an example.*

à I think it is same as copy constructor which is already done.

 

22.   WAP in C++ to read a set of numbers into an array and display the largest and smallest element on standard output device.

à

#include<iostream>

using namespace std;

int main(){

                int a[10],n,i,mul=1;

                cout<<"Enter the number of elements:";

                cin>>n;

                cout<<"enter the numbers of array:";

                for(i=0;i<n;i++){

                                cin>>a[i];

                }

 

                for(i=0;i<n;i++){

                 if (a[0] < a[i]) {

                                a[0] = a[i];

    }

}

cout<<"The largest is"<<a[0]<<endl;

for(i=0;i<n;i++){

     if (a[0] > a[i]) {

      a[0] = a[i];

    }

                }

                                cout<<"The smallest  is"<<a[0];

                return 0;

}

 

23.   WAP to overload + operator.

àAlready in concatenating

 

24.   WAP using the single inheritance implementing the following figure.*

à

#include<iostream>

using namespace std;

class School{

                public:

                                void Schoolinfo(){

                                                cout<<"School information\n";

                                }

                                void display(){

                                                cout<<"Display school\n";

                                }

                               

};

class Student : public School{

                public:

                                void Stdinfo(){

                                                cout<<"student information\n";

                                }

                                void display(){

                                                cout<<"Display student\n";

                                }

};

int main(){

                Student obj;

                obj.Schoolinfo();

                obj.display();

                obj.Stdinfo();

               

}

Reactions

Post a Comment

0 Comments