For this program, you will make use of string functions and namespace. Most of t
ID: 3580842 • Letter: F
Question
For this program, you will make use of string functions and namespace. Most of the program has been done for you, but you need to fill in the bolded parts. (C++)
// This program will define 3 strings; It will make use of various string functions and the concept of namespace.
#include <iostream.h>
#include <stdlib.h>
#include <iomanip.h>
#include <string>
#include <your include file’s full name>
using namespace std;
using namespace name of namespace from the above file;
int main()
{
string first = "", second = "your first name here", third = "your last name here";
string new_string;
int i;
double wage, hours;
// Displaying the string
Display 3 strings in one line
// string length
Display the length of all 3 strings
// put strings together in another variable and print it
Concatenate your first name and last
// empty string
List if the string is empty or not
// use of replace
Use the REPLACE function for second string to say your first initial with your last name
// use of namespace
cout << " What is your hourly wage? ";
cin >> wage;
cout << " How many hours did you work? ";
cin >> hours;
// now call the program from the namespace
Calculate the wage using the program from another file
cout << " Good Bye..." << endl << endl;
system("PAUSE");
return 0;
} // end of main
Explanation / Answer
Answer
#include <iostream.h>
#include <stdlib.h>
#include <iomanip.h>
#include <string>
#include <your include file’s full name>
#include "wage_calculator.cpp"
using namespace std;
using namespace name of namespace from the above file;
int main()
{
string first = "", second = "your first name here", third = "your last name here";
string new_string;
int i;
double wage, hours;
// Displaying the string
cout<<first<<" "<<second<<" "<<third<<" ";
// string length
cout<<strlen(first)<<" "<<strlen(second)<<" "<<strlen(third)<<" ";
// put strings together in another variable and print it
strcpy(new_string, first);
strcat(new_string, second);
strcat(new_string, " ");
strcat(new_string, third);
cout<<new_string<<" ";
// empty string
if(first.empty())
cout<<"The first string is empty ";
else
cout<<"The first string is not empty ";
if(second.empty())
cout<<"The second string is empty ";
else
cout<<"The second string is not empty ";
if(third.empty())
cout<<"The third string is empty ";
else
cout<<"The third string is not empty ";
// use of replace
second.replace(0,strlen(second), "your first initial with your last name");
// use of namespace
cout << " What is your hourly wage? ";
cin >> wage;
cout << " How many hours did you work? ";
cin >> hours;
// now call the program from the namespace
wage(wage, hours);
cout << " Good Bye..." << endl << endl;
system("PAUSE");
return 0;
} // end of main
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.