C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language.

learn more… | top users | synonyms

3
votes
2answers
23 views

Value Iteration Implementation for MDPs

I've been working for a while on a decision theory library, and since I've never really had any formal training in code best practices I'd love to hear your feedback. This particular class is one of ...
0
votes
1answer
22 views

Stack with minimum implementation [on hold]

My homework is to write an implementation of a stack with minimum. Could you please tell me if my implementation is correct? And, if it is correct, how to make it better? My most concern is about the ...
6
votes
3answers
112 views

Scorekeeper for a game

The code is not for any project, I just want to know the best coding practices. The code is also on GitHub. ...
-4
votes
0answers
22 views

Overloaded Operators [on hold]

May someone please help me with the following problem on overloaded operators: Consider the mathematical construct of a matrix (http://mathworld.wolfram.com/Matrix.html) Create an Abstract Data Type ...
3
votes
2answers
42 views

Emulating __uint128_t

I developed a lot of code locally with __uint128_t only to find out that it is not available on the target platform. I am now trying to write my own struct that ...
6
votes
1answer
46 views

Bitmap problem performance boost

Problem statement: Input is a rectangular bitmap like this: 0001 0011 0110 The task is to find for each black (0) "pixel", the distance to the ...
0
votes
0answers
38 views

Handling infinities in this numerical integration method [on hold]

I have written a parallelized version of Gauss-Laguerre quadrature and am wondering how best to handle infinities that occur due to lack of floating-point precision. Basically, I use Newton's method ...
5
votes
1answer
37 views

File validator configured using XML

I am making an application to check for any files that does not follow a specific pattern defined in a XML file. The application works well, but the source code is not the greatest, and memory ...
4
votes
3answers
498 views

STL Queue Implementation

I've implemented a simple C++ STL like queue. (I've tried to follow @LokiAstari stack implementation code fashion) ...
1
vote
2answers
89 views

Binary search as a generic algorithm

I am upgrading my C++11 knowledge and repeating some essential algorithm. Here is binary search only in terms of iterators. ...
5
votes
1answer
44 views

Diagonal gradient optimization

With the SDL library, I'm creating an SDL_Surface* at w and h dimensions. SDL_Color is a struct with 4 ...
7
votes
2answers
71 views

Entity management design & smart pointers

I'd like to get some guidance on whether or not I'm approaching my design the correct way, especially with regards to usage of smart pointers and references. I've started developing a small game ...
6
votes
3answers
526 views

STL Vector Implementation

I've implemented a simple vector like STL C++. ...
10
votes
2answers
90 views

Parsing of a (Linux) netlink hotplug uevent packet

The netlink service is used, among other things, to notify userspace about hotplug events (e.g. "a device has been connected"). These events come in the form of packets, which follow the following ...
9
votes
3answers
578 views

Clean code attempt at ATM problem on codechef.com

The problem asks you to take an integer (debit amount) and a double (credit or initial balance amount) and process the requested debit verifying that 1 it's a multiple of the minimum denomimation ...
12
votes
2answers
123 views

Thread pool worker implementation

As an exercise in using C++11 features I decided to make a thread pool class. I would like to have a review on the code with focus on: Standards compliance / Portability issues / Best practices ...
-6
votes
0answers
59 views

decrement operator c++ - n queens reduce operations [closed]

While we wrote this code n-warp.cpp we made us two questions: Are we making an incorrect use of the increment and decrement operators? Or is there some limitation with this operators, which we don't ...
3
votes
2answers
47 views

Creating polls and calculator with custom functions and without any global variable

I solved this problem using custom functions and calling them in main function. The challenge was to avoid global variables. Please note that I'm C++ noob and this program is fairly large. I'm ...
0
votes
0answers
28 views

Solving Subset problem in a recursive way [closed]

I have tried to solve the following problem but I still get wrong answer, however the two test cases in the problem are correct answer for me. Problem Statement: Subsets Sum, or "SS" (double S) for ...
-3
votes
0answers
77 views

Reducing operations in n-queens implementation [closed]

We're trying to write our fastest code to solve the n-queens problem. We made our best effort to reduce the number of operations per iteration. We wrote this code and we have two questions related to ...
6
votes
1answer
103 views

Bluetooth door-opener program

I've been working on a little project on an Arduino and I need some help with making the code more efficient / cleaner. I really don't like the three for loops. I ...
5
votes
3answers
171 views

Determine whether one vector is a prefix of the other

Exercise 5.17: Given two vectors of ints, write a program to determine whether one vector is a prefix of the other. For vectors of unequal length, ...
7
votes
2answers
73 views

Generic absolute value function

I wanted to write a generic abs function that would correctly work for every type. Basically, I wanted to use the following algorithm: If the type is a built-in ...
1
vote
0answers
29 views

Wrapping boost accumulators

Here is a namespace for wrapping boost accumulators for use in a broader code base. I love these accumulators but re-typedefing them everywhere is ugly and a pain. ...
4
votes
1answer
75 views

Cart mover- OOP usage and learning design patterns

