Determing if string has all unique characters

Problem
Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?

bool is_all_unique(std::string str ) {
	bool char_set[256] = { false };
	bool rc = false;
	for ( int idx = 0; idx < (int)str.length(); idx++) {
		int ascii_code = (int)str[idx];
		if (char_set[ascii_code]){
			rc = true;
			 break;
		}
		char_set[ascii_code] = true;
	}
	return rc;
}

Pangrams

Description:

The sentence ‘A quick brown fox jumps over the lazy dog’ contains every single letter in the alphabet. Such sentences are called pangrams. You are to write a program, which takes a sentence, and returns all the letters it is missing (which prevent it from being a pangram). You should ignore the case of the letters in sentence, and your return should be all lower case letters, in alphabetical order. You should also ignore all non US-ASCII characters.In case the input sentence is already a pangram, print out the string NULL
Input sample:

Your program should accept as its first argument a filename. This file will contain several text strings, one per line. Ignore all empty lines. eg.

A quick brown fox jumps over the lazy dog
A slow yellow fox crawls under the proactive dog

Output sample:

Print out all the letters each string is missing in lowercase, alphabetical order .e.g.

NULL
bjkmqz

My solution

#include <fstream>
#include <string>
#include <algorithm>
#include <iostream>

struct InvalidChar {
    bool operator()(char c) const {
        return !isprint((unsigned)c);
    }
};

void print_missing_pangrams_chars(std::string &line) {
	bool found = true;
	std::transform(line.begin(), line.end(), 
		           line.begin(), ::tolower);

	std::sort(line.begin(), line.end());

	line.erase(std::remove_if(line.begin(),
		                      line.end(),
							  InvalidChar()), 
							  line.end());

	std::string dictionary = "abcdefghijklmnopqrstuvwxyz";
	for ( std::string::iterator itr = dictionary.begin();
		itr != dictionary.end();++itr) {
			if (line.find(*itr) == std::string::npos){
				std::cout << *itr;
				found = false;
			}
	}
	if ( found )
		std::cout << "NULL";
	std::cout << std::endl;
}
int main ( int argc, char **argv) {
    std::ifstream inpFile(argv[1]);
    if ( inpFile.peek() == EOF ){
        return -1;
	} 
    std::string line; 
    if (inpFile.is_open()) {
        while (! inpFile.eof() ) {               
            std::getline (inpFile,line);
			if ( !line.empty()) {
				print_missing_pangrams_chars(line);
			}
        }
        inpFile.close();
    }
	return 0;
}

Prefix expressions

Description:
You are given a prefix expression. Write a program to evaluate it.
Input sample:
The first argument will be an input file with one prefix expression per line. e.g.

* + 2 3 4

Your program has to read this and insert it into any data structure you like. Traverse that data structure and evaluate the prefix expression. Each token is delimited by a whitespace. You may assume that the only valid operators appearing in test data are ‘+’,’*’ and ‘/’
Output sample:
Print to stdout, the output of the prefix expression, one per line. e.g.

20

My solution

#include <iostream>
#include <fstream>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <algorithm>

void Tokenize(const std::string& str, 
			  std::vector<std::string>& tokens,
			  const std::string& delimiters = " ") {
	std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
	std::string::size_type pos     = str.find_first_of(delimiters, lastPos);
	while (std::string::npos != pos || std::string::npos != lastPos){
        tokens.push_back(str.substr(lastPos, pos - lastPos));
        lastPos = str.find_first_not_of(delimiters, pos);
        pos = str.find_first_of(delimiters, lastPos);
    }
}

int string_to_int(std::string const &val) {
	std::istringstream istr(val);
	int returnVal;
	istr >> returnVal;
	return returnVal;
}

void evaluate_prefix_expression( std::string &expr) {
	std::stack<int> operand_stack;
	std::string operators = "+*/-";
	//std::reverse(expr.begin(), expr.end());
	std::vector<std::string> tokens;
	Tokenize(expr,tokens);
	for ( std::vector<std::string>::reverse_iterator itr = tokens.rbegin();
		itr != tokens.rend(); ++itr) {
			if ( operators.find(*itr) == std::string::npos) {
				operand_stack.push(string_to_int(*itr));
			}
			if ( operators.find(*itr) != std::string::npos){
				int t1 = operand_stack.top(); operand_stack.pop();
				int t2 = operand_stack.top(); operand_stack.pop();
				if ( *itr == "+") {
					operand_stack.push(t1 + t2 );
				} else if ( *itr == "*" ) {
					operand_stack.push(t1 * t2 );
				} else if ( *itr == "/" ) {
					operand_stack.push(t1 / t2 );
				} else if ( *itr == "-" ) {
					operand_stack.push(t1 - t2 );
				}

			}
	}
	std::cout << operand_stack.top() << std::endl;
}
int main( int argc, char **argv) {
    std::ifstream inpFile(argv[1]);
    if ( inpFile.peek() == EOF ){
        return -1;
	} 
    std::string line; 
    if (inpFile.is_open()) {
        while (! inpFile.eof() ) {               
            std::getline (inpFile,line);
			if ( !line.empty()) {
				evaluate_prefix_expression(line);
			}
        }
	}
	return 0;
}

Project Euler – 2

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

int Problem2() {
	long fib_array[3]; 
	fib_array[0] = 1; 
	fib_array[1] = 2; 
	long total = 2; 
	while(true) { 
		fib_array[2] = fib_array[0] + fib_array[1]; 
		fib_array[0] = fib_array[1]; 
		fib_array[1] = fib_array[2];

		if(fib_array[2] >= 4000000) 
			break; 
		if(fib_array[2] % 2 == 0) 
			total += fib_array[2]; 
	}
	return total;
}

Project Euler – 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.

int Problem1() {
	int current = 0;
	int result  = 0;
	while ( current < 1000 ) {
		if ( current % 5 == 0 || current % 3 == 0 ) {
			result += current;
		}
		current++;
	}
	return result;
}