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

learn more… | top users | synonyms

6
votes
2answers
132 views

Optimisation of palindrome

My program takes as first input the number of test cases, n. For the following n inputs, I output the smallest positive integer that has to be added to the input to make the input a numeric ...
2
votes
1answer
47 views

Still an observer pattern?

Usually when I see tutorials about Observer Pattern I see an unique method called notify, but I'm wondering. What if I have different methods that can be called in ...
0
votes
0answers
39 views

Objects as pass by reference arguments in C++ [on hold]

I am doing a molecular dynamics simulation with velocity Verlet algorithm on particles put around uniformly on the circumference of a circle. These particles on the circle are interacting via a spring ...
3
votes
2answers
49 views

Parsing arguments for cd command

The file manager https://github.com/corporateshark/WalCommander has a code snippet that handles an argument of the "cd" console command. It converts the argument to a valid path, expands ~ and ...
5
votes
1answer
38 views

Parsing .obj 3D meshes

I have a legacy code parsing .obj 3D mesh files. However, it seems to me a bit ugly: ...
1
vote
1answer
33 views

Win32API program Main with Child windows design pattern

Below is the code of a development status project. I have designed a main window with 3 children. I am mainly interested in your comments on the design pattern used for drawing the child windows and ...
5
votes
2answers
189 views

Re-arrange a string into a { consonant, vowel, consonant, vowel … } sequence

I was prompted to give someone advice about the following problem: Given a string with equal amount of vowels and consonants, re-arrange it so that it follows the sequence { consonant, vowel, ...
3
votes
1answer
51 views

Program that handles program options

I'm using boost::program_options to parse input from the user. However, while the standard library makes this an easy task to do, it's causing an (in my opinion) ...
11
votes
5answers
427 views

Custom mathematical vector class

My first bigger C++ project: a vector class for personal use and statistical computation. ...
0
votes
0answers
9 views

Matrix Game SPOJ [migrated]

I solved this problem on spoj: Two players A and B play the following game. First, a matrix M of size N*M is chosen, and filled with non-zero numbers. Player A starts the game and ...
1
vote
2answers
62 views

Speeding up and shortening a loop [on hold]

I'm still relatively new to C++ and I've written a program that could do with being a bit shorter and faster. I use this same set of for loops many times to cycle through the whole tree of values. ...
12
votes
2answers
117 views

C++ function composition

What is a good way to compose std::function objects in C++? I tried the following, and it seems to work well: ...
-2
votes
0answers
26 views

C++ memset() memory overflow [closed]

I am new to C++. Can any C++ expert tell me would this causing buffer overflow? Sample Code: MyObject op; memset(&op, 0, sizeof(MyObject)); On my view it ...
1
vote
1answer
50 views

Polynomial class [on hold]

I'm looking for some assistance on an exercise for my C++ programming class. Unfortunately, I was rather ill the previous week an was unable to attend class, meaning I have only been able to use the ...
0
votes
0answers
64 views

Scanning file performance concerns - C++ vs. Java [closed]

I converted code in Java to C++. The code is large, and to give an example, even simple code for scanning a file takes 60 seconds in C++, while it takes less than a few seconds in Java. The data ...
3
votes
2answers
140 views

Read binary file by blocks

I wrote a function that allow me to read a binary file using 3 blocks what ever the length of file. I've decided to divide the length of my file into 3: block 1: ______________ block 2: ...
17
votes
4answers
4k views

If she floats then she is not a witch like we thought

Continuing my C++ saga, this is the third project for my CS1 class: Buoyancy is the ability of an object to float. Archimedes' principle states that the buoyant force is equal to the weight of ...
7
votes
2answers
622 views

“Guess the number” game

Any tips on how to improve my code and make it cleaner to read for other programmers? Formatting, spacing, etc. ...
-3
votes
0answers
23 views

Get input of integers with space between [closed]

How do I get input of 3 integers with white space inbetween from 1 line? For example, I would prompt ... a,b,c? 1 2 3 ...
4
votes
2answers
70 views

“Vaishnav and Pizzas” challenge

I am trying to solve the below mentioned problem from HackerEarth. Although the results are fine, the code takes extraordinarily long time to run execute. I am pretty sure the problem is because of ...
2
votes
1answer
78 views

ComponentManager - Entity-Component-System architecture in C++

Lately I've been working on a small C++ Entity-Component-System framework. Like most other ECS frameworks the internal data is presented as a table where an entity is a simple row index and each ...
5
votes
0answers
46 views
3
votes
2answers
105 views

Encryption with many algorithms using Crypto++

For the last few days I have been working on this code to develop a class that allow me to crypt a block of byte with many algorithme. One block will be divided into three equal blocks and every ...
5
votes
2answers
124 views

One-to-many multiplicity pattern

The following working C++11 code demonstrates working code for a pattern for representing one-to-many relationships between objects. GitHub (A variant of that code is also copied inline at the ...
3
votes
2answers
440 views

Convert number into words

I am trying to implement a program which can convert number into words. My code can convert numbers between 0 - 999. It uses recursive function calls and simple arithmetic operations. Can you please ...
11
votes
2answers
754 views

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

This is my first attempt at a programme. Is it good form? Does it follow best practice? Or am I completely off the mark? ...
5
votes
1answer
58 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
160 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
64 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
480 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
544 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
69 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
64 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 ...
7
votes
2answers
106 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
113 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
71 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 ...
14
votes
2answers
469 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
127 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
63 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
84 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
123 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
63 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
1answer
82 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
781 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
288 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
33 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
48 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
73 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
48 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 ...