You work for the social security Administration and are asked to design a machin
ID: 3541255 • Letter: Y
Question
You work for the social security Administration and are asked to design a machine that generates, and prints new Social Security cards. When it is run, it must generate a random nine digit Social-Security number, separate the number into its individual digits, and then print the digits back separated from one another with dashes in appropriate positions. Printed output should look as the number normally appears on a Social-Security card. If the random number your program generated was, say, 123421390, you program should work like this:
Name SURNAME
123-42-1390
Every time your program runs, a new random number must come out.
Can anyone help me for this question. I have no idea about it...
Explanation / Answer
/* SAMPLE OUTPUT
Kumar Ravi
604-45-8567
#include<iostream>
#include<string>
#include<iomanip>
#include<stdlib.h>
#include <sstream>
#include<time.h>
using namespace std;
int main()
{
srand(time(NULL));
string Name = "Kumar";
string sur_Name = "Ravi";
double Social_Security_number = rand()% 900000000 + 100000000;
std::stringstream ss;
ss <<setprecision(9) << (Social_Security_number);
string str= ss.str();
//cout << setprecision(9) << Social_Security_number << endl;
str.insert(3,1,'-');
str.insert(6,1,'-');
cout << Name << " " << sur_Name << endl;
cout << str << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.