BookBook that takes title and pagestitle and pages in member variablesprintDetails method to display the book's title and pagesBook object with title "C++ Basics" and pages 250printDetails to show the book informationBookBook that takes title and pagestitle and pages in member variablesprintDetails method to display the book's title and pagesBook object with title "C++ Basics" and pages 250printDetails to show the book informationBook with two private member variables: title of type std::string and pages of type int.Use class Book { private: std::string title; int pages; }; to define the class and variables.
Book class that takes std::string title and int pages as parameters and sets the member variables accordingly.Use Book(std::string title, int pages) { this->title = title; this->pages = pages; } inside the class.
printDetails to the Book class that prints the book's title and number of pages in the format: Title: [title], Pages: [pages].Define void printDetails() { std::cout << "Title: " << title << ", Pages: " << pages << std::endl; }.
main(), create a Book object named myBook using the parameterized constructor with title "C++ Basics" and pages 250. Then call myBook.printDetails() to display the book information.Create the object with Book myBook("C++ Basics", 250); and call myBook.printDetails();.
What is the main purpose of a parameterized constructor in C++?
Which of the following is the correct syntax for a parameterized constructor in C++?
class Box {
public:
Box(int w, int h) { width = w; height = h; }
private:
int width, height;
};What will be the output of this code?
#include <iostream>
class Point {
public:
int x, y;
Point(int a, int b) { x = a; y = b; }
};
int main() {
Point p(3, 4);
std::cout << p.x << ", " << p.y << std::endl;
return 0;
}Identify the error in this code snippet:
#include <iostream>
class Car {
public:
int speed;
Car(int s) { speed = s; }
};
int main() {
Car c;
std::cout << c.speed << std::endl;
return 0;
}Car c; tries to create an object without parameters.Car(int s) exists; no default constructor is defined.Car c; causes a compilation error.Car c; -> Option CGiven this class, how can you create an object r with width 5 and height 10 using the parameterized constructor?
class Rectangle {
public:
int width, height;
Rectangle(int w, int h) { width = w; height = h; }
};Pass the test and this pattern moves unknown