Question

In this question you have to write a C++ program to convert a date from one format to another. You have to write a complete pint main() مسی string americanDate; // Add the code for the main function here return 0; The main() function should prompt th

A number of stringmember functions to help you StringObject.size() StringObject.substr(startPos, length) StringObject.find(su

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

Below is the code in C++ for the above question:

#include<iostream>
#include<string>
using namespace std;

string convertDate(string americanDate){
   // creating string variables for extracting
   // month, day and year.
   string month = "",day = "",year = "";
   int pos;
   // finding pos of space
   pos = americanDate.find(' ');
   // finding month
   month = americanDate.substr(0,pos);
  
   // removing the month part from the americanDate
   americanDate = americanDate.substr(pos+1,americanDate.length()-month.length());
  
   // finding the pos of space.
   pos = americanDate.find(' ');
   // finding the day.
   day = americanDate.substr(0,pos - 1);
  
   // finallu finding the year
   year = americanDate.substr(pos+1,5);
  
   // constructing the converted date.  
   string convert = day + " " + month + " " + year;
   return convert;
}

int main(){
  
   string americanDate;
   // getting date from the user.
   getline(cin,americanDate);
  
   // calling convertDate function to convert the format
   string convertedDate = convertDate(americanDate);
   // displaying the converted date.
   cout << convertedDate;

   return 0;
}


Refer to the screenshot attached below to better understand the code and indentation:
#include<iostream> #include<string> using namespace std; string convertDate(string americanDate) { // creating string variabl



Output:
December 29, 1953 29 December 1953

If this answer helps you then please upvote,
for further queries comment below.
Thank you.

Add a comment
Know the answer?
Add Answer to:
In this question you have to write a C++ program to convert a date from one...
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
  • QUESTION 6 15 marks In this question you have to write a C++ program to convert...

    QUESTION 6 15 marks In this question you have to write a C++ program to convert a date from one format to another. You have to write a complete program consisting of a main() function and a function called convertDate(). The function receives a string of characters representing a date in American format, for example December 29, 1953. The function has to convert this date to the international format. For example: If the string December 29, 1953 is received, the...

  • QUESTION 6 15 marks In this question you have to write a C++ program to convert...

    QUESTION 6 15 marks In this question you have to write a C++ program to convert a date from one format to another. You have to write a complete program consisting of a nain() function and a function called convert Datel). The function receives a string of characters representing a date in American format, for example December 29, 1953. The function has to convert this date to the international format. For example: If the string December 29, 1953 is received,...

  • QUESTION 6 15 marks In this question you have to write a C++ program to convert...

    QUESTION 6 15 marks In this question you have to write a C++ program to convert a date from one format to another. You have to write a complete program consisting of a nain() function and a function called convert Datel). The function receives a string of characters representing a date in American format, for example December 29, 1953. The function has to convert this date to the international format. For example: If the string December 29, 1953 is received,...

  • QUESTION 6 15 marks In this question you have to write a C++ program to convert...

    QUESTION 6 15 marks In this question you have to write a C++ program to convert a date from one format to another. You have to write a complete program consisting of amain () function and a function called convertDate(). The function receives a string of characters representing a date in American format, for example December 29, 1953. The function has to convert this date to the international format. For example: If the string December 29, 1953 is received, the...

  • in c++ In this question you have to write a C++ program to convert a date...

    in c++ In this question you have to write a C++ program to convert a date from one format to another. You have to write a complete program consisting of a main()function and a function called convertDate(). The function receives a string of characters representing a date in American format, for example December 29, 1953. The function has to convert this date to the international format. For example: If the string December 29, 1953 is received, the string that the...

  • 1 Problem Description Instructions. You are provided one skeleton program named LCS.java . The source files...

    1 Problem Description Instructions. You are provided one skeleton program named LCS.java . The source files are available on Canvas in a folder named HW6 . Please modify the skeleton code to solve the following tasks. • Task 1 (100 pts). Implement the lcs length() function as discussed in Lecture 11. • Note: You should not return the double-array b and c as in the pseu- docode. Instead, return the length of the longest common subsequence. • Hint: To get...

  • C++, use the skeleton code to make a program of the following

    c++, use the skeleton code to make a program of the following include <iostream> tinclude <string> using namespace std; class car public: //define your functions here, at least 5 private: string name; int mpg; double price int horsepower; // feel free to add more atributes int main() // create you objects, call your functions // define member functions here For this lab, write a program that does the following: Creates a class based on the car skeleton code (you may...

  • In java write a command-line program that helps to decrypt a message that has been encrypted...

    In java write a command-line program that helps to decrypt a message that has been encrypted using a Caesar cipher1. Using this method, a string may contain letters, numbers, and other ASCII characters, but only the letters (upper- and lower-case) are encrypted – a constant number, the shift, is added to the ASCII value of each letter and when letters are shifted beyond ‘z’ or ‘Z’ they are wrapped around (e.g. “Crazy?” becomes “Etcba?” when shifted by 2). When your...

  • 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; //...

  • Given the incomplete program below, write two functions, one called integer and another called decimal. You...

    Given the incomplete program below, write two functions, one called integer and another called decimal. You can use following incomplete program. Your assignment is to supply the necessary missing code: #include #include using namespace std; int integer (….) { //REPLACE THE … WITH THE REQUIRED PARAMETER (A DOUBLE) //WRITE HERE THE CODE TO EXTRACT THE INTEGER AND RETURN IT } double decimal (….) { //REPLACE THE … WITH THE REQUIRED PARAMETER //WRITE HERE THE CODE TO EXTRACT THE DECIMAL PORTION,...

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