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

learn more… | top users | synonyms

5
votes
2answers
168 views

“Who are you, and where do you live?” — a Q&A exercise

This is my first attempt at a program. Is it in a good form? Does it follow best practice? Or am I completely off the mark? ...
2
votes
0answers
25 views

Solving a one-dimensional Euler equation for fluid dynamics

I just wrote a program to solve one dimensional Euler equation for fluid dynamics. Attached is a snippet of the vtune profile result for one of the function. There are a few things which looks weird ...
5
votes
4answers
134 views

Implementing Conway's Game of Life

Here is an implementation of Conway's Game of Life. My code is working fine but I want you to review and give me your suggestions of how to improve it. These are the steps of my code: Initialize ...
3
votes
1answer
58 views

Small pre-C++11 pseudo-random library

Some time ago (pre-C++11) I wrote a small random number generator library as part of a university assignment. The code has been stored on my hard drive for quite some time and today I dug it out and ...
12
votes
4answers
442 views

Voxel-based chunk manager

I'm creating a voxel-based game and have been working on it for quite a while. I've come to a point where I have to load and unload chunks on the fly. I've created a chunk manager class and it's ...
6
votes
3answers
535 views

Lemonade stand menu program

This is an assignment given in my C++ programming class. I have one main menu with four other menus branching out from it. I would like to make my code as clutter-free as I can, so please review ...
2
votes
1answer
51 views

Should I add a function that takes as parameter a ptree?

I have a class ConfigFile that reads some values from a JSON using Boost and store them in variables. Everything is done in the constructor: ...
4
votes
2answers
56 views

Console class that handles multiple buffers

I'm working on a 80x25 terminal that splits the screen into two. The top half gets the first buffer, the bottom half gets the second buffer. I'm concerned about readability and accessibility. For ...
6
votes
2answers
89 views

Array-like container for uints shorter than 8 bits (Rev 1)

This is a follow-up to Array-like container for uints shorter than 8 bits In short: The PackedBitfieldArray should be a kind of container for packed (unsigned) ...
4
votes
3answers
107 views

Squaring all integers in an array [closed]

I have a function that takes array and replaces all integer elements with their square: ...
3
votes
1answer
64 views

Implementing a genetic algorithm to solve knapsack

I am trying to develop a genetic algorithm to solve knapsack problem(0-1). I am new to algorithm and programming as well. Here is my code and it works but I would like to know your suggestions of how ...
13
votes
2answers
447 views

Lexer+Parser code for my “Reedoo” programming language

I've been working on my own programming language, as a hobby for the past couple of months now, called Reedoo. It is implemented in pure C++ 11 and uses only the libraries that come with C++; no ...
10
votes
1answer
123 views

Array-like container for uints shorter than 8 bits

Follow-up: Array-like container for uints shorter than 8 bits (Rev 1) First of all: yes, I need this kind of array to generate data for a piece of hardware, and it must be stored and manipulated ...
-1
votes
1answer
53 views

Custom 2D/3D Graphics Vector Classes vs SFML's

I don't really like SFML's Vector Classes so I tried making my own. Any criticism is welcome. ...
-1
votes
2answers
82 views

LinkedVector : a vector of elements with links to other elements

I wanted to have a vector with usual values and with some sort of indexing : an element can have links to other elements (via indices). Something like the following, where ...
6
votes
2answers
113 views

Policy-based, variadic logger class in C++

I've been exploring design based around some of the more advanced C++11 features lately, and some of them are turning out to be rather useful for some projects I'm working on. One is this ...
13
votes
4answers
1k views

Living off of chocolate

This is the second project for my CS1 class, this time I'm actually getting it reviewed before I submit it ;) The Harris-Benedict equation estimates the number ...
8
votes
2answers
61 views

Generic mean function

It seems useful to have a generic function to calculate the mean of all elements in a container, so I wrote one. By default it calculates the arithmetic mean, but should be able to accommodate other ...
2
votes
0answers
60 views

Variadic template data pack strucuture designed for debug/trace log (variable-sized records)

