It compiles and executes but for some reason my vectors do not initialize in the fillarrays function. What am I doing wrong?
#include <iostream>
#include <conio.h> // for getch()
#include <vector>
using namespace std;
bool and (std::vector<bool> p, std::vector<bool> q, int i); // returns bool for and
bool or (std::vector<bool> p, std::vector<bool> q, int i); // returns bool for or
bool xor (std::vector<bool> p, std::vector<bool> q, int i); // returns bool for xor
bool implies (std::vector<bool> p, std::vector<bool> q, int i); // returns bool for if then;
bool ifandif (std::vector<bool> p, std::vector<bool> q, int i); // returns bool for if and only if
void fillarrays (std::vector<bool> p, std::vector<bool> q); // initialises p and q
void dashes ();
int main ()
{
vector<bool> p, q;
int i;
fillarrays(p,q);
cout << "P|Q|P and Q\n";
dashes ();
for (i=0; i<p.size(); i++)
{
cout << p[i] << "|" << q[i] << "|" << and (p, q, i) << endl;
}
cout << "Press any key to continue.\n";
getch ();
cout << "\nP|Q|P or Q\n";
dashes ();
for (i=0; i<p.size(); i++)
{
cout << p[i] << "|" << q[i] << "|" << or (p, q, i) << endl;
}
cout << "Press any key to continue.\n";
getch ();
cout << "\nP|Q|P xor Q\n";
dashes ();
for (i=0; i<p.size(); i++)
{
cout << p[i] << "|" << q[i] << "|" << xor (p, q, i) << endl;
}
cout << "Press any key to continue.\n";
getch ();
cout << "\nP|Q|P -> Q\n";
dashes ();
for (i=0; i<p.size(); i++)
{
cout << p[i] << "|" << q[i] << "|" << implies (p, q, i) << endl;
}
cout << "Press any key to continue.\n";
getch ();
cout << "\nP|Q|P <-> Q\n";
dashes ();
for (i=0; i<p.size(); i++)
{
cout << p[i] << "|" << q[i] << "|" << ifandif (p, q, i) << endl;
}
return 0;
}
bool and (std::vector<bool> p, vector<bool> q, int i)
{
if (p[i]&&q[i]==true)
return true;
else return false;
}
bool or (std::vector<bool> p, vector<bool> q, int i)
{
if (p[i]||q[i]==true)
return true;
else return false;
}
bool xor (std::vector<bool> p, vector<bool> q, int i)
{
if (p[i]&&q[i]==true)
return false;
else if (p[i]||q[i]==true)
return true;
else return false;
}
bool implies (std::vector<bool> p, std::vector<bool> q, int i)
{
if ((p[i]==false)&&(q[i]==false))
return true;
else if (q[i]==true)
return true;
else return false;
}
bool ifandif (std::vector<bool> p, std::vector<bool> q, int i)
{
if (((p[i]==true)&&(q[i]==true))||((p[i]==false)&&(q[i]==false)))
return true;
else return true;
}
void fillarrays (std::vector<bool> p, std::vector<bool> q)
{
p.push_back(true);
q.push_back(true);
p.push_back(true);
q.push_back(false);
p.push_back(false);
q.push_back(true);
p.push_back(false);
q.push_back(false);
}
void dashes ()
{
cout << "-------------------" << endl;
}