Question

In: Computer Science

#include <iostream> #include <string> #include <sstream> using namespace std; int main() { string userInput; getline(cin, userInput);...

#include <iostream>

#include <string>

#include <sstream>

using namespace std;

int main() {

string userInput;

getline(cin, userInput);

// Declaring base

int N = 30;

if (userInput.length() > 10) {

cout << 0 << endl;

}

else {

int finalTotal = 0;

//Iterates through userInput

for(int i = 0; i < 10; i++){

char convertedInput = userInput[i];

// ASCII decimal value of each character

int asciiDec = int(convertedInput);

//Casts char value from input to int value

stringstream chr;

chr << convertedInput;

int temp;

chr >> temp;

// Sets whitespace value equal to zero

if(convertedInput == ' ') {

temp = 0;

}

//Converting to base 30 value

if (temp >= 1 && temp <= 10) {

temp = temp;

}

else if(asciiDec >= 65 && asciiDec <= 84) {

temp = asciiDec - 55;

}

else if(asciiDec >= 97 && asciiDec <= 116) {

temp = asciiDec - 87;

}

else {

temp = 0;

}

finalTotal += temp; //(1)

}

cout << finalTotal << endl;

}

return 0;

}

Accurate conversion from C++ to MIPS please

Solutions

Expert Solution

std::operator|(std::_Ios_Openmode, std::_Ios_Openmode):

        daddiu  $sp,$sp,-32

        sd      $fp,24($sp)

        move    $fp,$sp

        move    $3,$4

        move    $2,$5

        sll     $3,$3,0

        sw      $3,0($fp)

        sll     $2,$2,0

        sw      $2,4($fp)

        lw      $3,0($fp)

        lw      $2,4($fp)

        or      $2,$3,$2

        move    $sp,$fp

        ld      $fp,24($sp)

        daddiu  $sp,$sp,32

        j       $31

        nop

main:

        daddiu  $sp,$sp,-496

        sd      $31,488($sp)

        sd      $fp,480($sp)

        sd      $28,472($sp)

        sd      $16,464($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(main)))

        daddu   $28,$28,$25

        daddiu  $28,$28,%lo(%neg(%gp_rel(main)))

        daddiu  $2,$fp,24

        move    $4,$2

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1Ev)($28)

        move    $25,$2

        nop

        daddiu  $2,$fp,24

        move    $5,$2

        ld      $4,%got_disp(_ZSt3cin)($28)

        ld      $2,%call16(_ZSt7getlineIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE)($28)

        move    $25,$2

        nop

        li      $2,30                 # 0x1e

        sw      $2,8($fp)

        daddiu  $2,$fp,24

        move    $4,$2

        ld      $2,%call16(_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv)($28)

        move    $25,$2

        nop

        sltu    $2,$2,11

        xori    $2,$2,0x1

        andi    $2,$2,0x00ff

        beq     $2,$0,.L4

        nop

        move    $5,$0

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZNSolsEi)($28)

        move    $25,$2

        nop

        ld      $5,%got_disp(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)($28)

        move    $4,$2

        ld      $2,%call16(_ZNSolsEPFRSoS_E)($28)

        move    $25,$2

        nop

        b       .L5

        nop

.L4:

        sw      $0,0($fp)

        sw      $0,4($fp)

