Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please let me know how to write C++ code. Have to use the variables or functions that are mention in the instruction. Need 2 separate

Please let me know how to write C++ code.

Have to use the variables or functions that are mention in the instruction.

Need 2 separate files - NameTag.cpp NameTag.h

image text in transcribedimage text in transcribedimage text in transcribed

Tester Program

image text in transcribed

Correct Output

image text in transcribed

Please note that you can (and probably should) add more member functions to make the DIY part work. Create a Module for a NameTag to create/read information for a name tag and print it. The class name must be NameTag. It should be able to hold two pieces of information; A name and a 5 digit extension number. The name should be kept dynamically; however if the name is longer than 40 characters, only 40 characters should be printed in the name tag. Also if the name is shorter than 20 characters, it should be printed in 20 spaces. The extension number is optional and if not provided, it should be printed as N/A. Print the name tag by drawing a box around it. The box must have five interior lines and the name should have exactly one space distance with the line of the box at left and minimum of one space with the line at right. The name and the extension are printed on lines 2 and 4 and the rest of the name tag is filled with spaces. Here are couple of examples: (Name: "Fred Soley", extension 12345): (Name: "David Wright Mason Gilmour Waters Rogers Nick", extension not available) constructors - default constructor (for an empty tag) - constructor with one argument to set the name without extension number - constructor with two arguments to set the name and the extension destructor - have a destructor to avoid memory leaks Functions: print a function called print to print the name tag as shown above read A function called read that receives the name and then the extension number from console and returns the reference of the current object (NameTag\&). Read function should read the name up to the maximum of 40 characters and ignore the rest and then set the name of the NameTag to the entered name. (This may overwrite an already existing name in the NameTag) Then it should give an option to the user to enter the extension number or not. If the user chooses to enter the extension it should enforce the user to enter a 5 digit integer and if user does not comply, it should print one of the following messages based on the type of the error: and get the new value and repeat until the user enters a correct value. A sample for execution is provided below; Note that the read() execution is demonstrated right before the name tag printouts.(The exact tester output is in Execution Sample Section) Please enter the name: Hubert Blaine Wolfeschlegelsteinhausenbergerdorff Would you like to enter an extension? (Y)es/(N)o: x Only (Y) or (N) are acceptable, try agin: n Please enter the name: Lisa Simpson Would you like to enter an extension? (Y)es/(N)o: Y Please enter a 5 digit phone extension: five Bad integer value, try again: 9999 Invalid value [10000

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

Students also viewed these Databases questions