Article View: alt.comp.lang.learn.c-c++
Article #662Accessing bool table from char string
From: Jeffery J Connell
Date: Mon, 27 Mar 2000 00:00
Date: Mon, 27 Mar 2000 00:00
63 lines
2599 bytes
2599 bytes
Beginner-simple code, any help/explanation would be great. I've gotten to
the point where I need to return a bool value from thearray that corresponds
with the input of 2 char values.
Here's what I have so far:
const int numofels=6;
char opchar[numofels]={'+','-','*','/','^','('};
bool precedence (char incomer, char topvalue);
int search (char incomer, char opchar[]);
int search1 (char topvalue, char opchar[]);
int main ()
{
cout.setf(ios::fixed, ios::floatfield);
cout.setf(ios::showpoint);
cout.precision(2);
char incomer;
char topvalue;
cout<<"incomer";
cin>>incomer;
incomer=search (incomer, opchar);
cout<<"topvalue";
cin>>topvalue;
topvalue=search1 (topvalue, opchar);
cout<<"The value is: "<<precedence (incomer,topvalue);
return 0;
}
bool precedence (char incomer, char topvalue)
{
bool table [6][6]=
{
{false,false,false,false,false,true},
{false,false,false,false,false,true},
{true,true,false,false,false,true},
{true,true,false,false,false,true},
{true,true,true,true,true,true},
{true,true,true,true,true,true},
};
return table [incomer][topvalue];
}
int search (char incomer, char opchar[])
{
for (int i=0; i<6; i++)
if (incomer==opchar[i])
cout<<i<<endl;
return i;
}
int search1 (char topvalue, char opchar[])
{
for (int j=0; j<6; j++)
if (topvalue==opchar[j])
cout<<j<<endl;
return i;
}
Technical Details
Message-ID:
<8bpa9j$78qu$1@node17.cwnet.frontiernet.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8a20,f3bf3a7b6fb22f27,start X-Google-Attributes: gidf8a20,public X-Google-Thread: 10b7bb,f3bf3a7b6fb22f27,start X-Google-Attributes: gid10b7bb,public X-Google-Thread: 109fba,f3bf3a7b6fb22f27,start X-Google-Attributes: gid109fba,public X-Google-Thread: 114592,f3bf3a7b6fb22f27,start X-Google-Attributes: gid114592,public X-Google-Thread: fd559,f3bf3a7b6fb22f27,start X-Google-Attributes: gidfd559,public From: "Jeffery J Connell" <connelj@frontiernet.net> Subject: Accessing bool table from char string Date: 2000/03/27 Message-ID: <8bpa9j$78qu$1@node17.cwnet.frontiernet.net> X-Deja-AN: 603249268 X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 X-Complaints-To: abuse@frontiernet.net X-Trace: node17.cwnet.frontiernet.net 954215539 238430 209.130.150.88 (28 Mar 2000 03:52:19 GMT) Organization: Frontier GlobalCenter Inc. X-MSMail-Priority: Normal NNTP-Posting-Date: 28 Mar 2000 03:52:19 GMT Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c++,ctdl.lang.c++,ncf.sigs.c++-prog,symantec.support.devtools.pc.sc++