.L12:

        lw      $2,4($fp)

        slt     $2,$2,10

        beq     $2,$0,.L6

        nop

        lw      $3,4($fp)

        daddiu  $2,$fp,24

        move    $5,$3

        move    $4,$2

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm)($28)

        move    $25,$2

        nop

        lbu     $2,0($2)

        sb      $2,12($fp)

        lb      $2,12($fp)

        sw      $2,16($fp)

        li      $5,8                        # 0x8

        li      $4,16                 # 0x10

        ld      $2,%got_disp(std::operator|(std::_Ios_Openmode, std::_Ios_Openmode))($28)

        move    $25,$2

        nop

        move    $3,$2

        daddiu  $2,$fp,64

        move    $5,$3

        move    $4,$2

        ld      $2,%call16(_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_Openmode)($28)

        move    $25,$2

        nop

        lb      $2,12($fp)

        move    $3,$2

        daddiu  $2,$fp,64

        daddiu  $2,$2,16

        move    $5,$3

        move    $4,$2

        ld      $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c)($28)

        move    $25,$2

        nop

        daddiu  $3,$fp,56

        daddiu  $2,$fp,64

        move    $5,$3

        move    $4,$2

        ld      $2,%call16(_ZNSirsERi)($28)

        move    $25,$2

        nop

        lb      $3,12($fp)

        li      $2,32                 # 0x20

        bne     $3,$2,.L7

        nop

        sw      $0,56($fp)

.L7:

        lw      $2,56($fp)

        blez    $2,.L8

        nop

        lw      $2,56($fp)

        slt     $2,$2,11

        beq     $2,$0,.L8

        nop

        lw      $2,56($fp)

        sw      $2,56($fp)

        b       .L9

        nop

.L8:

        lw      $2,16($fp)

        slt     $2,$2,65

        bne     $2,$0,.L10

        nop

        lw      $2,16($fp)

        slt     $2,$2,85

        beq     $2,$0,.L10

        nop

        lw      $2,16($fp)

        addiu   $2,$2,-55

        sw      $2,56($fp)

        b       .L9

        nop

.L10:

        lw      $2,16($fp)

        slt     $2,$2,97

        bne     $2,$0,.L11

        nop

        lw      $2,16($fp)

        slt     $2,$2,117

        beq     $2,$0,.L11

        nop

        lw      $2,16($fp)

        addiu   $2,$2,-87

        sw      $2,56($fp)

        b       .L9

        nop

.L11:

        sw      $0,56($fp)

.L9:

        lw      $2,56($fp)

        lw      $3,0($fp)

        addu    $2,$3,$2

        sw      $2,0($fp)

        daddiu  $2,$fp,64

        move    $4,$2

        ld      $2,%call16(_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev)($28)

        move    $25,$2

        nop

        lw      $2,4($fp)

        addiu   $2,$2,1

        sw      $2,4($fp)

        b       .L12

        nop

.L6:

        lw      $2,0($fp)

        move    $5,$2

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZNSolsEi)($28)

        move    $25,$2

        nop

        ld      $5,%got_disp(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)($28)

        move    $4,$2

        ld      $2,%call16(_ZNSolsEPFRSoS_E)($28)

        move    $25,$2

        nop

.L5:

        move    $16,$0

        daddiu  $2,$fp,24

        move    $4,$2

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev)($28)

        move    $25,$2

        nop

        move    $2,$16

        b       .L18

        nop

        move    $16,$4

        daddiu  $2,$fp,64

        move    $4,$2

        ld      $2,%call16(_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev)($28)

        move    $25,$2

        nop

        b       .L15

        nop

        move    $16,$4

.L15:

        daddiu  $2,$fp,24

        move    $4,$2

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev)($28)

        move    $25,$2

        nop

        move    $2,$16

        move    $4,$2

        ld      $2,%call16(_Unwind_Resume)($28)

        move    $25,$2

        nop

.L18:

        move    $sp,$fp

        ld      $31,488($sp)

        ld      $fp,480($sp)

        ld      $28,472($sp)

        ld      $16,464($sp)

        daddiu  $sp,$sp,496

        j       $31

        nop

