In: Computer Science
a) Given a variable word that has been assigned a string value, write a string expression that parenthesizes the value of word. So, if word contains "sadly", the value of the expression would be the string "(sadly)"
b) Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Write a statement that prints the value of price in the form "X dollars and Y cents" on a line by itself. So, if the value of price was 4321, your code would print "43 dollars and 21 cents". If the value was 501 it would print "5 dollars and 1 cents". If the value was 99 your code would print "0 dollars and 99 cents".
c) Assume that word is a String variable. Write a statement to display the message "Today's Word-Of-The-Day is: " followed by the value of word on a line by itself on standard output.
CODE:
#include
#include
using namespace std;
int main()
{
string word;
cout << "Enter string: ";
cin >> word;
word = "(" + word + ")";
cout << "After parenthesization: " << word
<< endl;
}
OUTPUT:
2. CODE:
#include
#include
using namespace std;
int main()
{
int value;
cout << "Enter value: ";
cin >> value;
int dollars, cents;
dollars = value / 100;
cents = value % 100;
cout << endl << dollars << " dollars
" << cents << " cents" << endl;
}
OUTPUT:
3. CODE:
#include
#include
using namespace std;
int main()
{
string word;
cout << "Enter string: ";
cin >> word;
cout << endl << "Today's Word-Of-The-Day
is: " << word << endl;
}
OUTPUT: