C++ Pointers & Classes: Translating $0-9999

In summary, The conversation discusses the use of c++ pointers and classes in writing a program to translate numbers into their corresponding English text strings. The use of conditional statements is suggested for the algorithm, with a potential method of dividing the number into chunks of three orders of magnitude. Helpful resources for pointers and classes are also provided.
  • #1
ladykaelin
1
0
Hi I am new using pointers and i am having a hard time trying to figure out how to write a program in c++ using pointers and classes. The program can be used to translate whole dollar amounts in the range 0 through 9999 into an English description of the number. For example, the number 713 would be translated into the string seven hunde thirteen, and 8203 would be translated into eight thousand hundred three, etc.,

Any idea is helpful. Thanks!
 
Technology news on Phys.org
  • #2
Are you looking for help on the use of c++ pointers/classes, or on the algorithm of translating numbers to text strings?

For help on pointers, try http://www.cplusplus.com/doc/tutorial/pointers/

For help on classes, try http://www.cplusplus.com/doc/tutorial/classes/

Regarding the application, I don't think there is anything particularly clever that can be done other than a series of conditional statements. Some time ago, I made an excel macro to prepare text like that for cheque printing. The general idea was to split the number into chunks of three orders of magnitude (eg. the "millions", "thousands" and "ones").

With that, each three-digit chunk was processed by my algorithm, which appended to a string based on the contents of that chunk. The whole thing was stitched together in the end, where proper place holders were stuck in.
 
Last edited by a moderator:
  • #3


Hello there,

As a fellow scientist, I understand that learning new concepts can be challenging. Pointers and classes in C++ can be tricky, but with practice and patience, you can master them.

To write a program using pointers and classes to translate dollar amounts into English descriptions, you can start by creating a class that will hold the dollar amount and the corresponding English description. Then, use pointers to access and manipulate the data within the class.

To translate the dollar amount, you can use a switch statement or a series of if-else statements to determine the digits in the number and assign the appropriate English description to each digit. For example, for the number 713, you can have a switch statement that checks the first digit (7) and assigns the string "seven hundred" to a variable. Then, it checks the second digit (1) and assigns the string "thirteen" to another variable. Finally, you can concatenate these variables to get the final translation "seven hundred thirteen".

I suggest breaking down the problem into smaller tasks and tackling them one at a time. This approach will make it easier for you to understand and implement the solution using pointers and classes.

In addition, there are plenty of online resources and tutorials available that can help you understand pointers and classes better. I recommend practicing with different examples and seeking help from experienced programmers if you get stuck.

I hope this helps. Good luck with your program!
 

Related to C++ Pointers & Classes: Translating $0-9999

What are pointers in C++?

Pointers in C++ are variables that store memory addresses. They are used to indirectly access and manipulate data stored in memory.

How do you declare a pointer in C++?

A pointer is declared using the asterisk symbol (*) before the variable name. For example, int* ptr; declares a pointer variable called "ptr" that can store the memory address of an integer.

How do you use pointers to translate numbers in C++?

To translate numbers in C++ using pointers, you can create a pointer variable to store the value of the number and then use the pointer to access the individual digits and translate them accordingly.

What are classes in C++?

Classes in C++ are user-defined data types that can contain both data and functions. They are used to create objects, which are instances of the class, and allow for data encapsulation and abstraction.

How do you create a class in C++?

To create a class in C++, you use the class keyword followed by the name of the class and a pair of curly braces. Inside the curly braces, you can define the data members and member functions of the class.

Similar threads

  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
5
Views
976
  • Programming and Computer Science
Replies
23
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
31
Views
2K
  • Programming and Computer Science
Replies
34
Views
2K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
3
Replies
89
Views
4K
Back
Top