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
}
#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.
in c++ In this question you have to write a C++ program to convert a date...
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 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 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 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 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(). #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 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 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...
C++ question Input Format You are given two strings, a and b, separated by a new line. Each string will consist of lower case Latin characters ('a'-'z'). Output Format In the first line print two space-separated integers, representing the length of a and b respectively. In the second line print the string produced by concatenating a and b (a+b). In the third line print two strings separated by a space, a' and b'. a' and b' are the same as...
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:...