Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
1answer
21 views

Looking for matching Elements in a List via loop. Can I gain speed, readability or cleanliness here?

The actual data types here are probably not relevant to post an answer. I use Qt types here, but the question should apply for other structured types as well. I ...
0
votes
0answers
11 views

GUI Button Element with Unit Tests follow-up

This is my second attempt with unit-tests. Like my previous attempt, I would prefer a focus on the unit-tests, however I am always happy to improve my code in any way reviewers can help. Once again ...
1
vote
0answers
19 views

Chandy/Misra solution to Dining Philosophers

I took a swing at Dining Philosopher Problem. Decided to use Chandy/Misra solution. However, it ends up with about 1/5 of the threads getting starved for no apparent reason. ...
4
votes
1answer
61 views

Knuth-Morris-Pratt algorithm in C++

First of all, I know there is huge amount of information about KMP on the internet but many examples are just the code without any explanation. So I've decided to implement it on my own. Secondly, I ...
3
votes
1answer
34 views

Iterative version of a permutations algorithm

For learning purposes, I've written an iterative version of a recursive algorithm for generating the set of permutations for a given set of unique integers. Can I make any improvements to increase ...
9
votes
0answers
67 views

Implementation of std::any

Today, I decided to implement std::any using the cppreference page. I've never actually used std::any before and after seeing ...
2
votes
1answer
68 views

Graph implementation using FIFO lists

I've made a little implementation of an undirected graph, using FIFO lists, for one of my homeworks. Never really knew how to write a proper FIFO data structure, so I would be glad to see some opinion ...
3
votes
0answers
36 views

Central class for SFML game engine

I have worked on a SFML Game/Game-Engine Project for 2 months now and am looking for some feedback in terms of... Is this a valid approach for a Game class? Are there any glaring C++ coding practice ...
5
votes
2answers
851 views

Array Dynamic resize in heap

I have answered a Question in Stackoverflow link. a) Create a function called resize that can be used to increase the size of integer arrays dynamically. The function takes three parameters. ...
-1
votes
0answers
16 views

Similar to boggle game [on hold]

Need help to edit this code to allow user to find words in the grid that are touching horizontally, vertically, and diagonally adjacent. For example, the board: Q W E R T A S D F G Z X C V B Y U A ...
1
vote
1answer
42 views

Get a map containing elements which are present in unordered map A but are not present in unordered map B [on hold]

I would like to create a function which returns a map containing differences between two unordered maps. Here is the code: ...
5
votes
2answers
327 views

Compute all the permutations for a given vector of integers

The task is to compute all the permutations for a given vector of integers (but of course the specific integer type is not relevant for the solution) The strategy is based on recursion + iterations ...
3
votes
2answers
77 views

Mario Party Snake and Ladders Board

Context Was inspired from this LeetCode post to do my own System Design exercise of the common Snake and Ladders problem. As I was writing the code Mario Party kept coming to mind so I added a little ...
-2
votes
0answers
17 views

Ordered List insertion [on hold]

I am having trouble making the numbers that I put in the list go in order. I am making a program with a list where I can insert 3 numbers into that list. The 3 numbers should be sorted after inserted ...
4
votes
4answers
98 views

Find the smallest element in a sorted and rotated array

I was solving a question asked in interview by Uber. It says: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. Find the minimum element in \$O(\log n)\$...
-4
votes
0answers
18 views

Implementing a Stack container adapter to check whether brackets are balanced [on hold]

I am a beginner and I wanted to implement my own Stack container adaptor that uses a function that checks whether brackets are balanced or not. I tried implementing the function but I get an error of ...
1
vote
0answers
27 views

“Detailed” exception class hierarchy

I'm designing an modular exception class hierarchy to use in various projects. I intend to inherit from std::exception in order to be maximally compatible with any ...
-1
votes
0answers
22 views