__static_initialization_and_destruction_0(int, int):

        daddiu  $sp,$sp,-48

        sd      $31,40($sp)

        sd      $fp,32($sp)

        sd      $28,24($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(__static_initialization_and_destruction_0(int, int))))

        daddu   $28,$28,$25

        daddiu  $28,$28,%lo(%neg(%gp_rel(__static_initialization_and_destruction_0(int, int))))

        move    $3,$4

        move    $2,$5

        sll     $3,$3,0

        sw      $3,0($fp)

        sll     $2,$2,0

        sw      $2,4($fp)

        lw      $3,0($fp)

        li      $2,1                        # 0x1

        bne     $3,$2,.L21

        nop

        lw      $3,4($fp)

        li      $2,65535                    # 0xffff

        bne     $3,$2,.L21

        nop

        ld      $2,%got_page(_ZStL8__ioinit)($28)

        daddiu  $4,$2,%got_ofst(_ZStL8__ioinit)

        ld      $2,%call16(_ZNSt8ios_base4InitC1Ev)($28)

        move    $25,$2

        nop

        ld      $6,%got_disp(__dso_handle)($28)

        ld      $2,%got_page(_ZStL8__ioinit)($28)

        daddiu  $5,$2,%got_ofst(_ZStL8__ioinit)

        ld      $4,%got_disp(_ZNSt8ios_base4InitD1Ev)($28)

        ld      $2,%call16(__cxa_atexit)($28)

        move    $25,$2

        nop

.L21:

        nop

        move    $sp,$fp

        ld      $31,40($sp)

        ld      $fp,32($sp)

        ld      $28,24($sp)

        daddiu  $sp,$sp,48

        j       $31

        nop

_GLOBAL__sub_I_main:

        daddiu  $sp,$sp,-32

        sd      $31,24($sp)

        sd      $fp,16($sp)

        sd      $28,8($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(_GLOBAL__sub_I_main)))

        daddu   $28,$28,$25

        daddiu  $28,$28,%lo(%neg(%gp_rel(_GLOBAL__sub_I_main)))

        li      $5,65535                    # 0xffff

        li      $4,1                        # 0x1

        ld      $2,%got_page(__static_initialization_and_destruction_0(int, int))($28)

        daddiu  $2,$2,%got_ofst(__static_initialization_and_destruction_0(int, int))

        move    $25,$2

        nop

        move    $sp,$fp

        ld      $31,24($sp)

        ld      $fp,16($sp)

        ld      $28,8($sp)

        daddiu  $sp,$sp,32

        j       $31

        nop

DW.ref.__gxx_personality_v0:

I believe this is working well pls upvote


Related Solutions

