Do a C++ program for the following string manipulation assignment:
Prompt the user for their first name, last name, phone number, and social security number. Make sure to let the user knows to not enter any dashes or parenthesis for phone number and social security number.
Validate each number for the number of characters (phone number must be 10 characters and SSN must be 9). Make sure to insist for a valid number that is if the number length is incorrect display an error message and prompt again, again, and again until valid number was entered.
Take the phone number and social security number and place proper dashes or parenthesis and display the result.Also display their full name and their reversed full name.
#include <iostream>
using namespace std;
int main()
{
string firstname, lastname;
long long int phonenumber, ssn;
cout<<"Enter your first name, last name ";
cin>> firstname >> lastname;
do{
cout <<"Enter your phone number without any dashes or parenthesis ";
cin>>phonenumber;
if (phonenumber<1000000000||phonenumber>9999999999)
cout << "You make a mistake, try again\n";
} while(phonenumber<1000000000||phonenumber>9999999999);
do{
cout <<"Enter your social security number without any dashes or parenthesis ";
cin>>ssn;
if (ssn<100000000||ssn>999999999)
cout << "You make a mistake, try again\n";
} while(ssn<100000000||ssn>999999999);
string reverse="", rev="";
for (int i=0; i< firstname.size(); ++i)
reverse+=firstname[firstname.size()-1-i];
for (int i=0; i< lastname.size(); ++i)
rev+=lastname[lastname.size()-1-i];
cout << reverse << " " << rev;
return 0;
}
Comments
Leave a comment