469,575 Members | 1,668 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

Switch Operator

ok I have to do the following to a previous program

A) Modify the program loop such that a ‘SWITCH’ structure is used to call each of the FUNCTIONS which display the individual Logical Operator Truth Tables, and
B) Upon terminating the program, display a message as follows:
“Thank you for using the Logical
Operator Truth Table Display Program:
‘Your full name’ “

Here's the program. Need advice on switch structure and how to displat that message
// Asgn4.cpp
// March 4,2008
// 2:35 pm
// Program that uses function to display
// truth tables for the Logical And,
// Logical Or, and Logical Not operators

#include <iostream>
using std::cout; // outputs data
using std::endl; // endline
using std::cin; //inputs data
using std::boolalpha; // causes bool values to print as "true" or "false"
void AND ()
void OR ()
void NOT ()

// program has to display truth table at user's will and loop until user quits
int main()

{
int a, b; // variables to store user input

do {
cout << "Choose one truth table to display:";
cin >> a; // input for truth table to display
if ( a == 1)
AND ();
// if user chooses 1 display logical and truth table

if ( a == 2)
OR ();
// if user chooses 2 display logical or truth table

if ( a == 3 )
NOT ();
// if user chooses 3 display logical not truth table

// loop until user quits
cout<<"Do you want to quit? Press 1 to quit or 0 to display another truth table \n";
cin>>b; // input answer for continuance
cout<<endl;
} while ( b!= 1 ); // input of one needed to terminate

return 0; // indicate successful termination
}

void AND()
{
// create truth table for && (logical AND) operator
// make function
cout << boolalpha << "Logical AND (&&)"
<< "\nfalse && false: " << ( false && false )
<< "\nfalse && true: " << ( false && true )
<< "\ntrue && false: " << ( true && false )
<< "\ntrue && true: " << ( true && true ) << "\n\n";
}
void OR ()
{
// create truth table for || (logical OR) operator
// make function
cout << boolalpha << "Logical OR (||)"
<< "\nfalse || false: " << ( false || false )
<< "\nfalse || true: " << ( false || true )
<< "\ntrue || false: " << ( true || false )
<< "\ntrue || true: " << ( true || true ) << "\n\n";
}
void NOT ()
{
// create truth table for ! (logical negation) operator
cout << boolalpha << "Logical NOT (!)"
<< "\n!false: " << ( !false )
<< "\n!true: " << ( !true ) << endl;
cout <<"\n";
}
Mar 17 '08 #1
1 2193
weaknessforcats
9,208 Expert Mod 8TB
Just:

Expand|Select|Wrap|Line Numbers
  1. switch(a)
  2. {
  3.     case 1:
  4.         etc...
  5.         break;
  6. }
  7.  
You can only switch on an integer value.

This should be in any textbook.
Mar 17 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by clueless_google | last post: by
13 posts views Thread by webzila | last post: by
7 posts views Thread by Tim Cowan | last post: by
27 posts views Thread by Yuriy Solodkyy | last post: by
1 post views Thread by babysweet | last post: by
2 posts views Thread by Miyagi | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.