Okay guys, I am having a problem with this code. I really need help with this one because I am stuck. The problem with this question is that the name, ss, id, and pass have to be ONE STRING. It's stupid because I wish I could make the strings split up but we have to create a substring. PLEASE NOTHING TOO FANCY, I'm still a beginner. This is what I have so far:
Write a program that reads in a line consisting of a student’s name, Social
Security number, user ID and password. The program outputs the string in which
all the digits of the Social Security number, and all the characters in the password
are replaced with X. (The Social Security number is of the form 000-00-0000, and the
user ID and the password do not contain any spaces.) Your program should not use
operator [ ] to access a string element. Use appropriate functions that described in the
textbook.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void getInfo(string& info);
void splitInfo(string& a, string& b);
void unseenInfo(string& hide);
int main()
{
string k, name;
getInfo(k);
splitInfo(k, name);
system ("PAUSE");
return 0;
}
void getInfo(string& info)
{
cout << "Enter your Name, Social Security number, User ID, and Passord - separated by commas: " << endl;
getline(cin, info);
return;
}
/*cout << "Name: ";
for (counter = 0; counter < b.length(); counter++)
{
if (b.length() == ',')
cout << " ";
*/
//cout << "SSN: ";
//for (counter = 0; counter < b.length(); counter++)
//{
// cout << "x";
//}
//cout << endl;
//cout<<"User ID: ";
//for (counter = 0; counter < b.length(); counter++)
//{
// cout << b;//if I did cout << "x"; it could replace the user ID with x's
//}
//cout << endl;
//cout << "Password: ";
//for (counter = 0; counter < b.length(); counter++)
//{
// cout << "x";
//}
/*cin.ignore();
return;
}*/
//void split(char a)
//{
//
//}
void splitInfo(string& a, string& b)
{
b = "a";
int p = 1;
for (int i = 0; a.at(i) != ','; i++)
p++;
if (a.at(0) != ' ')
b = a.substr(0, p);//assigned substring to b
else
b = a.substr(1, p);//end of pulling out the substring from string
a.erase(0, p + 1);//erase from 0 to p + 1, erase the first comma and everything before it
cout << a << endl;
cout << b << endl;
cout << endl;
cout << endl;
for (int i = 0; a.at(i) != ','; i++)
p++;
if (a.at(0) != ' ')
b = a.substr(0, p);
else
b = a.substr(1, p);
a.erase(0, p + 1);
cout << a << endl;
cout << b << endl;
return;
}
void unseenInfo(string& hide)
{
char y = 'x';//to hide social security and password
for (int i = 0; i < hide.length(); i++)
hide[i] = y;//turns string values into x's to hide the string
return;
}
Thank you for helping me!