Skip to content

Commit

Permalink
lägga till allt
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Lööf committed Feb 7, 2014
1 parent 5a18195 commit 3c01d86
Show file tree
Hide file tree
Showing 11 changed files with 99,321 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Define the compiler and the linker. The linker must be defined since
# the implicit rule for linking uses CC as the linker. g++ can be
# changed to clang++.
CXX = g++
CC = g++

# Define preprocessor, compiler, and linker flags. Uncomment the # lines
# if you use clang++ and wish to use libc++ instead of GNU's libstdc++.
# -g is for debugging.
CPPFLAGS = -std=c++11
CXXFLAGS = -O2 -Wall -Wextra -pedantic-errors -Wold-style-cast
CXXFLAGS += -std=c++11
CXXFLAGS += -g
LDFLAGS = -g
#CPPFLAGS += -stdlib=libc++
#CXXFLAGS += -stdlib=libc++
#LDFLAGS += -stdlib=libc++

# Targets
PROGS = preprocessor

all: $(PROGS)

# Targets rely on implicit rules for compiling and linking
preprocessor: preprocessor.o


# Phony targets
.PHONY: all clean

# Standard clean
clean:
rm -f *.o $(PROGS)

# Generate dependencies in *.d files
%.d: %.cc
@set -e; rm -f $@; \
$(CPP) -MM $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$

# Include the *.d files
SRC = $(wildcard *.cc)
include $(SRC:.cc=.d)
21 changes: 21 additions & 0 deletions dictionary.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <algorithm>
#include "word.h"
#include "dictionary.h"

using namespace std;

Dictionary::Dictionary() {
}

bool Dictionary::contains(const string& word) const {
return true;
}

vector<string> Dictionary::get_suggestions(const string& word) const {
vector<string> suggestions;
return suggestions;
}
1 change: 1 addition & 0 deletions dictionary.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dictionary.o dictionary.d : dictionary.cc word.h dictionary.h
15 changes: 15 additions & 0 deletions dictionary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef DICTIONARY_H
#define DICTIONARY_H

#include <string>
#include <vector>

class Dictionary {
public:
Dictionary();
bool contains(const std::string& word) const;
std::vector<std::string> get_suggestions(const std::string& word) const;
private:
};

#endif
1 change: 1 addition & 0 deletions preprocessor.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
preprocessor.o preprocessor.d : preprocessor.cc
29 changes: 29 additions & 0 deletions spell.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include "dictionary.h"

using namespace std;

int main() {
Dictionary dict;
string word;
while (cin >> word) {
transform(word.begin(), word.end(), word.begin(), ::tolower);
if (dict.contains(word)) {
cout << "Correct." << endl;
} else {
vector<string> suggestions = dict.get_suggestions(word);
if (suggestions.empty()) {
cout << "Wrong, no suggestions." << endl;
} else {
cout << "Wrong. Suggestions:" << endl;
for (const auto& w : suggestions) {
cout << " " << w << endl;
}
}
}
}
}
1 change: 1 addition & 0 deletions spell.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spell.o spell.d : spell.cc dictionary.h
15 changes: 15 additions & 0 deletions word.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <string>
#include <vector>
#include "word.h"

using namespace std;

Word::Word(const string& w, const vector<string>& t) {}

string Word::get_word() const {
return string();
}

unsigned int Word::get_matches(const vector<string>& t) const {
return 0;
}
1 change: 1 addition & 0 deletions word.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
word.o word.d : word.cc word.h
21 changes: 21 additions & 0 deletions word.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef WORD_H
#define WORD_H

#include <string>
#include <vector>

class Word {
public:
/* Creates a word w with the sorted trigrams t */
Word(const std::string& w, const std::vector<std::string>& t);

/* Returns the word */
std::string get_word() const;

/* Returns how many of the trigrams in t that are present
in this word's trigram vector */
unsigned int get_matches(const std::vector<std::string>& t) const;
private:
};

#endif
Loading

0 comments on commit 3c01d86

Please sign in to comment.