PLEASE ANSWER ALL OF THE QUESTIONS THIS USING CTT PROGRAMMING THANK YOU!!! QUEST
ID: 3765850 • Letter: P
Question
PLEASE ANSWER ALL OF THE QUESTIONS THIS 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
1.
~Course()
{
cout<<"Distructor";
}
2.
3 objects of double type
3.
Data encapsulation is a mechanism of bundling the data, and the functions that use them and data abstraction is a mechanism of exposing only the interfaces and hiding the implementation details from the user.
class Box
{
public:
double getVolume(void)
{
return length * breadth * height;
}
private:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};
4.
functional area
5.
length and width are private
area is public
6.
3 objects have been created.
7.
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.
8.
3 objects have been created.
9.
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.
10.
private
11.
struct Book { string title; int publi_year;};
defination of Book type structure which has string title and int publi_year
class Book { string title; int publi_year;};
defination of Book class which has private type string title and int publi_year
12.
Scope resolution operator(::) is used to define a function outside a class or when we want to use a global variable but also has a local variable with same name.
#include <iostream>
using namespace std;
char c = 'a'; // global variable
int main() {
char c = 'b'; //local variable
cout << "Local variable: " << c << " ";
cout << "Global variable: " << ::c << " "; //using scope resolution operator
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.