Questions tagged [c++]

C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. This tag should be used for any question which requires knowledge or expertise with the C++ programming language. This is a general tag which is used for any of the C++ language standards (C++98, C++11, C++17, etc.). The question should identify the compiler being used, the operating system, and which of the C++ standards is being targeted.

Filter by
Sorted by
Tagged with
1
vote
0answers
12 views

Parallel computation of factorial-base left-truncatable primes with GMP library

Factorial base - representation of numbers not as sums of base_number^digit_number, but as sums of digit_number! (factorial) So 7 = 6+1 = 3! x 1 + 2! x 0 + 1! x 1 = 101_! - 7 in base 10 is 101 in ...
3
votes
0answers
22 views

simple and extendable shop

My task is to write a simple shop. The requirements are : It can have multiple items Each item its own price and quantity Each customer basic identifier such as full name Each customer receives ...
3
votes
2answers
61 views

C++ logging class

I've created a simple C++ logging class. It outputs various loglevels, and adjusts output color accordingly. I'm interested in any tips to improve my coding style. I am especially concerned with my ...
4
votes
0answers
20 views

program options from command line initialize [v2 - after CR]

After getting a CR from @pacmaninbw and @ALX23z here, I want to share my new code, and to ask for better ways (which always exist) to improve the code, even with new libraries. The only thing that ...
-5
votes
0answers
31 views

Can't replicate code with the same logic [on hold]

The code that gets the right value (Utility percentage) ...
3
votes
2answers
68 views

program options from command line initialize

I'd like to receive a CR for the following command-line program options' initializing using boost::program_options. I'd like to know if there is a better way of ...
8
votes
2answers
2k views

Implementation of A* algorithm in C++

I have implemented the A-Star path finding algorithm for a 2D grid. The function returns a list of positions of an acceptable path. main.cpp : ...
2
votes
1answer
36 views

OpenFile function in C++

I am in the process of learning basic C++ and one of the practice questions I came across was to write a function to open a file in C++. I did understand how to use the streams but I think I went ...
-1
votes
1answer
33 views

Prime coins- Segment Tree [on hold]

So this question came up to one of the company interview. I felt it as a straight segment tree question with sieve, and I was able to pass the given sample test cases, but unfortunately not a single ...
-2
votes
0answers
15 views

My code seems to work fine until i started to input a string on my x coordinate and it just kept on looping [on hold]

The program runs totally fine until i decide to input a letter when the program ask for the x and y coordinate and it just keeps on looping forever and i cant seem to know why. If i do input a number ...
6
votes
1answer
50 views

Light weight C++ Signals/Slots or Event System

This assumes there is no need to aggregate results from the listeners of a broadcast signal. Technically I guess the slots are whatever your std::function holds, ...
-2
votes
0answers
23 views

Translate n-body code from C to C++ using classes [on hold]

I want to translate my old n-body C code to C++ and want to use classes and other features of C++ like arrays or vectors. My problem is that I do not really know how to start. How do I structure a ...
-1
votes
0answers
36 views

Readers-Writers Lock implementation - ThreadSanitizer is unhappy [on hold]

I'm working on a platform which only has (shaky) support for C++11 so I wrote my own implementation of shared_mutex using the Wikipedia description of the readers-writers lock algorithm. ...
-2
votes
0answers
36 views

C++ ringbuffer with cas [on hold]

This a sample unlock ringbuffer with cas.But still with bugs in put / get. One known bug is multi readers will make m_rear step over m_front then block or coredump. Can someone help me to fix it? ...
6
votes
1answer
74 views

Find overlapping area of octagons

Here is my problem statement: There is a matrix of octagons, for example, 4 octagons in a row and 3 such rows. So 4 columns and 3 rows of octagons. But they are not arranged in a perfect rectangle ...
2
votes
1answer
30 views

Merge adjacent occurrences of identical elements in data collection

There is a small programming exercise to merge adjacent identical elements in a collection. Here are two solutions (passing the tests from the exercise). I am asking for review of the first version ...
8
votes
1answer
795 views

Favorite Game List utilizing vectors and iterators

So in learning c++ I have to make a little program that makes a game list that can add games to the list, remove games, and display the list, and it has to use vectors and iterators, so I made the ...
-2
votes
0answers
35 views

how fix bubble sort optimization [on hold]

I need help with bubble sort. Is there any possibility to optimize the following code? How do you put it in one on the 'if' to make it work? I tried it myself but I can't do it ...
3
votes
3answers
63 views

Optimized Longest Collatz Sequence

I'm writing a program to calculate the longest collatz sequence for positive integers below some N. I have optimized it as far as I can - is there anything more I could do to optimize it? Any ...
6
votes
1answer
64 views

Mvc design for FTP Client

This app will be a FTP desktop application meant to transfer files between a server and a client, pretty much like Filezilla, there is no server code to show as I will not implement Network features ...
4
votes
1answer
88 views

A Graph implementation in C++

I am building a generic Graph. I want to know whether the current design is fine. Are there any memory leaks ? Any suggestions are deeply appreciated. GraphCode ...
6
votes
1answer
52 views

Convert a Hex value string to an ASCII Text String

We had a little bit of fun in the 2nd Monitor this morning, one user greeted another with a hex string. It turned out that the user being greeted deals with Hex Dumps enough that they were able to ...
3
votes
1answer
38 views

Closest element in std map when discarding values

I have the following situation: I have two std::map<int,float> and I want to go through the first map one by one and find the element in the second map with ...
-4
votes
0answers
42 views

Writing a large CSV file write to disk in C++ [closed]

I need to write a large csv file to disk. I've reduced the problem to the below code. When I compile with VS 2017 run on my Windows 7 box it runs on average in 26 seconds. Could someone suggest a ...
5
votes
1answer
60 views

