In MIPS Assembly language coding on MARS 4.5: Develop a program that takes a har
ID: 3606667 • Letter: I
Question
In MIPS Assembly language coding on MARS 4.5:
Develop a program that takes a hardcoded statement, and asks the user for two different input words such as "UCF" and "KNIGHTS". Any words less than 10 characters will be accepted into the input.
Then the output should find how many times the user input word is given in the hardcoded statement. (the frequency of the word)
This program should not be case sensitive and regardless of the way user inputs the words, it should correctly find how many words in the statement. It can find any word in the sentence. For example, the user inputs "was" and "the", it will count how many times those words are in the statement.
Hardcoded statement:
"The mascot of UCF was chosen as the Knights. The Knights of Pegasus was a submission put forth by the students, staff and facult. UCF's original mascot was the Citronaut."
Sample Output Example:
Please input first word: Knight (or KnIGhT, knight, ..) Please input second word: UCF (or ucf, UcF,... KNIGHT: 6 UCF: 3Explanation / Answer
#include<iostream>
#include<string>
#include<sstream>
#include <algorithm>
using namespace std;
int main(){
string word1;
string word2;
string word;
std::size_t found;
string data = "The mascot of UCF was chosen as the Knights. The Knights of Pegasus was a submission put forth by the students, staff and facult. UCF's original mascot was the Citronaut.";
std::transform(data.begin(), data.end(), data.begin(), ::tolower);
cout << "Plese input first word: ";
cin >> word1;
cout << "Plese input second word: ";
cin >> word2;
std::transform(word1.begin(), word1.end(), word1.begin(), ::tolower);
std::transform(word2.begin(), word2.end(), word2.begin(), ::tolower);
stringstream iss(data);
int count1 = 0;
int count2 = 0;
while (iss >> word){
found = word.find(word1);
if (found != string::npos)
count1++;
found = word.find(word2);
if (found != string::npos)
count2++;
}
cout << word1 << " = " << count1 << endl;
cout << word2 << " = " << count2 << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.