Answered step by step
Verified Expert Solution
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 caseinsensitive. That means, numbers Two, two, and TWO are equivalent. Write a C program following ObjectOriented principles to accomplish the following tasks. Declare the class with its attribute marks 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 marks 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 Note that only numbers to is supported, other numbers will be translated to an empty string. Table :The number in integer values and its English word Int number word zero one two three four five six seven eight nine marks Define a mutator method that sets the attribute data with a value of type string. marks 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 Consider only numbes zero to nine. As for other numbers, they will be converted to value. marks 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 to implement this operator. marks 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 will result in marks 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 marks 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 oneand two respectively. Adding these two objects will result in another object with its attribute datathree marks 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 marks 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 marks In the main function, declare an array to hold 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 Fourth element with the constructor from Task Then, print all the objects of the list. marks Modify the data of each object in the list using input from the user and print the new list marks 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. marks Using an appropriate addition operator of the class, add the sum object from Task with a string value and store the result into a variable. The string value shuld be obtained from a user input. marks Figure shows an example run of the program. The bold text indicate user inputs. Original objects zeroonetwothree To modify the objects with user input
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