Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE ANSWER ALL OF THE FOLLOWING QUESTIONS USING CTT PROGRAMMING THANK YOU QUE

ID: 3765852 • Letter: P

Question

PLEASE ANSWER ALL OF THE FOLLOWING QUESTIONS USING CTT PROGRAMMING THANK YOU

QUESTION 1

Consider the class Course { grade = new double;}

                  

Write a destructor for class Course.

10 points   

QUESTION 2

Consider the following class; how many objects have been declared?

class Rectangle

{

double length;double width;

public: double area(double length, double width) {return length * width;}

};

10 points   

QUESTION 3

What is encapsulation in Object Oriented Programming? Give an example.

10 points   

QUESTION 4

What is a function part of a class called?

10 points   

QUESTION 5

In the following code, what is the access specifier of the attribut (data)length?

class Rectangle

{

double length;double width;

public: double area(double length, double width) {return length * width;}

};

10 points   

QUESTION 6

How many objects have been created in this program?

#include<iostream>

using namespace std;

class affair

{

int a;

public: affair() {a++;};

int geta() {return a;};

};

int main()

{

affair a1, a2, a3;

cout << "There are " << a3.geta() << "objects" << endl;

return 0;

}

10 points   

QUESTION 7

What is a destructor?

10 points   

QUESTION 8

1.            How many constructors have been created in this program?

·         #include<iostream>

·         using namespace std;

·         class affair

·         {

·         int a;

·         public: affair() {a++;};

·         int geta() {return a;};

·         };

·         int main()

·         {

·         affair a1, a2, a3;

·         cout << "There are " << a3.geta() << "objects" << endl;

·         return 0;

·         }

10 points   

QUESTION 9

What is a constructor?

10 points   

QUESTION 10

What is the default access specifier of a class?

10 points   

QUESTION 11

What is the difference between the 'Book" structure and the 'Book' class?

struct Book { string title; int publi_year;};

class Book { string title; int publi_year;};

10 points   

QUESTION 12

When/why do you use the scope operator? Explain

Explanation / Answer

question 1   Consider the class Course { grade = new double;}

Now the destructor is

~Course ()

{

grade=new double;

}

Question 3

What is encapsulation in Object Oriented Programming? Give an example.

Encapsulation is an Object Oriented Programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse. Data encapsulation led to the important OOP concept of data hiding.

C++ supports the properties of encapsulation and data hiding through the creation of user-defined types, called classes. We already have studied that a class can contain private, protected and public members. By default, all items defined in a class are private. For example:

The variables length, breadth, and height are private. This means that they can be accessed only by other members of the Box class, and not by any other part of your program. This is one way encapsulation is achieved.

To make parts of a class public (i.e., accessible to other parts of your program), you must declare them after the public keyword. All variables or functions defined after the public specifier are accessible by all other functions in your program.

Making one class a friend of another exposes the implementation details and reduces encapsulation. The ideal is to keep as many of the details of each class hidden from all other classes as possible.

Question 7

What is a destructor?

A destructor is a special member function of a class that is executed whenever an object of it's class goes out of scope or whenever the delete expression is applied to a pointer to the object of that class.

A destructor will have exact same name as the class prefixed with a tilde (~) and it can neither return a value nor can it take any parameters. Destructor can be very useful for releasing resources before coming out of the program like closing files, releasing memories etc.

Following example explains the concept of destructor

Destructors will never have any arguments.

Question 8

#include<iostream>

·         using namespace std;

·         class affair

·         {

·         int a;

·         public: affair() {a++;};

·         int geta() {return a;};

·         };

·         int main()

·         {

·         affair a1, a2, a3;

·         cout << "There are " << a3.geta() << "objects" << endl;

·         return 0;

·         }

Here single constructor is there that is affair().This is explained in the below answers

Question 9

what is a constructor?

A class constructor is a special member function of a class that is executed whenever we create new objects of that class.

A constructor will have exact same name as the class and it does not have any return type at all, not even void. Constructors can be very useful for setting initial values for certain member variables.

Constructors can be defined either inside the class definition or outside class definition using class name and scope resolution :: operator.

Question10

A class can have multiple public, protected, or private labeled sections. Each section remains in effect until either another section label or the closing right brace of the class body is seen. The default access for members and classes is private

The Private members

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 in the following class width is a private member, which means until you label a member, it will be assumed a private member:

When the above code is compiled and executed, it produces the following result:

Question 12

Operator: ‘::’ is known as Scope Resolution Operator. C++ is a block structured language. Different program modules are written in various blocks. Same variable name can be used in different blocks. Scope of a variable extends from the point of declaration to the end of the block. A variable declared inside a block is ‘local’ variable. Blocks in C++ are often nested.

Example

Output of program:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote