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
1 answer
103 views

A uniform interface for storing data by fd or container

I need to store the data in three different ways: storing the data to a std::string writing the data to a given file descriptor both of the above And I hope to ...
  • 29
2 votes
1 answer
105 views

Boolean evaluation

Given a boolean expression consisting of the symbols 0 (false), 1 (true), & (AND), | (OR), and ^ (XOR), and a desired boolean result value result, implement a function to count the number of ways ...
1 vote
1 answer
86 views

Minimum number of swaps to sort a array, but swaps only allowed with elements 2 apart

I wanted to solve a problem where I sort an array of any size and return the minimum number of swaps. The explanation for the distance 2 is that I choose 3 neighboring elements ABC and then swap them ...
1 vote
1 answer
951 views

Convert string to date C++

New to C++ here, by combining different pieces of code I've found, i came with this solution below to convert a date in string to a date object. It works as I want but I'm not certain to do the ...
  • 219
2 votes
2 answers
131 views

Bogo Sort Algorithm

I am a beginner programmer and have written a program that sorts a number of integers of your choosing using bogo sort. Are there any improvements that could be made to make this code more efficient (...
3 votes
2 answers
78 views

Ball movement within an area

I was asked to write a code in C++ using threads, in which I have to have two limits and 4 characters. Characters can go inside the area limited at the same time when they approach from opposite sides....
  • 31
-3 votes
1 answer
48 views

Printing contiguous sub-arrays

The following method of printing all subarrays(contiguous subsequences) of an array is faster as compared to the general method of using three nested for loops: ...
1 vote
2 answers
134 views

Why my implementation of Anagram function is redundant and might have cache issues?

Task I was asked to write a function, which can determine (return a bool) whether 2 given strings are anagrams of each other? That function should have the following constraints: Upper and lowercase ...
  • 263
11 votes
4 answers
2k views

String formatting in C++

To develop my understanding of C++, I've written an overload function that allows users to use & to insert strings within other strings (denoted by a ...
  • 9,652
1 vote
3 answers
229 views

Printing subarrays ⚡

I was trying to to print all subarrays of an array in quadratic time. Here is my code: ...
2 votes
1 answer
77 views

Storing (and retrieving) functions by indexing them by address

I want to implement a "service" of callbacks, where subscribers register or unregister a callback. I was thinking about indexing the callbacks by the function address, so that to unregister ...
  • 133
4 votes
1 answer
125 views

Vectorset, a faster std::set

I decided to implement a vectorset, which is intended to be faster than std::set for the 3 fundamental operations, namely insert,...
  • 41
3 votes
2 answers
149 views

Random dice class based off D&D

I am learning C++ and I took on this small project to get more familiar with OOP. The goal was to create a Die class that randomly rolls and returns a value based on the sides of the die, the number ...
5 votes
2 answers
132 views

Terminal calculator that saves and displays calculation history

I am self-learning C++ and this was my first smallish project. The goal was to create a working calculator that runs in the terminal, saves history of previous calculations, and has the ability to ...
9 votes
3 answers
1k views

Computing a simple moving average on an array in C++

I have just started to learn C++ and wanted to improve my function. I am making a basic statistical API and am calculating an SMA (simple moving average) for some data. This function provides the ...
  • 191
4 votes
1 answer
90 views

Ways to optimize my FFT impementation's performance

I cooked up a FFT code in c++ for calculating with arbitrary data size. The czt function is copied from GNU octave's czt.m. Here'...
0 votes
0 answers
26 views

UPDATE #2: Lengthening the time it takes to access files using function hooking

https://github.com/speedrun-program/load_extender This is the previous post: UPDATE #1: Lengthening the time it takes to access files using function hooking I came back to this to try to improve it. I'...
4 votes
3 answers
153 views

Introsort implementation

I recently decided to make my own implementation of the Introsort sorting algorithm for educational purposes. Here's what I ended up with (apologies for the lack of comments): ...
  • 196
2 votes
3 answers
311 views

Subarrays with length

You are given an array A of length N (where N is as large as 2×105). All elements of the array are positive integers less than or equal to N. Determine the count of subarrays (contiguous subsequences) ...
2 votes
1 answer
81 views

Heston model implementation in C++

I have implemented an option pricing algorithm following the Heston model. The simulation involves specifying the number of simulations, then generating a discretized path for each simulation (code ...
  • 23
1 vote
3 answers
74 views

Binary Search Tree that allows for duplicate elements - C++

I've recently made an attempt at creating a binary search tree class that allows for duplicate elements. I've included as many functions as I can think of so that I can use it later on. I've tested ...
0 votes
1 answer
133 views

Parallelise numerical integration with OpenMP in C++

I would like to parallelise with OpenMP a one-dimensional integral using the integrate() function implemented in the Boost library. I found a rather obscure ...
2 votes
1 answer
143 views

Electronic circuit logic gates simulator

I've seen a lot of C++ simulators implementing logic gates, but absolutely all of them use the wrapped bitwise operations of the programming language itself. I have tried to omit the use of a bitwise ...
  • 155
4 votes
3 answers
836 views

Infix to Postfix Converter in C++

I have written a program to convert an infix expression to postfix with the help of infix2postfix() function. Please review my code and suggest ways to make it ...
2 votes
1 answer
66 views

Connect4 game multiplayer

I made a connect4 game in c++ please tell my how I can make the code better, thanks. I already asked some people and they told me i should be using fixed witdh ints and [[nodiscard]] on functions that ...
-4 votes
0 answers
29 views

Connect4 game board class [duplicate]

I'm making a connect4 game in c++ and so far i have almost got the board class done before I continue coding i want your thoughts on what I should improve because i definently feel like this could be ...
2 votes
2 answers
58 views

Accept an array, erase some elements and print the array

I'm trying to learn about OOP, specifically encapsulation, and use of static. My goal is to improve my coding skills, I am just looking for feedback specific to encapsulation, the use of static, and ...
2 votes
2 answers
428 views

C++ Hash table, Hash function, benchmark vs std::unordered_set and std::hash

I wrote my own hash function and my own hash table. My hash function seems to work surprisingly well! Feel free to comment anything! Hash function: ...
  • 1,643
5 votes
3 answers
313 views

Templatizing a Timer class

I'm making a timer class in C++. This is the overview: ...
  • 75
1 vote
3 answers
355 views

Any bettter way to achieve this lookup table?

What I need: I need a lookup table. Once the keywords are all found, then the value of the std::unordered_map is returned.And I don't care about the sequence of the ...
  • 29
2 votes
1 answer
71 views

C++ Doubly linked list, including benchmark vs std::list

I wrote a rudimentary implementation of doubly linked list. Feel free to comment anything! ...
  • 1,643
3 votes
2 answers
694 views

Rendering primitive 2D shapes

I am currently creating my own 3D renderer (think something like OpenGL). As a first step, I created a mini program below to render primitive 2D shapes essential to 3D graphics: points, lines, and ...
1 vote
2 answers
158 views

Basic OpenGL application that renders multiple cubes on a textured plane, setup for a 3D game

I'm learning OpenGL and started work on a small 3D game (like Sokoban) for practice. I want to know if the design of my OpenGL code reflects a good understanding of the technology. For example, one ...
  • 11
0 votes
2 answers
567 views

AES GCM C++ implementation

I have written a C++ program that uses the Crypto++ library to encrypt files using AES-256Bit (in GCM mode). I am planning to eventually have the program store the keys for the files in a file e.g. ...
  • 11
7 votes
7 answers
1k views

A probability distribution function, to be called repeatedly during numerical integration

I am trying to speed up as much a possible this function in C++. As I explained in another post, Implementing multidimensional integral for a custom function in C++, this function will be used inside ...
1 vote
2 answers
139 views

Minesweeper implementation in C++

I have implemented minesweeper in C++. You can get a box by entering the coordinates -row number, then column; starting from 0- of said box (eg: "0 0"); you can mark a box as a bomb by ...
6 votes
2 answers
433 views

std::array based push-only circular buffer

Minimal implementation of a circular buffer based on std::array, where elements can only be pushed and iterated. I'm interested on potential failures and very trivial optimizations, as I'd like to ...
  • 163
1 vote
1 answer
62 views

Binary Search Tree implementation in C++ with templates

Im implementing a BST using templates and dynamic memory, here is my attempt: This is the BSTNode.hh ...
  • 269
1 vote
1 answer
46 views

Asking for C++ advice based on a radix sort function

Can someone point out what possible edge cases/leaks/inefficiencies my code has and how they could be avoided/fixed. Basically, I want to know what mistakes I make so I can avoid making them in the ...
2 votes
2 answers
44 views

Simple non balancing indexed binary search tree

The following code represents a simple indexed binary search tree of integers. The insert method inserts an int. The indexed lookup looks up the ith smallest element (0 indexed). I'm trying to write C+...
  • 21
1 vote
1 answer
92 views

Adapter pattern in C++ via Inheritance and Composition

Any suggestions on how the implementation of the C++ Adapter pattern could be improved here? Implemented via: Composition Inheritance What needed to be adapted was the ...
2 votes
2 answers
179 views

Implementing multidimensional integral for a custom function in C++

I am not an expert with C++, but I am trying to implement a 4-dimensional integral using GSL numerical integration approach. The code below shows the whole algorithm. Although it seems correct what I ...
4 votes
1 answer
310 views

Blackjack game in C++

I developed a blackjack game. I am relatively new to c++ and OOP, so I am asking for feedback on what could be improved. This game features betting, taking a card, standing, and splitting a hand. ...
2 votes
1 answer
81 views

C++17 view over the Ith elements of tuples in containers of tuples

For mainly didactic reasons, I have designed my ElementsView<I, T> class template, which provides a view over the I th ...
  • 123
0 votes
1 answer
45 views

How do I increase the memory efficiency of this longest substring implementation? (C++)

I'm practicing my coding on leetcode. I implemented the following algorithm to solve the longest substring problem: ...
2 votes
1 answer
455 views

C++20 Multi-queue Thread Pool with Work Stealing

This is a follow up to my previous post which also follows up on my first post regarding my thread pool implementation. I have since made some further changes and attempted to improve performance with ...
4 votes
1 answer
1k views

Create and view a family tree

I have an assignment due Friday to make a family tree. Started to code in January. My reviews from the teacher for this code was that the use of pointers was horrendous and it wasn't OOP enough. This ...
  • 43
0 votes
1 answer
55 views

Excessive space C++ string [closed]

Extra gaps A string is given. Write an application that will remove all extra spaces from this string. A space will be considered superfluous if: it is at the beginning of the line, before the first ...
  • 1
1 vote
1 answer
137 views

"Fast Pimpl": aligned storage instead of the pointer, special member functions

I have attempted to implement a "fast Pimpl" idiom based on the talk slides and further sources, which is essentially an aligned storage of some size that can be used as a drop-in ...
  • 113
2 votes
1 answer
149 views

Map: Group Tuple keys Together with Empty Elements

Introduction We have std::map<key,std::vector<std::string>> m; where the key is represented by ...
  • 191

1
3 4
5
6 7
182