Question

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 t

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

Code is as follows:

***********************************************************************************************************************************

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


string convertDate(string americanDate){
int i = americanDate.find(" "); //find the first space
string Month = americanDate.substr(0,i); //get month
int k = americanDate.find(","); //find location of ","
string Day = americanDate.substr(i+1,k-i-1); //find day
  
string Year = americanDate.substr(k+2,americanDate.size()); //find year
  
string newDate = Day + " " + Month + " " + Year; //concatenate to get international format
return newDate; //return newDate
}
int main()
{
string americanDate;
  
cout<<"Enter the date in American format : "; //prompt for the americanDate
getline(cin,americanDate); //get americanDate
  
cout<<"Original date: "<<americanDate<<endl; //print americanDate
cout<<"Coverted date(to international format): "<<convertDate(americanDate)<<endl; //call the convertDate and print Coverted date
return 0;
}

***********************************************************************************************************************************

Screenshot of the code:

1 #include <iostream> 2 #include<string> 3 using namespace std; 4 5 6. string convertDate(string americanDate) { 7 int i = am

Output:

Enter the date in American format : December 29, 1953 Original date: December 29, 1953 Coverted date(to international format)

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

  • In this question you have to write a C++ program to convert a date from one...

    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 function...

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

  • Write a C++ Program. You have a following class as a header file (dayType.h) and main()....

    Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public:     static string weekDays[7];     void print() const;     string nextDay() const;     string prevDay() const;     void addDay(int nDays);     void setDay(string d);     string getDay() const;     dayType();     dayType(string d); private:     string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...

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

  • Write a program that prompts the user to input a string. The program then uses the...

    Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. #include <iostream> #include <string> using namespace std; void removeVowels(string& str); bool isVowel(char ch);...

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

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

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