I have trouble to come up with a Boolean function as expected by the assignment. I just need some explanations as I want to write my own code. I am supposed to write a MIPS code that actually counts the number of Uppercase, Lowercase, Vowels, Consonants and Digits in a string. I am writing the code in C++, then I will translate into MIPS assembly. I pasted the requirement below followed by the way the function bool consonant(char c) should look like (idea given by my professor). The problem is that it seems I am missing some information to make that function work. Can anyone provide me more information regarding that function? I don't need a code, just the missing details. Your help will be very appreciated.
//requirement of assignment bellow
To determine if an ASCII character c is a vowel or a consonant, write two functions bool vowel(char c) and bool consonant(char c). Use the stack to pass the character argument to these functions. Avoid long conditional expressions when testing a character for being a vowel and a consonant. Instead, use two global arrays (tables) containing Boolean flags to implement vowel() and consonant(). For example, an array named is_vowel would have true for characters ’a’ and ’A’ but false for ’b’ and ’B’.
// function that returns 0 if c is a consonant, or 1 if c is not a consonant
bool consonant(char c)
{
const bool is_conson[30]={0,0,...1,1,1,0,0...};
return is_conson[c];
}
//Here is The Code (C++) that I wrote for testing purpose only using Dev-C++
#include <iostream>
#include <math.h>
#include <cstdlib>
using namespace std;
bool consonant(char c)
{
const bool is_conso[30]= {1,1,1,1,0,0,0,0,0,1,0,1,1,0,0,0,1,0,1,0,1,1,1,1,0,1,0,1,0,1};
return is_conso[c];
}
int main()
{
int i;
bool result;
char c;
char sentence[]="aaaabbbbb";
cout<<"the array: ";
cout<<sentence<<endl;
for (i=0; i<9; i++)
{
c=sentence[i];
result=consonant(c);
if (result==0)
cout<<c<<" is a Consonant"<<endl;
}
return 0;
}
'a'or'A'constants as indices to the array? - Shahbazis_conson? (hint - 30 isn't big enough) - Michael Burr