Question
Please write code by using C++ For certain applications, it is useful to be able to generate a series of names that form a sequential
Please write code by using C++
For certain applications, it is useful to be able to generate a series of names that form a sequential pattern. For example, if you were writing a program to number figures in a paper, having some mechanism to return the sequence of strings Figure 1, Figure 2, Figure 3, and so on, would be very handy. However, you might also need to label points in a geometric diagram, in which case you would want a similar but independent set of labels for points such as P0, P1, P2, and so forth. If you think about this problem more generally, the tool you need is a label generator that allows the client to define arbitrary sequences of labels, each of which consists of a prefix string (Figure or P for the examples in the preceding paragraph) coupled with an integer used as a sequence number. Because the client may want different sequences to be active simultaneously, it makes sense to define the label generator as an abstract type called LabelGenerator. To initialize a new generator, the client provides the prefix string and the initial index as arguments to the LabelGenerator constructor. Once the generator has been created, the client can return new labels in the sequence by calling next_label() on the LabelGenerator. The constructors function signature should be: LabelGenerator(const std::string &prefix, int start); The signature of next_label should be: std::string next_label(); Your implementation should match these function signatures, you should not change them. As a hint your label printing should behave similar to the following code: LabelGenerator point_numbers("P", 0); for (int i = 0; i
Input and output
The input for each case will consist of two lines. On the first line is a prefix string which may contain spaces (indicated by **_** in the example below), including leading or trailing spaces. On the second line are two integers which are the initial and the final values of a sequence. Your program will print the sequence of labels on one line, adjacent terms separated by a space. To turn an integer into a string, you can use the std::to_string() function defined in (see cppreference.com for more information).
3. Label Generator: 20 points File: label generator.cpp For certain applications, it is useful to be able to generate a series of names that form a sequential pattern. For example, if you were writing a program to number figures in a paper, having some mechanism to return the sequence of strings "Figure 1, "Figure 2", "Figure 3", and so on, would be very handy However, you might also need to label points in a geometric diagram, in which case you would want a similar but independent set of labels for points such as P0", P1", ''P2", and so forth. If you think about this problem more generally, the tool you need is a label generator that allows the client to define arbitrary sequences of labels, each of which consists of a prefix string ("Figure" or "P" for the examples in the preceding paragraph) coupled with an integer used as a sequence number. Because the client may want different sequences to be active simultaneously, it makes sense to define the label generator as an abstract type called LabelGenerator. To initialize a new generator, the client provides the prefix string and the initial index as arguments to the LabelGenerator constructor. Once the generator has been created, the client can return new labels in the sequence by calling next label) on the LabelGenerator The constructor's function signature should be: LabelGenerator (const std: :string kprefix, int start); The signature of next label should be: std: :string next_labelO Your implementation should match these function signatures, you should not change them. As a hint your label printing should behave similar to the following code: LabelGenerator point_numbers ("P", 0); for (int i 0;Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started