Question

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 function should return must be
29 December 1953
Use the following C++ skeleton:
include <iostream>
#include <string>
using namespace std;
string convertDate(………)
{
// Add the code for the function  here
}

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


#include <iostream>
#include<stdio.h>
#include<cstring>

using namespace std;

string convertDate(string str);

int main()
{
  
string str1;
  
str1=convertDate("December 20 1998");
cout<<str1;
  
}

string convertDate(string str)
{
cout<<"The American standard is="<<str<<endl;
int l,i,j,s,s1,s2;
string str1;
string a,a1;
l=str.size();
for (i=0;i<l;i++)
{
a1=str[i];
if (a1==" ")
{
s1=i;
s2=i;
s=i;
while (true){
s=s+1;
a=str[s];
if (a==" ")
{
s1=s;
break;
}
str1=str1+str[s];
}
str1=str1+" ";
for(i=0;i<s2;i++)
{
str1=str1+str[i];
}
for (j=s1;j<l;j++)
{
str1=str1+str[j];
}
break;
}
}
  
return str1;
  
}

This code worked and if i am explaining it what i did was first checked weather their is any space as soon as i encountred a space from their i started to change the string and add it into new string str1.

If you have any doubt please comment me.

Add a comment
Know the answer?
Add Answer to:
in c++ In this question you have to write a C++ program to convert a date...
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 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 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...

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

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

  • Write a program in C++ that reads a string consisting of a positive integer or a...

    Write a program in C++ that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. DO NOT USE STACK LIBRARY OR STACK FUNCTIONS OR A STRING LIBRARY. For this assignment you have to use STACK with all methods to convert the decimal number to numeric...

  • 1. In ANSII standard C++, there is no library function to convert an integer to a...

    1. In ANSII standard C++, there is no library function to convert an integer to a string. Your program should develop such a function. In other words complete the following program using your itos function. (Use of other C functions is prohibitted) // this program will read in an integer and convert it to a string #include <iostream> #include <cstdlib> #include <string> using namespace std; string itos(int n) { } int main(int argc, char* argv[]){ int n = atoi(argv[1]); cout...

  • 4.14 LAB: Convert to binary Write a program that takes in a positive integer as input,...

    4.14 LAB: Convert to binary Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the output is:...

  • Hello, The C++ question is: ------------------------------------------------------------------------------- Write a program that takes as input 2 strings from...

    Hello, The C++ question is: ------------------------------------------------------------------------------- Write a program that takes as input 2 strings from the user. Then it determines if one string is a permutation of the other string. If the program answers "yes" to the previous question, meaning the two strings are permutations of each other, determine if each string has all unique characters. --------------------------------------------------------------------------------- I have completed the first part but I am unsure on how to also determine if each string is all unique characters...

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