-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassingObjectAsArgument.cpp
More file actions
38 lines (29 loc) · 951 Bytes
/
PassingObjectAsArgument.cpp
File metadata and controls
38 lines (29 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*Write a short program to implement the concept of passing object as argument, in C++.*/
#include <iostream>
#include <string>
using namespace std;
// Define a simple class called 'Book'
class Book {
public:
// Constructor
Book(string title, string author) : title(title), author(author) {}
// Function to display information about the book
void displayInfo() const {
cout << "Title: " << title << ", Author: " << author << endl;
}
private:
string title;
string author;
};
// Function that takes a 'Book' object as an argument
void printBookInfo(const Book& book) {
cout << "Printing book information from function:" << endl;
book.displayInfo();
}
int main() {
// Create a 'Book' object
Book book1("From Messenger to Forever", "Sayan Banik");
// Call the function passing the 'Book' object as an argument
printBookInfo(book1);
return 0;
}