Question

Finish the program. Follow the program logic and then complete the algorithm in the function. Use...

Finish the program. Follow the program logic and then complete the algorithm in the function. Use the programs given constructs and variables only.

#include <iostream>
#include <string>
using namespace std;
// Prototype
string format(string);
int main()
{
// The following string will hold the user's input.
string userDate;
// The following string will hold the formatted date.
string formattedDate;
// Get a date from the user.
cout << "Enter a date in the form mm/dd/yyyy: ";
cin >> userDate;
// Format the date.
formattedDate = format(userDate);
// Display the formatted date.
cout << "You entered " << formattedDate << endl;
return 0;
}
// The format function accepts a date in the form mm/dd/yyyy
// as a string, and returns the date in the form March 12, 2014.
string format(string date)
{
int month; // To hold the numeric month
string temp; // Temporary storage
string result; // To hold the formatted date
// The following string array holds the names of
// the months.
string months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September",
"October", "November", "December" };
YOUR CODE HERE....

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ CODE :

#include <iostream>
#include <string>
#include <sstream>
using namespace std;
// Prototype
string format(string);
int main()
{
// The following string will hold the user's input.
string userDate;
// The following string will hold the formatted date.
string formattedDate;
// Get a date from the user.
cout << "Enter a date in the form mm/dd/yyyy: ";
cin >> userDate;
// Format the date.
formattedDate = format(userDate);
// Display the formatted date.
cout << "You entered " << formattedDate << endl;
return 0;
}
// The format function accepts a date in the form mm/dd/yyyy
// as a string, and returns the date in the form March 12, 2014.
string format(string date)
{
int month; // To hold the numeric month
string temp; // Temporary storage
string result; // To hold the formatted date
// The following string array holds the names of
// the months.
string months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September",
"October", "November", "December" };
  
std::string str2 = date.substr (0,2); // "month"
temp = date.substr (3,2)+" , "+ date.substr (6,4); // "day , year"
istringstream ( str2 ) >> month; // convert string to int type
result = months[month-1]+" "+temp;
return result;
}

OUTPUT :

Default Term sh-4.2$ main Enter a date in the form mm/dd/yyyy: 03/12/2014 You entered March 12, 2014 sh-4.2$

Add a comment
Know the answer?
Add Answer to:
Finish the program. Follow the program logic and then complete the algorithm in the function. Use...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ Consider the following Date class: #include <iostream> using namespace std; class MyDate { private:...

    In C++ Consider the following Date class: #include <iostream> using namespace std; class MyDate { private: int month, day, year; public: MyDate() {setDate(2,27,2006);} MyDate(int, int, int); void setDate(int mm, int dd, int yyyy); void showDate(); }; MyDate::MyDate(int mm, int dd, int yyyy) { month = mm; day = dd; year = yyyy; }; void MyDate::setDate(int mm, int dd, int yyyy) { month = mm; day = dd; year = yyyy; }; void MyDate::showDate() { cout << "The date is "...

  • Complete a partially written C++ program that includes a function that return a value. The program...

    Complete a partially written C++ program that includes a function that return a value. The program is a simple calculator that prompts the user of 2 number and an operation (+, -, * or, /). The two number and the operator are passed to the function where the appropriate arithmetic operation is performed. The result is return to the main function () where the arithmetic operation and result are displayed. For example 3 * 4 = 12 The source code...

  • Python 3. Date Printer Write a program that reads a string from the user containing a...

    Python 3. Date Printer Write a program that reads a string from the user containing a date in the form mm/dd/yyyy. It should print the date in the format March 12, 2018 3. Date Printer Write a program that reads a string from the user containing a date in the form mm/dd/yyyy. It should print the date in the format March 12, 2018

  • Transform the find function of Question 4 into a function template. Here is the program used...

    Transform the find function of Question 4 into a function template. Here is the program used to test your template, followed by the output of that program: #include <iostream> #include <string> #include "find.h" using namespace std; #define NUM_ELEMENTS(a) (sizeof(a) / sizeof(a[0])) int main() {         cout << "int" << endl;         cout << "---" << endl;         int arr1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};         cout << "3 is at location " << find(arr1, NUM_ELEMENTS(arr1),...

  • Question 19 4 pts Using the program below, please complete the program by adding 2 functions...

    Question 19 4 pts Using the program below, please complete the program by adding 2 functions as follow: 1. A function named getAverage that calculates and returns the Average. 2. A function named getMaximum that returns the maximum of the three numbers. Make sure to use the proper data types for all variables and functions. #include <iostream> using namespace std; //function getAverage //function getMaximum int main(int argc, char** argv) { int x, y, z; cout << "Enter three whole numbers:...

  • 81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5...

    81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5 );                    int BoxVolume(int length = {1}, int width = {1}, int height = {1});                                                     T__   F__                                                                     82. The following function is implemented to swap in memory the          argument-values passed to it:         void swap(int a, int b)                   {           int temp;             temp = a;             a = b;             b = temp;        ...

  • #include <iostream> #include <string> using namespace std; //Write a function that changes all characters in a...

    #include <iostream> #include <string> using namespace std; //Write a function that changes all characters in a string to dashes string to_dash(string s){ for(int i = 0; i < s.length(); i++){ } return s; } int main(){ string s; cin >> s; s = to_dash(s); cout << s << endl; }

  • /* * Program5 for Arrays * * This program illustrates how to use a sequential search...

    /* * Program5 for Arrays * * This program illustrates how to use a sequential search to * find the position of the first apparance of a number in an array * * TODO#6: change the name to your name and date to the current date * * Created by Li Ma, April 17 2019 */ #include <iostream> using namespace std; //global constant const int ARRAY_SIZE = 10; //TODO#5: provide the function prototype for the function sequentialSearch int main() {...

  • working on a program in c++ The user enters an email address into your program. You...

    working on a program in c++ The user enters an email address into your program. You must cuteverything after the @ symbol and output it. #include <iostream> #include <string> using namespace std; int main() { string email_adress = ""; //email get the info cout <<"what is your email adress? "; getline(cin, email_adress) ; cin.ignore('@'); // now we put into writitng in sentence cout <<"the email you entered is: " << email_adress << ". " <<"your email adress domian is :"...

  • using the source code at the bottom of this page, use the following instructions to make...

    using the source code at the bottom of this page, use the following instructions to make the appropriate modifications to the source code. Serendipity Booksellers Software Development Project— Part 7: A Problem-Solving Exercise For this chapter’s assignment, you are to add a series of arrays to the program. For the time being, these arrays will be used to hold the data in the inventory database. The functions that allow the user to add, change, and delete books in the store’s...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT