answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Naya
2 months ago
6

Write a program that creates a login name for a user, given the user's first name, last name, and a four-digit integer as input.

Output the login name, which is made up of the first five letters of the last name, followed by the first letter of the first name, and then the last two digits of the number (use the % operator). If the last name has less than five letters, then use all letters of the last name. Hint: Use the to_string() function to convert numerical data to a string.
Computers and Technology
1 answer:
Amiraneli [1K]2 months ago
3 0

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;

You might be interested in
During a move, employee workstations were disconnected from the network and reconnected in new offices. However, after the move
Natasha_Volkova [1026]
Ensure the cables are operational and correctly connected. Given that everything functioned well prior to the relocation, but post-move some workstations are unable to receive a valid IP, the first action should be to confirm that the cables are securely connected. If they are, also test the cables for functionality. If issues persist after this, then additional troubleshooting would be necessary.
5 0
1 month ago
How can you check an orthographic drawing to be sure there are no missing lines
maria [1035]
Using a magnifying glass.
4 0
2 months ago
Firewalls are categorized into two; namely hardware firewall and software firewall. Identify the correct statement for a softwar
oksian1 [950]

Response:

Option (d) Software firewall is positioned between standard applications and the networking components of the operating system

Justification:

  • Software Firewalls safeguard computers against trojans and harmful content that may arise from insecure applications.
  • They also protect the system from threats originating from external networks.
  • The firewall checks data transmission to and from software applications on the desktop.
  • It similarly monitors data traffic to and from networks.
  • This protection is crucial to ensure that the system does not lose access to potential attackers.
  • It is adaptable software that requires consistent management, including updates and storage oversight.
  • Using a Software Firewall alongside a Hardware Firewall is essential for securing desktops and networks.
5 0
1 month ago
The budget process which emphasizes the achievement of goals and competition between alternatives is:
Rzqust [1037]

The question offers several choices;


<span>A) </span>Incremental budgeting.
B) Performance budgeting.
C) Program budgeting.
D) Target based budgeting.


I'd argue that D is the correct option; Target based budgeting.


Target based budgeting centers on achieving objectives and competing alternatives. This budgeting approach uses pricing as a strategic tool to influence sales outcomes. It involves market research to determine the precise selling price of a product.






4 0
2 months ago
Other questions:
  • 3.14 LAB: Input and formatted output: Caffeine levels A half-life is the amount of time it takes for a substance or entity to fa
    9·1 answer
  • You're installing two new hard drives into your network attached storage device. Your director asks that they be put into a RAID
    15·1 answer
  • An Internet user has a need to send private data to another user. Which of the following provides the most security when transmi
    14·2 answers
  • Write a loop that prints each country's population in country_pop. Sample output for the given program.
    6·1 answer
  • Q2 - Square Everything (0.25 points) Write a function called square_all that takes an input called collection that you assume to
    7·1 answer
  • The ______ is the information center that drivers need to refer to when they're NOT scanning the road.
    7·1 answer
  • Redo Programming Exercise 16 of Chapter 4 so that all the named constants are defined in a namespace royaltyRates. PLEASE DONT F
    14·1 answer
  • Write the definition of a function printAttitude, which has an int parameter and returns nothing. The function prints a message
    14·1 answer
  • Write lines of verse that rhyme to remember the following information:
    16·2 answers
  • Given what you have learned on DHCP, discuss the pros and cons of having a DHCP server on each and every network segment versus
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!