Problem Solving with C++, Student Value Edition
Problem Solving with C++, Student Value Edition
10th Edition
ISBN: 9780134543680
Author: Walter Savitch
Publisher: PEARSON
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 12.2, Problem 13STE

Explanation of Solution

Program:

//Header file

#include <iostream>

//For standard input and output

using namespace std;

//Create namespace "sally"

namespace sally

{

//Function declaration for message()

 void message( );

}

//Create unnamed namespace

namespace

{

 //Function declaration for message()

 void message( );

}

//Main function

int main( )

{

 {

/* Call the message() function for unnamed namespace */

  message( );

/* Call the function message() by "using" directive */

  using sally::message;

  //Call message() function

  message( );

 }

/* Call the message() function for unnamed namespace */

  message( );

 return 0;

}

/* Create function definition of namespace for "message()" function */

namespace sally

{

 /* Function definition for message() */

 void message( )

 {

   /* Display message */

 cout << "Hello from Sally.\n";

 }

}

/* Create function definition of unnamed namespace for "message()" function */

namespace

{

 void message( )

 {

   /* Display message */

 cout << "Hello from unnamed.\n";

 }

}

Explanation:

The given code is used to display the message from “sally” namespace and unnamed namespace...

Blurred answer
Students have asked these similar questions
What is the output of the following C++ code?   #include<iostream> using namespace std; class X { int m; public: X() : m(10) { } X(int mm): m(mm) { } int getm() { return m; } }; class Y : public X { int n; public: Y(int nn) : n(nn) {} int getn() { return n; } }; int main() { Y yobj( 100 ); cout << yobj.getm() << " " << yobj.getn() << endl; }
Can anyone debug this?#include <iostream>using namespace std;class Employee {   public:    string name;    int status;    double salary;    double d_salary;    int days;       void getInfo(){        cout<<"Input the following data: "<<endl;        cout<<"Employee's name: ";        getline(cin,name);        cout<<"Employee's status: ";        cin>>status;               }       void display() {        cout<<endl<<"Employee's Information"<<endl<<endl;        cout << "Employee Name: " << name<<endl;        if (status ==1){            cout << "Employee Status: Regular" <<endl;        else            cout << "Employee Status: Contractual" <<endl;            }     double displaySalary() {        cout << "Annual Salary : " <<salary;     }}; class Regular : public Employee {      public:    double m_salary;        void displayTitle(){        cout<<"Enter the details of the…
What is the output assuming dynamic scoping? #include <iostream> using namespace std;   int total = 5; int c = 3;   int fun1(int); int fun2(int);   int main() { int x = 2; int y = 8; cout << " variables x y and c have values: " << x <<" " << y << " " << c << endl; cout << "main: fun1(x) = " << fun1(x)  << endl; cout << " After Call to fun1(x) variables x y and c have values: " << x <<" " << y << " " << c << endl;   return 0; }   int fun1(int a) {    int b = 6;    int c = 3;       b = total + c + a;    cout << "in fun1: b= " << b << endl;    cout << "in fun 1 after call to fun2(total) the return value is " << fun2(total) << endl;    return (b); } int fun2(int w) {      c = c * 2; total = total + w + c; cout << "in fun2: total= " << total << endl; return(c); }
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education