Write a C++ program that enters an 8-digit string for a birthdate from keyboard. The first two digits in the string are month of birth, the next two are the day and the remaining four are the years. The C++ should squeeze out these substrings and display it on the screen as follows:
month of birth:
day of birth:
year of birth:
Write a C++ program that enters an 8-digit string for a birthdate from keyboard. The first two digits in the s
#include%26lt;iostream%26gt;
#include%26lt;string%26gt;
using namespace std;
int ctoi(string aString, int index)
{
return (int)(aString[index-1]-'0');
}
//program mmddyyyy
int main()
{
int month,day,year;
string strData;
while(true) {
system("cls");
cout %26lt;%26lt; "\nEnter a string : ";
cin %26gt;%26gt; strData;
month = ctoi(strData, 1) *10 + ctoi(strData, 2);
day = ctoi(strData,3) * 10 + ctoi(strData,4);
year = ctoi(strData, 5) * 1000 + ctoi(strData, 6) * 100 + ctoi(strData, 7) * 10 + ctoi(strData, 8);
cout %26lt;%26lt; "\nmonth of birth : " %26lt;%26lt; month %26lt;%26lt; endl;
cout %26lt;%26lt; "day of birth : " %26lt;%26lt; day %26lt;%26lt; endl;
cout %26lt;%26lt; "year of birth : " %26lt;%26lt; year %26lt;%26lt; endl;
cout %26lt;%26lt; endl %26lt;%26lt; endl;
system("pause");
}
return 0;
}
Reply:If you need omeone else to do your homework, then you should switch majors...
Reply:#include%26lt;iostream%26gt;
#include%26lt;string%26gt;
using namespace std;
int ctoi(string aString, int index)
{
return (int)(aString[index-1] - '0');
}
int main()
{
string strData;
int month = ctoi(strData, 8) *10 + ctoi(strData, 7);
int day = ctoi(strData,6) * 10 + ctoi(strData,5);
int year = ctoi(strData, 4) * 1000 + ctoi(strData, 3) * 100 + ctoi(strData, 2) * 10 + ctoi(strData, 1);
cout %26lt;%26lt; month %26lt;%26lt; endl;
cout %26lt;%26lt; day %26lt;%26lt; endl;
cout %26lt;%26lt; year %26lt;%26lt; endl;
return 0;
}
Reply:SeriouslY!
I agree.
Come on! do your homework yourself!
Be a Man! Do the right thing!
wedding reception flowers
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment