0
0
C++programming~15 mins

Namespace concept and std usage in C++ - Mini Project: Build & Apply

Choose your learning style9 modes available
Namespace concept and std usage
📖 Scenario: Imagine you are organizing a small library of books. You want to keep track of book titles and authors, but you also want to use some common tools from the C++ standard library to help you print and manage data.
🎯 Goal: You will create a simple program that uses a namespace to organize your book data and also use the std namespace to print the information.
📋 What You'll Learn
Create a namespace called library with a variable inside
Create a string variable bookTitle inside the library namespace
Create a string variable author inside the library namespace
Create a using namespace std; statement to use standard library features
Print the book title and author using cout
💡 Why This Matters
🌍 Real World
Namespaces help organize code in large projects to avoid name conflicts, just like organizing books in different shelves.
💼 Career
Understanding namespaces and standard library usage is essential for writing clean, maintainable C++ code in professional software development.
Progress0 / 4 steps
1
Create the library namespace with book data
Create a namespace called library. Inside it, create two string variables: bookTitle with the value "The Little Prince" and author with the value "Antoine de Saint-Exupéry".
C++
Need a hint?

Remember to write namespace library { ... } and declare the variables inside it.

2
Add using namespace std; for easier access
Add the line using namespace std; after the library namespace to allow using standard library features without std:: prefix.
C++
Need a hint?

Write using namespace std; outside the library namespace.

3
Write the main function to print book info
Write a main function. Inside it, use cout to print the book title and author from the library namespace in this format: "Book: The Little Prince, Author: Antoine de Saint-Exupéry".
C++
Need a hint?

Use library::bookTitle and library::author to access the variables inside the namespace.

4
Print the final output
Run the program and print the output line showing the book title and author exactly as: Book: The Little Prince, Author: Antoine de Saint-Exupéry.
C++
Need a hint?

Make sure the output matches exactly, including commas and spaces.