I am currently writing this pack template to pack all the values (raw / fundamental + arrays of such, especially c-strings and ...
8
votes
6answers
769 views

C++ 3D Vector Implementation

I have been learning C++ now for 2 months and this week I started reading a book on 3D graphics. I like coding whatever mathematical stuff I learn so I can understand it better, so when I learnt about ...
7
votes
4answers
281 views

Effectively calculate the result of geometric series

Given \$f(n) = 1 + x + x^2 + x^3 + \ldots + x^n\$ and the fact that computers take more time when multiplying two numbers than when adding, how can we work out the result with greater efficiency? ...
3
votes
1answer
32 views

Test if two nodes in binary search tree are cousins

Cousins are nodes at the same level of the tree, with different parents. They don't have to share the same grandparent. My solution depends on having a binary search tree with unique elements. This ...
3
votes
3answers
46 views

Hexadecimal to string without C++ standard library functions

For the purposes of this code review, I will use the standard library, but pretend that <cstddef> is <stddef.h>, ...
6
votes
1answer
67 views

Program that replicates itself

While misreading the beginning of Stage I of this classic paper by Ken Thompson, I decided to create program that replicates itself. Let's say this program is called Replicator.exe. Upon running it ...
3
votes
1answer
46 views

Evaluating given numbers and operations

The program reads in an operation, and then numbers, and does stuff to them based on that. Exercise number 1 at this linl For example, ./this_file sum 1 2 3 would ...
13
votes
5answers
837 views

Calculating freefalling object's height

This is the code for my first CS1 project, I hope to be posting my code here to track my progress of learning the language of C++. I shouldn't be too shabby, since I know C considerably well and have ...
5
votes
3answers
346 views

“Jolly Jumper” challenge

I'm a C#/Java full-time developer who is trying to pick up C++ purely for educational reasons. I've tried to solve a pretty simple ACM ICPC problem and would love to hear all kinds of criticisms on ...
3
votes
1answer
50 views

DestroyWindow() non-existant windows

What I am working on has sets of window controls. Controls are constantly being either destroyed, or created. ...
3
votes
2answers
57 views

C++ implementation of Java's floatToIntBits() and intBitsToFloat()

I am trying to implement Java's floatToIntBits() and intBitsToFloat() methods in C++. The latter method is the inverse of the former method, and the purpose of the former one is to pack a 32-bit ...
7
votes
2answers
89 views

Is this a modern C++11 implementation of a Level class and static factory?

This is a follow up to my previous question, now that I've read up more about modern C++ (specifically C++11) and the answers in the question. I'm using MSVC/Visual Studio 2012 Update 4. Specific ...
4
votes
2answers
83 views

Array kept contiguous by swapping with the last element

I made a class that encapsulates the common pattern of keeping an array contiguous when an element is removed by swapping the last element into its place. A few specific things I'm wondering about: ...
5
votes
2answers
52 views

writeln() and format() with variadic templates

I wanted to get better acquainted with variadic templates, so I decide to try to implement a function like D's writeln(), just for fun. ...
1
vote
1answer
29 views

Decoding an element list

I have a function which I am calling an infinite number of times (or until a condition is met). The problem with this recursive function is that on a higher level, it is called by a worker thread ...
2
votes
1answer
48 views

C++ messaging using templates

I wanted to allow components of my program to communicate without the components knowing about each other, thus keeping coupling low. So I devised some template classes that implement the observer ...
3
votes
2answers
74 views

Multithreading decouple update-logic and render-logic

I want to improve my multithreading competence and tried to build a compact doublebuffered way to separate two threads where one is only displaying the state and the other one updates the state. So I ...
10
votes
1answer
89 views

Container with sorted by multiple keys

From this question: Sorted vector (aka flat_set) for objects (pointers) with custom embedded key (functor used) This is an example of a multi-index container. Note: this is not a container as ...
1
vote
1answer
44 views

OpenMP code runs slower than single thread code

I'm making a program that takes an integer n and generates the first n Ulam numbers. I followed this guide about OpenMP. This ...
1
vote
1answer
74 views

Decreasing the runtime of this non-abundant sums solution

I have written a solution to problem 23 of Project Euler, and after doing some testing and editing, I've managed to get the run time down from 1.7443 seconds to 1.56616 seconds. The problem is ...
7
votes
2answers
116 views

Sorted vector (aka flat_set) for objects (pointers) with custom embedded key (functor used)

BEFORE YOU READ: this link should be included when you just don't like the format of the question and for those that read this question for the first time, the link may give you the idea what happened ...
6
votes
4answers
97 views

Custom class for a borrowed unique_ptr<T>?

In C++11, I tend to have master objects that maintain sole ownership of a collection of some children objects. Let's assume these children objects are non-copyable (for instance, ...
9
votes
5answers
378 views

Static factory function and lifetime

I'm trying to teach myself C++ at the moment, after years of C# and other managed languages. The class in question is a Level in a game, and the idea is to ...
6
votes
1answer
49 views

3D matrix rotation in homogeneous coordinate space

Assuming that the framework is in place to handle the difference between row and column major matrices, I am curious to know if in a header based library such implementation is semantically and ...
4
votes
1answer
130 views

Implement a string in reverse using pointers and recursion

I'm trying to reverse a string using pointers and recursion, and I send it a char array. Is this the best way, or is there a better one? ...
3
votes
2answers
127 views

Implementing a genetic algorithm to solve the Diophantine Equation

I am trying to implement a genetic algorithm to solve (Diophantine Equation). For instance, a + 2b + 3c + 4d = 90 where a, b, c, d are positive integers. After reading some books and following ...
5
votes
1answer
119 views

General multithreaded file processing

I'm trying to write a general multithreaded file processing facility. The idea is that some input file consists of a number of discrete records, each record needs to be processed in the same manner, ...
9
votes
2answers
110 views

RPG game shop system

I'm interested in the organization, layout and style of how I program. How does organizing code using whitespace work? I've had a go in the code below. I mean like when you press tab and start the ...
0
votes
3answers
92 views

UVa Challenge Problem 100: 3n+1 code

I have written this code for UVa Challenge 100: ...
6
votes
2answers
94 views

Summator simulation

This is a reference implementation of a summation unit. The algorithm used is a most straightforward carry-propagation. If necessary, a test driving code could be provided. Few notes for the ...
7
votes
3answers
635 views

Managing student budgets

I have just started to play around with C++ and I want to make my code efficient and clutter free. Please critique this code constructively and give feedback that will help me in my programming ...
7
votes
5answers
470 views

Removing the largest values encountered so far in a list

The problem is, in summary: A set of values will be given. Whenever the input is -1, the largest number from the values inputted until then needs to be printed, and is then deleted. Here is the ...