Answer:
In C++:
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main(){
string lname, fname, stringnum; int num; string login, pwd;
cout<<"Last Name: "; cin>>lname;
cout<<"First Name: "; cin>>fname;
cout<<"Four-digit integer: "; cin>>num;
stringnum = to_string(num).substr(0, 4);
stringstream geek(stringnum); geek>>num;
num = num%100;
pwd = to_string(num);
if(lname.length()<5){ login = lname + fname.substr(0, 1); }
else{ login = lname.substr(0, 5) + fname.substr(0, 1); }
cout<<"Login Name: "<<login<<endl;
cout<<"Password: "<<pwd<<endl;
return 0;
}
Explanation:
This initializes all the required variables
string lname, fname, stringnum; int num; string login, pwd;
This asks the user for their last name
cout<<"Last Name: "; cin>>lname;
This asks for the first name of the user
cout<<"First Name: "; cin>>fname;
This prompts for a four-digit number
cout<<"Four-digit integer: "; cin>>num;
This converts the number into a string and extracts the first four digits
stringnum = to_string(num).substr(0, 4);
This changes the string back into an integer
stringstream geek(stringnum); geek>>num;
This extracts the last two digits of the four-digit number
num = num%100;
This generates the user's password
pwd = to_string(num);
This constructs the user's login name.
This block runs if the last name has fewer than five letters
if(lname.length()<5){ login = lname + fname.substr(0, 1); }
This block runs otherwise
else{ login = lname.substr(0, 5) + fname.substr(0, 1); }
This displays the login name
cout<<"Login Name: "<<login<<endl;
This displays the password
cout<<"Password: "<<pwd<<endl;