Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define a class named WordNumber that models a number in English word. The requirements for the class are as follows: The number is stored in

Define a class named WordNumber that models a number in English word. The requirements for the class are as follows: The number is stored in English word for example, zero, one, two, and so on. The number is stored in an attribute of type string named data. You should consider only numbers zero to nine. Other numbers are beyond the scope of this test. The numbers should be treated as case-insensitive. That means, numbers Two, two, and TWO are equivalent. Write a C++ program following Object-Oriented principles to accomplish the following tasks. 1. Declare the class with its attribute (5 marks)2. Define a constructor that accepts a parameter of type string to set the classs attribute, data. Declare this constructor such that it can also serve as a default constructor (or default argument constructor). In this case, the parameter should be defaulted to string of zero.(6 marks)3. Define another constructor that accepts an integer number as a parameter. This constructor will translate the number into an English word to be stored in the attribute, data. The translation should be done based on Table 1.Note that only numbers 0 to 9 is supported, other numbers will be translated to an empty string. Table 1:The number in integer values and its English word Int number word 0 zero 1 one 22 two 3 three 4 four 5 five 6 six 7 seven 8 eight 9 nine (11 marks)4. Define a mutator method that sets the attribute data with a value of type string. (7 marks)5. Define a conversion method that converts a WordNumber object to an integer value. This method uses the string number stored in the attribute of the object to do the conversion following the translation table from Table 1. Consider only numbes zero to nine. As for other numbers, they will be converted to 0 value. (6 marks)6. Define an overloaded operator that will be used to determine whether a WordNumber object is greater than another WordNumber object. This operator will result in a boolean value. The comparison should be done with the integer value of the objects. You should make use of the converstion method from Task 5 to implement this operator. (6 marks)7. Define an overloaded operator for the addition operation to add a WordNumber with an integer value. This operator should results in an integer value. The addition operation is done by addding the integer value of the object with the integer number. For example, assume a WordNumber object, n is set to nine, thus the following statements: n +11 will result in 20.(5 marks)38. Define another overloaded operator for the addition operation to add a WordNumber with an string and results in a string. The addition operation is done by concatenating the the objects data with the string. For example, assume a WordNumber object, n is set to nine, thus the following statements: n + string( thousands) will result in nine thousands.(5 marks)9. Define another overloaded operator for the addition operation to add a WordNumber object with another WordNumbr object This operator will results in another WordNumber object. The addition operation is done by adding the integer values of both objects and translate the result into an English Word to be stored in the attribute data. For example, consider two WordNumber objects, a and b are set to one,and two, respectively. Adding these two objects will result in another object with its attribute data=three.(6 marks)10. Define a regular functions named printObject and specify it as a friend to the class WordNumber. This function accepts a WordNumber object as parameter amd prints out the data of the object along with its integer value. For example (seven,7).(4 marks)11. Define another regular functions named printArray to print a list of WordNumber objects that are passed as parameters. This function should make use of function from Task 10.(6 marks)12. In the main function, declare an array to hold 4 elements of WordNumber objects. Initialize each element with any value using the constructor as follows: First element with the default constuctor Second and third elements with the constructor from Task 2. Fourth element with the constructor from Task 3. Then, print all the objects of the list. 4(10 marks)13. Modify the data of each object in the list using input from the user and print the new list (6 marks)14. Using a loop and appropriate methods and operators of the class, find the largest object and the sum of the objects of the list. Then print the largest and sum objects. (13 marks)15. Using an appropriate addition operator of the class, add the sum object from Task 14 with a string value and store the result into a variable. The string value shuld be obtained from a user input. (4 marks) Figure 2 shows an example run of the program. The bold text indicate user inputs. Original objects (zero,0)(one,1)(two,2)(three,3) To modify the objects with user input

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

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

Students also viewed these Databases questions

Question

Under what circumstances do your customers write complaint letters?

Answered: 1 week ago