Work-In-Progress Lexer

So, purely out of desire to learn, I decided to take on a project of making my own very basic programming language from scratch. After which, I made a lexer. I've tested the lexer (but only a bit) ...
7
votes
3answers
158 views

Optimizing Conway's Game of Life in C++

How could I further optimize my implementation of Conway's Game of Life? And how would you critique my current strategies? I'm taking a C++ optimization class, the deadline has passed and my ...
3
votes
0answers
45 views

Driver program using custom 3D game engine

I am working on a custom game engine and have been fleshing out the various submodules (meshes, physics, shading, etc.) Here is a sandbox program that exercises the newly finished camera system. ...
4
votes
1answer
49 views

Implement HTTP server using libevent

...
5
votes
1answer
50 views

OpenGL shader abstraction class

I have implemented a class to abstract the process of building a shader program in OpenGL (For now it does not deal with uniforms). I would like some feedback on the coding style, and more ...
11
votes
2answers
156 views

YAAI (Yet another any implementation)

I am a C# game developer currently learning C++ and this is my second big-ish project (the first one being a vector implementation). This time I opted for implementing a mot-a-mot ...
0
votes
0answers
21 views

Lee Algorithm related C++ code has a memory issue [closed]

Today, I've been trying to solve some exercises with queues and I've bumped into one that uses the Lee Algorithm for pathfinding. After testing it and seeing it ...
3
votes
2answers
74 views

Two classes for avoid confusion when handling degrees and radians

Experimenting with operator overloading for the first time. Based on my reading, it appears to be a bit of a minefield. Have I fallen into any traps? ...
7
votes
2answers
79 views

Quick Sort Implementation with iterators

Most quicksort examples online use C-style arrays and indexes. I have written below quicksort implementation with STL style iterators. It looks fine to me, but I feel like I may be making more than ...
6
votes
0answers
107 views

Lazy Resource Loading class in C++

Recently I was studying about the benefits and uses of std::optional in C++17 (Bartek's Blog) and there I saw a line that said "...
-1
votes
0answers
19 views

What's the whole point between return const and non-const? [migrated]

this question is short and simple, I would like to know what's the whole point in returning an object in a fuction as constant or as non-constant. I was reading about 'return constant reference', and ...
6
votes
3answers
70 views

constexpr SmallVector - std::vector like container on the stack

2 years ago I did this: SmallVector - std::vector like container on the stack now, 2 years later, I am reinventing the wheel again, this time with fully constexpr SmallVector. This time, because I ...
1
vote
1answer
53 views

Finding the number of times a query string appears in a vector of strings c++

I wrote some code that iterates over some queries and counts the number of times each query appears in a vector of words. My first iteration iterated through all the words in the vector for each query ...
1
vote
0answers
25 views

Overloading both for (non) constant access [closed]

I'd offer a couple of iterator accesses to the class member, both constant and non-constant. I came to the following solution, but it seems to me far more verbose than needed. I'd like somehow to ...
1
vote
0answers
71 views

Fast matrix transpose

I would like to improve the naive matrix transpose algorithm by using a cache friendly algorithm. So far there are 4 variants. Iterate over the source matrix: ...
2
votes
1answer
49 views

CCC '19 S5:Triangle: The Data Structure

This problem is from [CCC2019]: https://dmoj.ca/problem/ccc19s5/ (Canadian Computing Contest 2019) and I have implemented it in C++. I used sequence [A054237]: https://oeis.org/A054237/table to ...
1
vote
2answers
75 views

MIT Puzzle: The Best Time to Party

This problem is from MIT Course and I have implemented it in C++. Please review and suggest improvements. There is a party to celebrate celebrities that you get to attend because you won a ticket ...
3
votes
2answers
66 views

MIT Puzzle: You Will All Conform

This problem is from MIT Course and I have implemented it in C++. Review this code and how can I improve it complexity-wise and with better features available in C++. Let’s say we have a whole ...
3
votes
1answer
63 views

Beginner FizzBuzz

I wrote a FizzBuzz program to get comfortable with C++. I haven't learned any languages before this, but I'm doing this on my own. I learned if, ...
1
vote
2answers
69 views

Optimizing the Sieve of Eratosthenes for prime generation

I've been on a Project Euler spree and I've been solving problems and as you might know, many of them require you to use prime numbers. I've been using the following code to generate and store primes ...
4
votes
0answers
47 views

Polymorphic deleter for unique_ptr

There is a basic difference in the way C++ manages the deleter for std::unique_ptr and std::shared_ptr, mainly for allowing ...
1
vote
1answer
54 views

Finding Minimum and Maximum Value

I'm doing a code-challenge problem: Captain Kaban: National Treasure is a popular football simulation game which can be played on most smartphones. In this game, you put up a team of 11 players and ...
2
votes
1answer
62 views

Find the largest sum of the GCD and LCM of two numbers in a range

The program is supposed to get one number n as input, and output the max value of gcd + lcm of two numbers that range from 1 to n. For example, if n == 3, the answer is 7 because gcd(3,2) == 1 and ...
10
votes
1answer
430 views

C++ Standard-Thread Threadpool

I have written a small and simple ThreadPool class for rather simple multithreading applications. The Threadpool class manages ...
7
votes
1answer
73 views

Minimal JSON Parser

Motivation: Partially for fun / learning, but also so I can roll out a custom JSON-like file format for a fighting game I am writing. There are two caveats: you cannot have repeated keys (requires <...
12
votes
2answers
963 views

Implementation of a Thread Pool in C++

I wanted to implement a thread pool to test my knowledge of various modern C++ features. The end result could be better, but I need a review as I'm not sure about delicate things especially regarding ...