#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() {...
#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() { ifstream infile("worldpop.txt"); vector<pair<string, int>> population_directory; string line; while(getline(infile, line)){ if(line.size()>0){ stringstream ss(line); string country; int population; ss>>country; ss>>population; population_directory.push_back(make_pair(country, population)); } } cout<<"Task 1"<<endl; cout<<"Names of countries with population>=1000,000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second>=1000000000){ cout<<population_directory[i].first<<endl; } } cout<<"Names of countries with population<=1000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second<=1000000){ cout<<population_directory[i].first<<endl; } } } can u pls explain the logic behind this code up to 10 lines pls, many thanks
#include <iostream> using namespace std; int main() {     int hour;     int min;     for (hour = 1;...
#include <iostream> using namespace std; int main() {     int hour;     int min;     for (hour = 1; hour <= 12; hour++)     {         for (min = 0; min <= 59; min++)         {             cout << hour << ":" << min << "AM" << endl;         }     }       return 0; } 1.      Type in the above program as time.cpp. Add a comment to include your name and date. Compile and run. 2.      What is the bug or logic error in the above program? Add the...
#include <iostream> #include <fstream> #include <string> using namespace std; const int QUIZSIZE = 10; const int...
#include <iostream> #include <fstream> #include <string> using namespace std; const int QUIZSIZE = 10; const int LABSIZE = 10; const int PROJSIZE = 3; const int EXAMSIZE = 3; float getAverage(float arr[], int size) { float total = 0; for (int i = 0; i < size; i++) { total += arr[i]; } return total/size; } // the following main function do.... int main() { ifstream dataIn; string headingLine; string firstName, lastName; float quiz[QUIZSIZE]; float lab[LABSIZE]; float project[PROJSIZE]; float midExam[EXAMSIZE];...
#include <iostream> #include <iomanip> using namespace std; int main() {     int studentid, numberreverse[20], count =...
#include <iostream> #include <iomanip> using namespace std; int main() {     int studentid, numberreverse[20], count = 0, maximum = 0, minimum = 0;     cout << "Enter your student ID number: ";     cin >> studentid;     cout << "Student ID Number = " << studentid << endl;     while (studentid != 0)     {          numberreverse[count] = studentid % 10;          if (count == 0)          {              minimum = numberreverse[count];              maximum = minimum;          }          else...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int end) { for (int i = start; i <= end; i++) cout << items[i] << " "; cout << endl; } //The legendary "Blaze Sort" algorithm. //Sorts the specified portion of the array between index start and end (inclusive) //Hmmm... how fast is it? /* void blazeSort(double * items, int start, int end) { if (end - start > 0) { int p =...
write the algorithm for this the code?!. #include<iostream> using namespace std; #include<string.h> int main() { char...
write the algorithm for this the code?!. #include<iostream> using namespace std; #include<string.h> int main() { char plain[50], cipher[50]="", decrypt[50]=""; int subkeys[50], len;       cout<<"Enter the plain text:"<<endl; cin>>plain;    cout<<"Enter the first subkey:"<<endl; cin>>subkeys[0];    _strupr(plain);    len = strlen(plain);    /**********Find the subkeys**************/    for(int i=1; i<len; i++) { if ((plain[i-1]>='A') && (plain[i-1]<='Z')) { subkeys[i] = plain[i-1]-65; } }    /****************ENCRYPTION***************/       for(int i=0; i<len; i++) { if ((plain[i]>='A') && (plain[i]<='Z')) {    cipher[i] = (((plain[i]-65)+subkeys[i])%26)+65; }...
c++ #include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start,...
c++ #include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int end) { for (int i = start; i <= end; i++) cout << items[i] << " "; cout << endl; } //The legendary "Blaze Sort" algorithm. //Sorts the specified portion of the array between index start and end (inclusive) //Hmmm... how fast is it? /* void blazeSort(double * items, int start, int end) { if (end - start > 0) { int p...
#include <string> using namespace std; //using recursion no loops allowed int main() { double nums[] =...
#include <string> using namespace std; //using recursion no loops allowed int main() { double nums[] = { 13.8, 2.14, 51, 82, 3.14, 1.7, 4.89, 18, 5, 23.6, 17, 48, 5.6 };   //Challenge #2: print the list from given range   printList(nums, 0, 12); //13.8 2.14 51 .... 48 5.6   cout << endl;   //Challenge #3: print the list, but backwards   printReverse(nums, 0, 12); //5.6 48 17 ... 2.14 13.8   cout << endl;                  //Challenge #4: reverse order of items in list   reverse(nums,...
#include<iostream> #include<cmath> using namespace std; int p = 7; void main() { extern double var ;...
#include<iostream> #include<cmath> using namespace std; int p = 7; void main() { extern double var ; int p = abs(-90); cout << ::p + p - var << endl; system("pause"); } double var = 5.5;
I want Algorithim of this c++ code #include<iostream> using namespace std; int main() { char repeat...
I want Algorithim of this c++ code #include<iostream> using namespace std; int main() { char repeat = 'y'; for (;repeat == 'y';){ char emplyeename[35]; float basic_Salary,EPF, Dearness_Allow, tax, Net_Salary , emplyee_id; cout << "Enter Basic Salary : "; cin >> basic_Salary; Dearness_Allow = 0.40 * basic_Salary; switch (01) {case 1: if (basic_Salary <= 2,20,00) EPF = 0; case 2: if (basic_Salary > 28000 && basic_Salary <= 60000) EPF = 0.08*basic_Salary; case 3: if (basic_Salary > 60000 && basic_Salary <= 200000)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT