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

learn more… | top users | synonyms (1)

3
votes
1answer
36 views

3Sum implementation

I have recently started to work through the problems on Leetcode, for the sake of bettering my own skills as well as preparing for interviews. I was faced with the 3Sum problem which is: Given an ...
1
vote
1answer
26 views

Sum of all paths between all pairs of nodes in a tree

I'm trying to solve a competitive programming problem. It basically gives a undirected graph (tree-like: no multiple paths between two nodes...) and asks for the sum of all possible paths between any ...
1
vote
1answer
42 views

Partial ArrayList implementation in C++

I've implemented a C++ version of Java ArrayList. It doesn't contain all the functionalities such as AddAll and iterators and such, but I still would appreciate criticism to my code correctness, style ...
3
votes
0answers
32 views

Simple ini file parser

The below is a C++ parser for a reasonably simple INI grammar (although my understanding is that there isn't an official spec as such). My grammar is roughly: ...
-3
votes
0answers
19 views

C++ - Code prints out Tic-Tac-Toe - What is wrong here? [on hold]

This is for a game of tic tac toe in c++. For some reason, when run this code just prints a blank screen. Please help! Code: ...
-1
votes
1answer
51 views

Using templates and function overloads to set DOM attributes

I'm making a library to build and manage a website. I want to control what gets to be inserted. For example I don't want to be able to insert ...
5
votes
0answers
47 views

Atomic floating-point addition

I need to be able to atomically add a 32-bit floating point value to a location in memory. Here is what I came up with. While the code is Windows-specific, I'll extend it with Linux support using <...
2
votes
0answers
67 views

Intrusive weak pointer

WeakPtr can point to any object provided it inherits from WeakBase. So, for example, you could use it to observe an object ...
2
votes
1answer
38 views

C++ getaddrinfo()/addrinfo wrapper (rewrite)

As suggested by @Dannnno on my original post, I am posting my partially rewritten getaddrinfo() (and now addrinfo) wrapper for ...
6
votes
2answers
78 views

C++ getaddrinfo() wrapper

EDIT: New version can be found here: C++ getaddrinfo()/addrinfo wrapper (rewrite) I'm a C++ novice, but an experienced Python and C programmer. I decided to code a C++ wrapper around ...
-2
votes
0answers
23 views

Is this reverse of binary tree correct? [on hold]

Lets say I have binary tree and want to reverse it. Do you think the following code works fine? ...
1
vote
1answer
46 views

Downloading yahoo finance stock historical data as CSV using C++

This post is a continuation of my previous post where I used jsoncpp package to fetch exchange rates from fixer.io. In this post I have reused the above code and used it to fetch stock historical ...
3
votes
3answers
81 views

C++ Queue Implementation

so I wrote a queue implementation in c++ and even though I know the code probably isn't as robust as it should be and probably doesn't perform all the checks it should, I'd like to know mostly if ...
5
votes
3answers
79 views

A command-line calculator using infix to postfix in C++

I was in the mood for some C++ and decided to write a command line calculator, which understands addition, subtraction, multiplication and parentheses. See what I have: main.cpp ...
2
votes
1answer
30 views

Fetching specific foreign exchange rates from fixer using curl and jsconcpp in C++

I am trying to create my own algorithmic trading system using C++. I have searched the web for a nice tutorial for such systems and I didnt find any. Then I started to learn about ...
-1
votes
0answers
26 views

Implementation of circular douby linked list and functions [on hold]

I have some functions I'd like looked over by better eyes. I consider myself a newbie so I was just wondering if you could spot any errors (or potential errors I may have missed) or maybe see ...
4
votes
1answer
40 views

Initializing a std::array from a recursive template computation

I wrote this code for an answer over on SO. I suspect it's possible to clean it up a bit, particularly the base-case specialization for FactorialArray, which is ...
3
votes
2answers
62 views

Evaluating a completely parenthesized arithmetic expression

I tried to solve the following problem in a programming challenge, but the verdict was time limit exceeded. Completely parenthesized expression Write a program that reads a completely ...
2
votes
1answer
35 views

Find offset that minimizes squared difference between two vectors of different size

I am working on a project where the hotspot is some code that is supposed to find an offset, such that the squared differences between a reference vector and a given vector becomes minimal. The core ...
0
votes
0answers
29 views

HackerEarth Prateek and his Friends non-contiguous

How to solve this problem for non-contiguous range? Prateek wants to give a party to his N friends on his birthday, where each friend is numbered from 1 to N. His friends are asking for a gift to ...
3
votes
1answer
31 views

Quicksort using uniform_int_distribution to select the pivot

I have not used C++ for a while. Could you please tell me if my usage of the <random> module is correct? I am not sure if I need to be creating a new instance ...
7
votes
2answers
739 views

Homework to display a square and calculate tips

Here's a simple school assignment I did: Problem 1: Write a program that asks the user for a positive integer no greater than 15. The program should then display a square on the screen using ...
3
votes
0answers
24 views

Get only intended input from user through the console

I finally worked out all of the bugs in this bit of code. I'm pretty proud of it and I wanted to give it to all of you so that you could have it if you wanted it for any console programs that you make....
-3
votes
0answers
14 views

Why does this work on windows and break when I compile on linux? [migrated]

I'm writing a console application for managing and tracking characters, monsters, turn order and conditions applied to make my battle run faster in DnD. The following code works perfectly on windows ...
1
vote
1answer
78 views

C++ Maze Generator

I have made a random maze generator that allows for custom sizes via command arguments. It uses depth-first search and is written is C++. Could you look over my code and suggest any improvements ...
2
votes
3answers
70 views

C++ Tree Class implementation

I am trying to implement a class for the Node of a Tree in C++ in order to represent an HTML structure. It is not complete by a shot, but i'd still like an opinion. TreeNode.h : ...
4
votes
0answers
34 views

cross-platform stdlib-only aligned allocator in C++14

I'm writing a program which uses OpenCL, and the OpenCL types are mostly over-aligned. Sometimes when using stl containers with these types, I'd get segfaults, so I tried to write my own aligned ...
-1
votes
0answers
24 views

c++ program to insert random numbers to a 2D array under a condition [closed]

I have done a c++ program that inserts random numbers (between 0 and 4) into a 2D array under a constraint that is -Its a array with 5 rows and 9 columns.Therefore total ...
-2
votes
0answers
14 views
4
votes
4answers
631 views

Find Watson's integer

Problem Statement: Watson gives Sherlock an array \$A_1\$, \$A_2\$ ... \$A_N\$. He asks him to find an integer \$M\$ between \$P\$ and \$Q\$ (both inclusive), such that, \$\min \{|A_i-M|, 1 \le i \...
0
votes
0answers
7 views

Qt model and Qml pages/controls binding to that model

We're currently learning Qt Quick (with Qt 5.3 at the moment). QML and Qt are not very familiar to me. I'm looking for feedback on the code below. It's not complete code. Ports.h and Ports.cpp are ...
77
votes
6answers
14k views

Basic Pokedex in C++

I recently started learning C++ about a week ago, and I made a bit of progress. In honor of Pokemon Go releasing, I decided to make a Pokedex with the original 151 Pokemon. So far I have 120 or so of ...
5
votes
2answers
65 views

NamedPoint class using unique_ptr for members

After reading this old article from 2001 I have tried to implement the class from it using unique_pointer. An author's claim is that C++ is not appropriate for ...
3
votes
1answer
37 views

C++ Syncronous Poll Wrapper v2

I recently asked for some feedback on my design for a syncronous wrapper around linux sockets and poll Based on the feedback, I created a new (hopefully more idiomatic) design. socket.h ...
4
votes
2answers
64 views

How can I use vector for entering numbers?

I want to enter names, student numbers and student scores and display this information. I used arrays in this way: ...
3
votes
0answers
24 views

Concurrently identify duplicate files from size ordered list

Following on from my program to identify files that have common file sizes, I have developed an application that takes the output from that process and then compares each of the files that are the ...
1
vote
1answer
61 views

Check if vector of strings has matching brackets

For an online screen, I had a question that would take in a vector of strings, and return a vector of strings indicating whether the input string was a valid combination of ...
0
votes
0answers
14 views

redo the author's table2 using the STL list class [closed]

I am having trouble using the STL list class. When I already used it in a linked list way. table2.h ...
4
votes
3answers
90 views

Program to reverse a string using std::string

Background: I'm trying to learn C++ and I'm doing that by writing some programs by myself. I'm decent with C, but I'm having trouble translating to OOP paradigm. I'm reading from learncpp.com and a ...
0
votes
2answers
56 views

Test if file exist

bool isFileExist(const std::string& fileName) { return !!std::ifstream(fileName.c_str()); } This is a function to check if a file exist. Are there non-...
3
votes
2answers
54 views

C++ Socket syncronous poll wrapper

Below is a simple C++ abstraction over linux sockets, and a layer of abstraction over a synchronous poll call. The goal was to exploit move semantics to allow the ...
2
votes
1answer
68 views

Linked list using dynamic memory [closed]

I created a simple linked list to test what I've learned so far and if I manage everything correctly. If you see syntax errors is't because of copy-paste. I just want to know if i'm making everything ...
6
votes
1answer
58 views

Integer to roman number converter

This is (yet another) integer to Roman numeral converter. To give it a slightly interesting twist, I've implemented this as a num_put facet of a C++ locale, so by ...
7
votes
2answers
126 views

Circular Buffer C++11 Implementation

Here's the implementation of a common data structure I use at work, mainly for logging purposes. I tried to make it C++11-compliant, but even if this standard has been around for a few years, it is ...
2
votes
3answers
68 views

QuickSort C++ Implmentation using Iterators #2

This is part 2 of the previous question asked which is at - QuickSort C++ Implementation using Iterators. Based on Jerry Coffin's answer, I have made the changes except for using templates. ...
-1
votes
1answer
55 views

A Rule of Divisibility by 13

A Rule of Divisibility by 13 When you divide the successive powers of 10 by 13 you get the following remainders of the integer divisions: 1, 10, 9, 12, 3, 4. Then the whole pattern ...
2
votes
3answers
104 views

Linked List design and implementation - C++

Seeking recommendations on how to improve this code, LL always seem to be a struggle. A basic linked list that does include next and previous pointers. I used a struct inside of a class, which I'm ...
2
votes
3answers
151 views

Standard deviation in one pass in C++ - follow-up

(See the previous and initial iteration.) This time, I use tag dispatching in order to make sure that non-random access iterators are not put into a std::distance, ...
0
votes
0answers
37 views

Octree population is too slow

EDIT A few code formatting corrections, can not do it better as I can't get to my working station, editing on my phone I've got basic octree structure for voxel storage. The tree is populated by ...
1
vote
3answers
58 views

Functor to compare two floats with tolerance

What do you think about this implementation of 2 floats comparison functor considering how tolerance is introduced? ...