Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
10,503 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]; | ||
} |
Oops, something went wrong.