Concept explainers
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...
Want to see the full answer?
Check out a sample textbook solutionChapter 12 Solutions
Problem Solving with C++ (10th Edition)
- Write in c#arrow_forwardHello, I was making a hangman simulation in C++. The code runs, but not fully. Could you identify the error and fix it? #include<iostream>#include<cstring> // for string class functions#include<fstream>#include <cctype>using namespace std; int main(){// define variable to get the response from user "Yes" or "No"string response;// Define index variableint w = 0;// define number of words that need to be guessed by the user assume 4const int WORDS = 4;// loopdo{// we will define the hangman bodyconst char body[] = "o/|\\|\\";// here we define the wordsstring words[WORDS] = {"MACAW", "SADDLE", "TOASTER", "XENOICIDE"};// fetch size or lengthstring xword(words[w].length(),'*');// define iterator to fetch the wordsstring::iterator i, ix = xword.begin();// define number of words to prompt for the userchar letters[26]={"\0"};// Now we define the variables which will be used in the simulationint n =0, xcount = xword.length();bool found = false, solved = false, hung =…arrow_forwardHello, I was making a hangman simulation in C++. The code runs, but not fully. Could you identify the error and fix it? #include<iostream>#include<cstring> // for string class functions#include<fstream>#include <cctype>using namespace std; int main(){// define variable to get the response from user "Yes" or "No"string response;// Define index variableint w = 0;// define number of words that need to be guessed by the user assume 4const int WORDS = 4;// loopdo{// we will define the hangman bodyconst char body[] = "o/|\\|\\";// here we define the wordsstring words[WORDS] = {"MACAW", "SADDLE", "TOASTER", "XENOICIDE"};// fetch size or lengthstring xword(words[w].length(),'*');// define iterator to fetch the wordsstring::iterator i, ix = xword.begin();// define number of words to prompt for the userchar letters[26]={"\0"};// Now we define the variables which will be used in the simulationint n =0, xcount = xword.length();bool found = false, solved = false, hung =…arrow_forward
- In C++ Find the five errors. For each error, state the line number, explain the error and show a correction. #include<iostream> #include<iomanip> using namespace std; class colorCode { public: void setRGB(int); //accepts an int parameter and sets the RGB to the value of the parameter void setName(string);//accepts a string parameter and sets the name of the object to the value of the parameter string getName() const;//returns the name of the object int getRGB() const;//returns the RGB of the object void changeColor();// adds 10 to the RGB value private: string name; int RGB; } int main() { colorCode paintCans[10]; int i; for (i = 0; i < 10; i++){ paintCans.setRGB[i] = 0;} paintCans[5].setName(GREEN); paintCan[5].setRGB(192000); cout << paintCans[5].getName << ' ' << paintCans[5].getRGB() << endl; return 0; }arrow_forward// // main.c // Assignment1 // // Created by Hassan omer on 15/10/21. // #include <stdio.h> # include <stdlib.h> int input(); int multiples(); int cions(); void display_change(); int main() { int num; num = input(); multiples(num); cions(); display_change(); return 0; } int input(int num) { printf("enter 5-95 number\n"); scanf("%d",&num); return num; } int multiples(int num) { int sum5 =0; if (sum5 %5 != 0 ||sum5<5|| sum5 >95) { printf("invaild input %d",sum5); } cions(sum5); return sum5; } int cions(int sum05){ int cent50 = 0; int cent20 = 0; int cent10 = 0; int cent05 = 0; if (sum05 > 0) { if (sum05 >= 50){ sum05 -= 50; cent50++; } else if (sum05 >=20){ sum05 -= 20; cent20++; } else if (sum05 >= 10){ sum05 -=10;…arrow_forwardPass the first parameter by reference and the second parameter by value. *arrow_forward
- C LANGUAGEA private railway company has just purchased a computer for its new automated reservationssystem. You have been asked to write a program to assign seats on each train of the railway havingonly (capacity: 100 seats). Your program should check whether it is a valid seat number or not.Also print its berth type i.e lower berth, middle berth, upper berth, side lower berth, side upperberth. Furthermore, then print a ticket indicating the person's seat number and whether it’s in the firstclass or economy section of the train. Use a single-subscripted array to represent the seating chartof the train. Initialize all the elements of the array to 0 to indicate that all seats are empty. As eachseat is assigned, set the corresponding element of the array to 1 to indicate that the seat is no longeravailable.arrow_forwardIn this c# program please convert into c++ program. Source Code: using System;namespace BMI{ internal class Program { static void Main(string[] args) { float bmi, m, h, b ; String name; Console.Write("Enter the student name: "); name = Console.ReadLine(); Console.Write("\nEnter the grade level(1-6): "); h = float.Parse(Console.ReadLine()); Console.Write("\nEnter the student Weight(kg): "); m = float.Parse(Console.ReadLine()); Console.Write("\nEnter the height (feet and inches): "); b = float.Parse(Console.ReadLine()); bmi = m / (h * h); Console.WriteLine("\nStudent BMI is: " + bmi); if(bmi < 18.5) { Console.WriteLine("\nStudent is Underweight"); } else if(bmi >= 18.5 && bmi < 25) { Console.WriteLine("\nStudent is…arrow_forwardJVarrow_forward
- c programing languagearrow_forwardhi can you explain these functions to me def encode(message):encode_dict = {'A': '.-', 'B': '-...', 'C': '-.-.','D': '-..', 'E': '.', 'F': '..-.','G': '--.', 'H': '....', 'I': '..','J': '.---', 'K': '-.-', 'L': '.-..','M': '--', 'N': '-.', 'O': '---','P': '.--.', 'Q': '--.-', 'R': '.-.','S': '...', 'T': '-', 'U': '..-','V': '...-', 'W': '.--', 'X': '-..-','Y': '-.--', 'Z': '--..', ' ': '.....'}encoded = ' '.join(encode_dict[i] for i in message.upper())return encodeddef decode(message):encode_dict = {'A': '.-', 'B': '-...', 'C': '-.-.','D': '-..', 'E': '.', 'F': '..-.','G': '--.', 'H': '....', 'I': '..','J': '.---', 'K': '-.-', 'L': '.-..','M': '--', 'N': '-.', 'O': '---','P': '.--.', 'Q': '--.-', 'R': '.-.','S': '...', 'T': '-', 'U': '..-','V': '...-', 'W': '.--', 'X': '-..-','Y': '-.--', 'Z': '--..', ' ': '.....'}decode_dict = {v: k for k, v in encode_dict.items()}decoded = ''.join(decode_dict[i] for i in message.split())return decodeddef process_lines(filename, mode):with…arrow_forwardc++, print the outputarrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,