Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
#include <iostream>
#include <sqlite3.h>//for SQL
#include <stdio.h> //for SQL
#include <string>
#include <iterator>
#include <algorithm>
#include "libsqlite.hpp"//Needed to add SQL
#ifndef MAIN_H
#define MAIN_H
#include <vector>
using namespace std;
class unfairSet//
{
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
void unfairSet::add(char elem)// function handles adding new characters to the vector
{
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
}
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);
}
}
int unfairSet::size()//Function tells you the size of the current vector
{
data.size();
}
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;
}
}
// // 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
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;
try
{
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 ");
//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
{
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())
{
}
else
{
if(loopCount == ADT.size())
{
cout << pkey << " " << filmName <<endl;
cout << " " <<endl;
break; //breaks at the first sign of a duplicate
}
}
loopCount = loopCount +1;
}
loopCount = 0;
}
}
catch( sqlite::exception e ) // catch all sql issues
{
cout << std::cerr << e.what() << std::endl;
return 0;
}
}