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/ADTV6.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
165 lines (142 sloc)
4.82 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; | |
class testclass{ // 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 testclass::add(char elem){ | |
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 in the vector | |
{ | |
data.push_back(elem); | |
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()) | |
{ | |
cout << "You have already got '" << elem << "' in the vector" << endl; | |
cout << "The size of the vector is " << data.size() << endl; | |
} | |
else | |
{ | |
data.push_back(elem); | |
cout <<"CHAR '" << elem <<"' implemented" << endl; | |
cout << "The size of the vector is " << data.size() << endl; | |
} | |
} | |
int testclass::size() | |
{ | |
cout << data.size() << "erg" << endl; //prints out correct size | only in this function | |
} | |
//^^need to fix | |
bool testclass::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 testclass::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; | |
} | |
// need to add code to remove duplicates !!!!!!!!!!!!!!! | |
} | |
int main(){ | |
testclass unfairSet; | |
unfairSet.add('A');// can't be "" to add char but must be '' | |
cout << "size should now be 1 is actually " << unfairSet.size() << endl; | |
unfairSet.add('a'); | |
unfairSet.add('a'); | |
unfairSet.add('A'); | |
unfairSet.add('b'); | |
unfairSet.add('B'); | |
unfairSet.add('A'); | |
unfairSet.add('H'); | |
unfairSet.add('e'); | |
unfairSet.add('e'); | |
unfairSet.add('h'); | |
unfairSet.add('c'); | |
unfairSet.add('a'); | |
unfairSet.add('a'); | |
unfairSet.add('H'); | |
unfairSet.is_in('h'); | |
unfairSet.remove('h'); | |
unfairSet.remove('B'); | |
unfairSet.remove('A'); | |
unfairSet.remove('e'); | |
unfairSet.remove('A'); | |
unfairSet.remove('e'); | |
cout << "The size of THE VECTOR is " << unfairSet.size() << endl; | |
string filmName; | |
//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 LIMIT 0,1 "); //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 << "" << endl; | |
filmName = cur1 -> get_text(1);//assigns the film name to this variable | |
testclass a;// cant have a() must be a by itself | |
for (char c : filmName)// will sort out into characters | |
{ | |
a.add(c); | |
//cout << c << endl; | |
} | |
} | |
} | |
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? | |
} | |
} |