Computer Science With C++ Chapter 2 Object Oriented Programming
  • Sponsor Area

    NCERT Solution For Class 12 Computer And Communication Technology Computer Science With C++

    Object Oriented Programming Here is the CBSE Computer And Communication Technology Chapter 2 for Class 12 students. Summary and detailed explanation of the lesson, including the definitions of difficult words. All of the exercises and questions and answers from the lesson's back end have been completed. NCERT Solutions for Class 12 Computer And Communication Technology Object Oriented Programming Chapter 2 NCERT Solutions for Class 12 Computer And Communication Technology Object Oriented Programming Chapter 2 The following is a summary in Hindi and English for the academic year 2021-2022. You can save these solutions to your computer or use the Class 12 Computer And Communication Technology.

    Question 1
    CBSEENCO12011519

    Differentiate between private and public members of a class in the context of Object Oriented Programming. Also, give a suitable example illustrating accessibility/non-accessibility of each using a class and an object in C++.

    Solution

    A class can have multiple public, protected, or private access modifier.

    A public class of member or function is accessible from anywhere outside the class but within the program. You can set and get the value of public variables without any member function as shown in the given example.
    A private member variable or function cannot be accessed, or even viewed from outside the class. Only the class and friend functions can access private members.By default, all the members of a class would be private, for example.

    classMyClass
    {
        public:int a;
        private:int b;
    };
        int main()
    {
       MyClass obj;
       obj.a =10;//Allowed
       obj.b=30;//Not Allowed, gives compiler error}
    Question 5
    CBSEENCO12011523

    Write the definition of a function Reverse(int Arr[], int N) in C++, which should reverse the entire content of the array Arr having N elements, without using any other array.

    Example: if the array Arr contains

    13 10 15 20 5

    Then the array should become

    5 20 15 10 13

    NOTE:

    • The function should only rearrange the content of the array.
    • The function should not copy the reversed content in another array.
    • The function should not display the content of the array.

    Solution
    void printarray(int arr[], int count)
    {
    	for(int i = 0; i < count; ++i)
    		cout<<arr[i]<<' ';
    	cout<<'\n';
    }
    
    void reverse(int arr[], int count)
    {
    	int temp;
    	for (int i = 0; i < count/2; ++i)
    	{
    		temp = arr[i];
    		arr[i] = arr[count-i-1];
    		arr[count-i-1] = temp;
    	}
    }
     
    int main ()
    {  
    	clrscr();
    	const int SIZE = 10;
    	int arr [SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    	cout<<'Input Array\n';
    	printarray(arr, SIZE);
    	reverse(arr, SIZE);
    	cout<<'Reverse Array\n';
    	printarray(arr, SIZE);
    	getch();
    }
    Question 7
    CBSEENCO12011566

    Differentiate between private and public members of a class in the context of Object Oriented Programming. Also, give a suitable example illustrating accessibility/non-accessibility of each using a class and an object in C++.

    Solution

    A class can have multiple public, protected, or private access modifier.

    A public class of member or function is accessible from anywhere outside the class but within the program. You can set and get the value of public variables without any member function as shown in the given example.

    A private member variable or function cannot be accessed, or even viewed from outside the class. Only the class and friend functions can access private members.By default, all the members of a class would be private, for example.

    classMyClass
    {
    	public:int a;
    	private:int b;
    };
    int main()
    { 
    	MyClass obj;
    obj.a =10;	//Allowed
    obj.b=30;	//Not Allowed, gives compiler error}

    Mock Test Series

    Sponsor Area

    Sponsor Area

    NCERT Book Store

    NCERT Sample Papers

    Entrance Exams Preparation

    39