Firstly, I would like to say that this site looks fantastic... I haven't tried it out yet, but I'm coming from SO, so I think it will be great. My code is for a simple "cart-creation" class and ...
4
votes
2answers
88 views

Converting a string to various number formats

I'm working on a set of PostgreSQL helper classes, and am representing each PostgreSQL data type as objects. Instead of creating a class for each number format, I've created a template so the user can ...
23
votes
6answers
4k views

Printing lyrics of 99 Bottles of Beer

I wrote a C++ program for 99 Bottles of Beer, but it's kind of messy. Is there any way I can make it short and cleaner and more easier to read? ...
2
votes
1answer
46 views

Producer - Consumer interaction

I have an implementation of Producer-Consumer multi-threaded interaction.It works.But I feel that during the execution wait states happen too often between Consumer ...
8
votes
2answers
411 views

Clean code attempt on codechef.com FCTRL

I have been reading Clean Code and decided to start working problems on Codechef.com attempting to apply some of what I have learned. Do I seem to be on the right track or am I way off? The ...
5
votes
0answers
62 views

PostgreSQL datatypes for libpq in c++

Following on from my earlier question: Very simple PostgreSQL ORM in C++ using libpq (tldr; I'm creating a set of helper classes for working with libpq) I've decided to have another attack at the ...
8
votes
1answer
101 views

Very simple PostgreSQL ORM in C++ using libpq

I'm working on a set of helper classes for working with libpq in C++ and I want to be able to pass in objects to the helper classes and have them internally represented as strings when sent to the db, ...
11
votes
3answers
176 views

Substitution cipher algorithm performance boost

This algorithm is meant to read a string of numbers on an input, a naive substitution cipher code (A = 1, B = 2, ..., Z = 26) and output the number of ways the code could be interpreted (e.g. 25114 ...
3
votes
2answers
61 views

contains() algorithm for std::vector

I wrote the following function for the purpose of reusability: ...
1
vote
0answers
57 views

Optimizing implementation of Dijkstra

I am using a std::priority_queue to implement Dijkstra's algorithm: ...
6
votes
3answers
332 views

Shuffling function using rand()

I would like to hear your suggestions about my shuffling function in C++. I've decided to take advantage of using rand() to build a shuffling function. ...
2
votes
0answers
47 views

CRTP object counter to track accidental singleton instantiation

I have used CRTP to implement an object counter for singleton classes. This way I can keep track of accidental attempts to instantiate more than one object. It is a header only class: ...
4
votes
2answers
132 views

Game framework using C++

I'm writing my own game framework and would like to get feedback on the API while I'm writing it. At the moment it's very simple, but I would like some guidance about where to take it. This is a ...
19
votes
5answers
2k views

Aliens at the train

I solved this problem on SPOJ: The aliens have arrived to Earth and everything is in harmony, the two races can live together. However, one specific Female Alien does not want to see humans ...
5
votes
2answers
96 views

Messy handler for multiple touch events in a game

I have mobile game that has a handler for touch events. What it does is: main function that get the touch loop in module A all sprites check if the touch coordinates are in the boundary of one of ...
3
votes
2answers
194 views

Checking whether a given timestamp is more than two weeks old

I am trying to see whether a given timestamp is more than two weeks old or not. If it is two weeks old, then print out "Hello" and if it is not more than two weeks old then print out "World". I have ...
12
votes
2answers
375 views

Efficiency/design of trim() library code

I am working on some library code and I am trying to optimize my trim() functions. To that effect I am trying to figure out how best to deal with each kind of ...
5
votes
2answers
96 views

Throw exception in constructor bad or good practice

I am doing a code review and I have encountered a class in an application that is throwing an exception in the constructor: ...
3
votes
2answers
122 views

Generic Sudoku solver might have too many iterations

I'm trying to implement a generic Sudoku solver (with n x n puzzles). The puzzle itself is contained in the class Feld with: ...
4
votes
3answers
282 views

Google Code Jam - Store Credit

Below is my answer to the Google Code Jam's answer to the Store Credit. As usual the code run's perfectly well, however, my credit_pos function gives a warning when ...
8
votes
3answers
377 views

Stock Pipe Cutting using Recursion

This problem is from the Stanford Open Course CS106B Programming Abstractions Assignment #3 Problem number 6 here. "You are charged with buying the plumbing pipes for a construction project. Your ...
7
votes
1answer
62 views

Member function state machine

For various reasons, I wrote this. For one, I don't like to wrap every single function in a separate class, which is too verbose. It's a state machine based on GoTW 57 function pointer wrapping and ...
8
votes
0answers
82 views

Template integer range

This is a follow-up of an old question by @LokiAstari, modified for the current community challenge. The idea is to provide a compile-time integer range. I applied all the modifications that I ...
2
votes
3answers
176 views

Simple shared pointer

I wrote a simple shared pointer, which I think works pretty well. I would like to see your review of it. This is the header file: ...
5
votes
4answers
1k views

Google Code Jam - reverse words

As a sequel from my previous question, I decided to solve the next problem statement from the GCJ dash board. Any thorough critique, this time, with much attention to skill and technicalities would ...