Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write C++ program which prompts and reads a string from the user and then comput

ID: 3535271 • Letter: W

Question

Write C++ program which prompts and reads a string from the user and then computes the Soundex code for this. Soundex is a set of rules that transforms an English name into a hash-code that can be used for similar names.


so looking up a name in a database based on the soundex code will yield similar sounding names.


Write your code using good modular design, i.e. use functions effectively and do not just put all of your code in the main method.


The correct value can be found as follows:

this is so important test your programe and see if it works perfectly


Using this algorithm, both "Robert" and "Rupert" return the same string "R163" while "Rubin" yields "R150". "Ashcraft" and "Ashcroft" both yield "A261" and not "A226" (the chars 's' and 'c' in the name would receive a single number of 2 and not 22 since an 'h' lies in between them). "Tymczak" yields "T522" not "T520" (the chars 'z' and 'k' in the name are coded as 2 twice since a vowel lies in between them). "Pfister" yields "P236" not "P123" (the first two letters have the same number and are coded once as 'P').

Explanation / Answer

he easiest way to print characters and read keyboard input is to use OS or BIOS interrupts, sometimes called system calls. They're basically separate programs written to handle a variety of rather complicated tasks, making it much easier for you to do those complicated tasks.

The only problem with OS and BIOS interrupts is that they're not directly accessible in a protected-mode operating system like Windows, so you have to write the program for 16-bit real-mode (DOS mode) and let Windows emulate the proper environment (or you have to learn the proper way to access them in protected-mode; I can't help you there as I'm still learning 16-bit assembly myself). Programming in 16-bit mode works as long as you don't need anything special from the other hardware, like video card, sound card, modem, etc. That's actually why many DOS games don't work properly in Windows.

The two DOS interrupts you need are INT 21h function 02h (print character) and INT 16h function 00h (read byte from keyboard). You can also use INT 21h function 09h (print character string), but it uses a '$' to mark the end of a string, meaning you can't use a dollar sign in any string you print with function 09h. I personally use function 02h because I can print any printable character with no problems, then use a 0 (binary 0 or NULL) to mark the end of a string. The C programming language uses the same method.

You can read up on DOS and BIOS interrupts by checking out Ralf Brown's Interrupt list, a very handy reference for assembly programming.

The rest is creating memory variables for your Welcome, prompts, and thanks, converting from binary to ASCII decimal (for printing), converting from ASCII decimal to binary (for ANDing), and a comparison to ensure that invalid input is ignored and 0 terminates the program.

Oh, you'll also need to use INT 21h function 4Ch (or 0x4C) to properly exit your program and return control to the OS. Otherwise DOS will crash or hang, or in Windows you'll end up with a hung app or an illegal operation that Windows will trap and kill.

Feel free to PM me if you want clarification or get stuck. I know how ugly it can get, but eventually things will 'click' and you'll be unstoppable. http://www.ctyme.com/intr/int.htm -- Ralf Brown's Interrupt list, online version (watch out for porn ads, though)
http://www.cs.cmu.edu/~ralf/files.html -- You can download the offline version here
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote