Skip to content
Permalink
Browse files
random beverage program pushed by mockk
  • Loading branch information
mockk committed Mar 7, 2019
1 parent c8f5b89 commit 56e178bec369cf1c7342ab211c5be433dd6fb4f8
Show file tree
Hide file tree
Showing 4 changed files with 10,503 additions and 0 deletions.
34 dbcon.h
@@ -0,0 +1,34 @@
#include "db.h" //a header file for reading records from the database, written by Ben.
#include <iostream>
#include <vector>
#include <string>
using namespace std;

vector<string> read()
{
Database *db;
db = new Database("cocktail-db.db");
string query_str;
query_str="SELECT Bev_Name FROM Beverage;";
vector<Row> result = db->query(query_str);
vector<string> bev;

for (int i=0;i<result.size();++i)
{
vector<string> columnsInRow = result[i].getColumns();

for (int j=0;j<columnsInRow.size();++j)
{
//cout<<columnsInRow[j]<<endl;
bev.push_back(columnsInRow[j]);
}
}
db->close();
/* checking results
for (int k=0;k<bev.size();++k)
{
cout << bev[k] <<endl;
}
*/
return bev;
}
@@ -0,0 +1,14 @@
#include <iostream>
#include <string>
#include "randBev.h"
#include "db.h"
#include <vector>
#include "dbcon.h"
using namespace std;

int main()
{
vector<string> bev = read();
cout << "I want " << randChoice(bev) << " pls!" << endl;
return 0;
}
@@ -0,0 +1,13 @@
#include <cstdlib>
#include <iostream>
#include <string>
#include <ctime>
#include <vector>
using namespace std;

string randChoice(vector<string> sarr)
{
srand(time(nullptr)); //"true" random numbers (?)
int randNo= rand() % sarr.size();
return sarr[randNo];
}

0 comments on commit 56e178b

Please sign in to comment.