Presenting a “wait for input”-type message before exiting program (on multiple OS's) [on hold]

Includes for std::string and cstrings: #include <string> #include <string.h> Preprocessor code testing for ...
1
vote
0answers
21 views

Average histogram combining multiple files and vector of vectors (in c++)

I run a program of simulation N times (I use each time a different random numbers to initialize it). The results of the program are stored in 2N directories: every run produces two approximations. The ...
1
vote
0answers
25 views

Implementation of std::experimental::observer_ptr (library fundamentals TS v2)

I made an implementation of std::experimental::observer_ptr (library fundamentals TS v2). observer_ptr basically behaves like a normal pointer and does no ...
1
vote
2answers
36 views

Segmented Sieve Spoj

I tried(trying...) to solve the SPOJ prime number problem PRIME1 so i learned and implemented Segmented Sieve correctly but this program works in time for 10^8 but getting Time limit exceeded (TLE) ...
-3
votes
0answers
32 views

C++ return: brackets considered harmful? [closed]

(Preliminary note: we had an interesting side discussion here, but obviously the question has deserved an own place.) Take this innocuous C++17 code: ...
6
votes
1answer
94 views

C++17 <span> implementation

C++20 added the span library under the header <span>. As voluntary exercise (not homework!), I spent approximately 1.5 ...
5
votes
2answers
58 views

GUI Button Element with Unit Tests

I would like a review on just a single class today. More important to me than a review on the class itself, however, is a review of the unit-tests I wrote for it. You see this is my first attempt at ...
3
votes
1answer
45 views

Min heap C++ implementation

I have implemented a min heap in C++, and I want to improve it in every possible way. Could you please review it and let me know your suggestions/comments? ...
13
votes
3answers
2k views

Simple HTTP Server

I'm working on a project (studying) and I have a lot of time for proof of concepts and write something from scratch. Basically I'm creating an HTTP server (simple, but not too simple) in C++ using ...
-5
votes
0answers
18 views

for 1 string. find the longest string of conditions [closed]

give 1 character string of 2 characters A and B. Find the number of characters of the longest substring so that the difference between the two characters does not exceed 1. (consecutive substring) <...
-1
votes
0answers
17 views

C++ Monster Roaming Functionality [migrated]

I have a working monster system that follows players around by moving a certain distance towards the players 2D (X, Y) location. However, I now want to make it so these monsters roam around at random ...
3
votes
2answers
62 views

C++ protocol for sending arrays over TCP

As someone who has programmed in C for a long time, I have just written my first C++ program and feel it would be very valuable to get a review of the code, to see what features of C++ I could make ...
3
votes
1answer
51 views

Project Euler #5 in C++

I'm currently doing the Project Euler challenges to learn C++. The fifth problem is the following. 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any ...
2
votes
0answers
23 views

DirectX11 Error Handling

I'm new to C++, been a C programmer most of my life. I wanted to get into graphics and Direct3D is C++ so I figured it was about time. I've been learning about strings, vectors, references, smart ...
14
votes
3answers
2k views

Hangman Game with C++

After finishing my C++ course, I decided to make a hangman game. (without the drawing part) I was wondering how the code could be improved. Header File: ...
19
votes
4answers
4k views

Project Euler #1 in C++

I'm learning C++ and currently doing Project Euler challenges. The first challenge is the following. If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. ...
5
votes
3answers
418 views

Finds a Character based on distance and health

I need to improve the efficiency of my program and, using the profiler, have narrowed the problem down to 2 key areas, but I am having trouble coming up with ways to make the program run better. ...
-1
votes
0answers
15 views

c++ code for a new version of LIS A. K. A “Longest increasing sub sequence” [closed]

i need a review on a code i have wrote for a new version of the LIS problem. New Version of The Longest Increasing Sub-Sequence: you are given an unsorted array of integers as "A".the goal is ...
3
votes
2answers
70 views

Binary genetic programming image classifier's fitness function

I am trying to figure out how to improve my binary image genetic programming classifier's fitness. It takes images and classifies them if it has some feature X or not in it. These are the main ...
0
votes
1answer
42 views

GUI that searches files using user inputted search strings [closed]

Basically, I've got a GUI where the user can select text files, enter in strings (that may or may not contain wildcards) and search those files for those strings. Currently, I take the user inputted ...
2
votes
1answer
97 views

Game to shuffle and guess a word

I'm new to C++ and while learning, I wrote a simple program that asks for a word, shuffle sthe characters and then asks another person to find the original word, given the shuffled letters. I would ...
5
votes
1answer
174 views

Finding the upper and lower bound using binary search

I am trying to solve this InterviewBit question https://www.interviewbit.com/problems/search-for-a-range/. My code for this seems to be working properly and it does give me the correct answers on my ...
1
vote
0answers
44 views

Simple Asynchronous Dispatch Queue

I'm practicing C++11/14/17 and am teaching myself the STL multithreading library by writing an asynchronous dispatch queue for my simple use case. It seems to "work ok" but I want to know if it's ...
2
votes
0answers
39 views

A C++17 `std::allocator` implementation

This is an implementation of C++17 std::allocator under the name my_std::allocator, with deprecated stuff omitted for simplicity....
8
votes
0answers
173 views

Windows keylogger in C++

Windows keylogger in C++ Known issues: Not implementing rule of five Having to use hack to use member variables, out_, in static method Pressing caps-lock won't ...
1
vote
0answers
34 views
+100

Line segment intersection from the Berg et all, computational geometry

I've implemented the following algorithm (From "Computational Geometry : Algorithms and Applications"). The code is below: (All the code actually is here: https://github.com/lukkio88/...
16
votes
6answers
5k views

Check which numbers satisfy the condition [A*B*C = A! + B! + C!]

#include <iostream> #include <cmath> using namespace std; int s = 1; //Serial No. Should I use recursion for the factorials function? ...
3
votes
1answer
60 views

Given a list of coordinates, find the rectangle with minimal area

A problem on leetcode asks the coder to write an algorithm to take a bunch of coordinates in the xy-plane and return the minimum area of a rectangle made from four of these coordinates (or return <...
5
votes
1answer
76 views

A cartesian product of tuples in C++17

I would like to write a function that computes a cartesian product of two tuples in C++17 (the tuples can be of type std::tuple or ...
5
votes
1answer
100 views

Matrix class with space-optimized triangular (lower and upper) variants

I've written a class for square numerical matrices (of doubles, in this case), in C++11. Since I intend to use this class later ...
6
votes
1answer
73 views

Qt Number Generator v2

Link to the old question. I tried to learn some new things from the answers and here's what I did: Used Qt Designer so that in Config.h, all member variables and ...
6
votes
2answers
109 views

Simulation of a banking system with an Account class in C++

I have been learning C++ and recently I have started practicing classes. I made this simulation of a banking system with an Account class. I would like to hear feedback on my code, what is good - what ...
4
votes
0answers
57 views

C++ shared_ptr memory pool

I put together this little memory pool class to help avoid the costs associated with heap allocation and deallocation of objects that are frequently created & destroyed. It creates C++ standard <...