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

CSE 232, Lab Exercise 4 Partner Choose a partner in the lab to work with on this

ID: 3891054 • Letter: C

Question

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 'O redirection Please read this page on ed 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 16" and early 17" centuries. He is known for a number of mathematical inventions, one of which is termed You job is to write functions that can convert back and forth between location and decimal representatioas, 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:len.wikipedia. org/wiki/Location arithmetic but here are the basics. 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 1 + 4 + 32 cafor 37 For convenience, the letters are typically soeted 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 fom, any pair of letters can be reduced to a single occurrence of the next "higher letter". For example: extended stoc) abboed accod aedd ace 1+4+16 21 Addition

Explanation / Answer

Source code :


#include <iostream>
#include <cstring>
#include <string>
#include<math.h>

using namespace std;
string abbreviate(string &s);
long add_loc(string &s1,string &s2)
{
    int length,sum=0,i=0;
    s1=s1+s2;
    cout<<" Added String is :"<<s1;
    string f=abbreviate(s1);
    length=strlen(f.c_str());
    //cout<<" "<<length;
  
    while(i<length)
    {
      
      sum=sum+pow(2,(f[i]-'a'));
    
      i++;
    }
    cout<<" Final sum is:"<<sum;
}
int main()
{
    string str1="abbcde";
    string str2="bcdef";
    //input strings if you need turn it into dynamic by removing comments
    //cout<<"Enter the two strings";
    //cin>>str1>>str2;
  
    str1=abbreviate(str1);
    str2=abbreviate(str2);
    cout<<" value 1 :"<<str1<<" value2: "<<str2;
    add_loc(str1,str2);
    return 0;
}

string abbreviate(string &str)
{
    int length,i=0;

    string abbr;
    length=strlen(str.c_str());

    while(i<=length-2)
    {
        if(str[i]==str[i+1])
        {
            abbr+=(str[i]+1);
         
            i+=1;
        continue;
        }
      
   
    abbr+=str[i];  
    i++;
  
    }

    return abbr;
  
}

output :