Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ADT/ADTV9.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
162 lines (142 sloc)
5.05 KB
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
#include <iostream> | |
#include <sqlite3.h>//for SQL | |
#include <stdio.h> //for SQL | |
#include <string> | |
#include <map> //decide which to use | |
#include <array> | |
#include <iterator> | |
#include <algorithm> | |
#include <locale> // caps converter || http://www.cplusplus.com/reference/cctype/toupper/ | |
#include "libsqlite.hpp"//Needed to add SQL | |
#ifndef MAIN_H | |
#define MAIN_H | |
#include <vector> | |
using namespace std; | |
bool duplicate; //works but doesn't reset the variable | |
class unfairSet{ // unfairSet CHANGE NAME | |
public: | |
vector<char>data; | |
vector<char>caps; // added to help get rid of duplicates | |
void add(char elem); | |
bool is_in(char elem); //bool because answer is either yes or no | |
int size(); | |
void remove(char elem); | |
}; | |
#endif | |
// function handles adding new characters to the vector | |
void unfairSet::add(char elem) | |
{ | |
// bool duplicate; //declare the variable | |
// bool * duplicatePointer; //declare the pointer for duplicatePointer | |
// duplicatePointer = &duplicate;//give the pointer a memory address | |
vector <char> caps = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; | |
if (find(caps.begin(), caps.end(), elem) != caps.end()) //checks if char is uppercase | |
{ | |
data.push_back(elem); //added if char is uppercase | |
//cout <<"char '" << elem <<"' implemented" << endl; | |
// cout << "The size of the vector is " << data.size() << endl; | |
} | |
else if(find(data.begin(), data.end(), elem) != data.end()) //if char is already in vector you get error message | |
{ | |
cout << "You have already got '" << elem << "' in the vector" << endl; | |
cout << "The size of the vector is " << data.size() << endl; | |
} | |
else //else statement to add lowercase char if not already in the vector | |
{ | |
data.push_back(elem); | |
// cout <<"CHAR '" << elem <<"' implemented" << endl; | |
// cout << "The size of the vector is " << data.size() << endl; | |
} | |
} | |
int unfairSet::size() | |
{ | |
data.size(); | |
//cout << data.size() << "erg" << endl; //prints out correct size | only in this function | |
} | |
bool unfairSet::is_in(char elem) // function finds chosen character | |
{ | |
if (find(data.begin(), data.end(), elem) != data.end())//added if statement to see if char in vect | |
{ | |
cout << "'" << elem << "' Is in vector ************" << endl; | |
cout << "" << endl; | |
return true; | |
} | |
else | |
{ | |
cout << "'" << elem << "' is not in the vector" << endl; | |
return false; | |
} | |
} | |
//^^^^^^ WOKRING | |
// // function handles deleting chosen character from the vector | |
void unfairSet::remove(char elem) | |
{ | |
vector<char>::iterator f = find(data.begin(), data.end(), elem );//iterator to find the first char in the vector | |
if (f != data.end()) //checks if char is in the vector | |
{ | |
data.erase(f); //deletes the found vector | |
//data.erase(std::remove(data.begin(), data.end(), elem), data.end());//code to delete a character | |
cout <<"CHAR '" << elem << "' unimplemented" << endl; | |
cout << "The size of the vector is " << data.size() << endl; | |
} | |
else | |
{ | |
cout <<"CHAR '" << elem << "' NOT IN VECTOR" << endl; | |
cout << "The size of the vector is " << data.size() << endl; | |
} | |
} | |
int main() | |
{ | |
string filmName; | |
int pkey; | |
int loopCount = 0; | |
//cout << "test" << endl; | |
//SQL not able to get film names in a variable | |
// | |
//should i have the bulk of SQL in a funcion by itself and filmName variable?? | |
{ | |
try //does this need to be in a function of its own? | |
{ | |
string sqliteFile = "film.sqlite"; //pulls the SQL table info | |
sqlite::sqlite db( sqliteFile ); | |
auto cur1 = db.get_statement(); | |
cur1->set_sql("SELECT pkey, title " // needed to add a space after title for the SQL to work | |
"FROM unfairset_eg "); //added limit just to test 5 records | |
//do i need to add placeholders as this is not a dynamic query??? | |
cur1->prepare(); // runs the query | |
while (cur1-> step()) // this while loop should show all the results in the table | |
{ | |
// cout << cur1->get_text(0) << " " << cur1->get_text(1) << << endl; | |
filmName = cur1 -> get_text(1);//assigns the film name to this variable | |
pkey = cur1 -> get_int(0); | |
unfairSet ADT;// cant have 'ADT()' must be 'ADT' by itself | |
for (char c : filmName)// will sort out into characters | |
{ | |
ADT.add(c); | |
if (filmName.length() == ADT.size()) | |
{ | |
// cout << filmName << "1" << endl; | |
} | |
else | |
{ | |
// cout << filmName << "2" << endl; | |
if(loopCount == ADT.size()) | |
{ | |
cout << pkey << " " << filmName <<endl; | |
cout << " " <<endl; | |
break; //breaks at the first sign of a duplicate | |
} | |
} | |
loopCount = loopCount +1; | |
} | |
// cout << loopCount << endl; | |
loopCount = 0; | |
} | |
} | |
catch( sqlite::exception e ) // catch all sql issues | |
{ | |
cout << std::cerr << e.what() << std::endl; | |
return 0; | |
} // there are 1000 records, how to perform the loop effiently? | |
} | |
} |