Answered step by step
Verified Expert Solution
Question
1 Approved Answer
!@%#$^%^&*%&$^#^&^&^%$#$#^@$^#$ c++ please CSE 232, Lab Exercise 4 Partner Choose a partner in the lab to work with on this exercise. Two people should work
!@%#$^%^&*%&$^#^&^&^%$#$#^@$^#$
c++ please
CSE 232, Lab Exercise 4 Partner Choose a partner in the lab to work with on this exercise. Two people should work at one computer. Occasionally switch who is typing. More Command Line I/O redirection Please read the page on I/O redirection in the Lab04 directory labeled IO-redirection.pdf cd to your x2go Desktop. Show your TA the sorted filenames there (using a combination of 1s, sort and redirection) Lab Assignment John Napier was a Scottish mathematician who lived in the late 16th and early 17th centuries. He is known for a number of mathematical inventions, one of which is termed location arithmetic You job is to write functions that can convert back and forth between location and decimal representations, as well as some support functions for the process Overview Location arithmetic is a way to represent numbers as binary values, using a notation that is not positional, but representational. You can see a detailed description in http://en wikipedia.org/wiki/Location arithmetic but here are the basics. The representation Napier used letters to represent powers of two. In using letters, the position of the letter is not important, allowing for multiple representations of the same number. For example, in location arithmetic a=1, b-2, c-4, d-8, e= 16, f-32 and thus: acf I + 4 + 32 caf or 37 For convenience, the letters are typically sorted but only to make reading easier. Napier allowed for redundant occurrences of letters, though he acknowledged that there is a normal form that had no repeats. He described this as the extended (repeated) vs. abbreviated (no repeats). To create the abbreviated form, any pair of letters can be reduced to a single occurrence of the next "higher letter". For example (extended) (2b's to c) (abbreviated) Addition Addition is particularly easy. Take all the letters from the two values, put them into a single string, sort, reduce, convert! mix reduce convert abc +bcd abbccdacccdacddace1 41621 Your Task Write the following four functions and main program to do location arithmetic 1. long loc_to_dec (string loc) :convert location arithmetic string to an nteger string abbreviate (string loc): take a location string and reduce it to its abbreviated form. We want you to experiment with string manipulation so you cannot convert it to integer first. You must do the abbreviation directly 2. Show your TA a working abbreviate function. 3. string dec to loc (longdec) convert an integer to an abbreviated location string 4. long addloc (string locl, string loc2)take two location strings, add them, provided the integer result. For this function, do it the way described above!, that is mix the strings sort them reduce the string (using your abbreviate function) convert the result (using your loc_to_dec function) a. b. c. d. 5. Write a main function that shows off your work: prompt for two elements: a location string and a long prints on a single line 4, space separated elements a. b. i. loc to_dec on the input location string ii. abbreviate on the input location string ii. dec to_long on the input long iv. add loc using the input location string twice (adding it to itself) Show your TA your working program. Testing You can check yourself on Mimir, Lab04 location strings. There is an empty file lab04/lab04.cpp for you to begin with. Sorting We haven't done sorting yet, but C++ makes it pretty easy. There's an example in the directory, but here is the gist. Sorting sorts the individual elements of a collection in sorted order from two points in the collection. Elements in strings are chars, so sorting from the beginning to the end of the string, character by character, is shown below. Note that sorting changes the string in place! includealgorithm> using std::sort; string my str = "adbche". //sort string, char by char, in place, from begin to end). Note the parentheses! sort (my_str.begin), my_str.end )) cout i. if you do addition/subtraction on a character, you need to cast it to a character for the "printable" version. c. push back method. i. you can push a character onto the end of the string using this method. d. indexing via the [1 operatorStep 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