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
6 votes
1 answer
94 views

Bagels (based on big book of python) in c++

I just learned programming and decided to copy projects in big book of python but in c++ and completed the first project. I would like to know your opinions and how can it be improved! Thanks in ...
2 votes
1 answer
95 views

Sender/Receiver threads using std::unique_lock and std::condition_variable

The code below is a sender/receiver setup in C++ where the sender is in one thread, the receiver is in another, and the data being sent/received is "shared" (global). The code uses the ...
2 votes
1 answer
65 views

Make an array of names and if the names are the same add a number at the end of the name

Note - I posted updated code; see version 2 of this question. I'm writing something like the Unity's shader graph and I'm kinda stuck on a property panel. I add a float property, which name is ...
  • 137
2 votes
2 answers
73 views

Check if a date is in an interval defined by partial/periodic dates

I can define an interval with start and end in the format YYMMDD, but they can also be ...
1 vote
1 answer
125 views

Euler's totient function for large numbers

I made this algorithm to compute Euler's totient function for large numbers. A sieve is used. ...
2 votes
1 answer
49 views

Reservoir sampling Algorithm A-ExpJ for C++17

Implementation of the Reservoir sampling algorithm A-ExpJ that allows sampling K random elements from a stream of elements according to their weights when we don't know the size of the stream in ...
2 votes
2 answers
200 views

Inserting into a Sorted Doubly Linked List

Edited: incorporated some feedback and added a lot of features I've written a basic Doubly Linked List Class where every insertion into the class should be sorted into ascending order. The project ...
  • 311
2 votes
1 answer
97 views

Reimplementing Alias method in C++

In the following I reimplement the Walker-Vose Alias method for sampling from nonuniform, discrete probability distributions. I am well aware that there is https://en.cppreference.com/w/cpp/numeric/...
  • 904
2 votes
1 answer
86 views

Shader Program OpenGL

I am new to OpenGL learning it on amazing website learnopengl.com I wanted to a convenient way to use shader programs thats why I created this struct, please review it. ShaderProgram.h ...
1 vote
1 answer
49 views

Class that can only be created and deleter through smart pointer

I would like to expose a nullable referance of a "mesh" object, so I am returning a const pointer. However, I explicitly want to prevent anyone handling this from deleting the object. The ...
  • 196
1 vote
1 answer
108 views

Function to find the closest points between two line segements

The following function is supposed to return the points p1 on line segment a, and p2 line segment b, such that |p1 - p2| is minimized. ...
1 vote
1 answer
48 views

N dimensional array index utility Improved

This is a continuation from a previous question; I updated the code with the suggestions and added an additional iteration. Templates are not an option because of the usage: The objects are stored as ...
0 votes
1 answer
77 views

Newton-raphson to find the square root of an arbitrarily sized number with arbitrary precision

I read here that "Furthermore, for a zero of multiplicity 1, the convergence is at least quadratic (see rate of convergence) in a neighbourhood of the zero, which intuitively means that the ...
  • 307
1 vote
0 answers
103 views

A-star pathfinding algorithm to route through a raster maze

I have a problem that needs path finding to solve. It is a vector of ints; 1 for passable terrain and 0 for non-passable. My implementation is not fast enough for the test. How could I make it faster? ...
1 vote
1 answer
92 views

Implementation of the driver for the speed sensor

I have been developing a C++ driver for the incremental rotary encoder (irc) based speed sensor. It is a part of my embedded software project. The driver is basically decomposed into two layers: The ...
  • 385
2 votes
1 answer
99 views

Tool for asynchronous IPC using pipes

Description of the code: The code provides asynchronous IPC functionality in C++ using the Boost libraries and pipes. Each process asynchronously "listens" on the read end of the pipe and ...
  • 23
0 votes
1 answer
70 views

Class that counts its instances

I'd love some feedback on the C++ base class shown below. It's basically a toy problem for a fake video game where the monsters that you have to avoid will all be sub-classed from the class shown ...
4 votes
2 answers
948 views

Code lines counter

It is a Windows command line utility for counting lines of code in a source code directory. It will count loc and sloc. I read from a file character by character using fgetc in the CountLines(...) ...
  • 41
1 vote
1 answer
35 views

Sparse String Matrix Storage Class C++

Introduction I implemented a class to store a matrix with entries at positions (i,j) that are strings. The matrices I would like to efficiently store in this class have strings as entries and it ...
  • 113
1 vote
2 answers
143 views

Bilinear interpolation optimized using intrinsics

I have found that a bottleneck of the OpenCV application I use is the bilinear interpolation, so I have tried to optimize it. The bilinear interpolation is in 8D space, so each "color" is an ...
  • 315
3 votes
2 answers
333 views

Concurrent Handle Table

I'm writing a data structure to solve a problem related to servicing hardware interrupts. I have to translate a 64-bit pointer to a 16-bit handle and back again. Unfortunately the hardware completions ...
  • 181
-1 votes
1 answer
56 views

Palindrome string program [closed]

...
1 vote
2 answers
63 views

multithreading LRUcache in C++

I want to implement a multithreading LRU cache in C++. And here is the code. Can you tell me what should I do to make it more multithreading? ...
  • 41
-1 votes
1 answer
88 views

Tic tac toe game - my first code using pointers in cpp [closed]

Below is the game code written in cpp. This is the first time I have consciously used pointers. I can't handle the logic of winning. I have no idea how to solve this in a different, more accessible ...
2 votes
1 answer
194 views

Minesweeper using SFML with C++

Hi, I am making a Minesweeper game using SFML 2.0. I am just a beginner in C++ and started using the framework for 2 weeks now, so it is safe to say I may have made lots of mistake especially when it ...
  • 23
7 votes
2 answers
68 views

N dimensional array index utility

I created the below class to help working with ND Arrays, mapping based on this question. This will help in implementing the code for handling convolutions. How can I improve upon this? Is there ...
3 votes
2 answers
678 views

TCP server in C++

I am building a TCP server in C++, and right now it's a test version without logic to handle server-client packet transactions. Please check if there are any memory leak related issues or anything ...
5 votes
2 answers
115 views

Simple virtual piano

The application is a virtual piano with only one octave for simplicity. What can I improve with this code? ...
  • 51
1 vote
1 answer
98 views

A greedy approach to the Knapsack problem with C++ templates

The assignment is to be implemented on the following instructions: You are to write a Knapsack class and the main() to support and demonstrate the functionality required here. A function generate(int)...
user avatar
4 votes
1 answer
64 views

Multiway map in C++

I recently had the problem that I wanted a hashmap where there would be a variable amount of distinct classes which each could be used to look up each other. I couldn't find any implementation online ...
3 votes
3 answers
136 views

C++ Hunt the Wumpus

I have been writing Hunt the Wumpus game in C++, and i think it's finished. It's first non-trivial project, and it DOES work properly (at least 20 hours of debugging showed so). How can the code be ...
1 vote
2 answers
108 views

Insert node at beginning of LinkedList

My professor required we make a LinkedList class with a bool add(in newEntry) method. Two things I'm questioning my choices on ...
  • 311
0 votes
1 answer
94 views

Is this the correct way of implementing a builder pattern in C++?

Coming from a Javascript background, and just now getting into c++. Want to know if im doing the builder pattern correctly in C++, and also what could improve on ? PongObject.cpp ...
  • 251
0 votes
1 answer
46 views

Using of fold expression to read csv file

I've written a code reading csv file using fold expressions. The only thing that should be defined is columns types and file name: ...
  • 113
2 votes
2 answers
106 views

Algorithm that prints day, when submitted date

I would love to know your opinion about this algorithm that we wrote in class. I was thinking about how I can optimize it (in terms of size of code/complexity) without using library functions (...
3 votes
1 answer
79 views

C++: Visit Any Type Holding Other Types (`std::any`, `std::variant`, etc.)

Intro I want to visit the value held by a class, which could be of multiple types. This class is very similar to a std::any, so I will be using this in this ...
12 votes
2 answers
6k views

Laughably tiny random engine

I devised a tiny pseudo-random engine and I wondered if it would be considered decent or even good. It is based on a SHA256 implementation and uses a single 32-bytes state variable. On seeding, the ...
-2 votes
1 answer
110 views

How can I optimize C++ serialization? [closed]

I want to serialize a C++ class Ramdomclass . Below is the serialization function. ...
2 votes
2 answers
85 views

Print the count of input numbers less than each of mutiple values "q"

I was solving a question in a competition I joined that asked for a program that calculates how many numbers are less than \$q\$. I solved the question but didn't get the full mark because the code ...
  • 23
2 votes
1 answer
58 views

Database buffer class

I designed the following DataBaseBuffer class, to be used by different threads that generate queries and need to send them to the database. It was inspired by ...
  • 23
3 votes
2 answers
119 views

A simple console-based banking system

I am an amateur. I have been coding for 3 months now. If you have any comments,suggestion or critics about my code please feel free to speak up(i am urging you to). I want to be a really good ...
2 votes
1 answer
124 views

Pong in c++ console app

I would really appriciate if someone could review my code and give me feedback. This was my first multi file project. Main: ...
  • 75
0 votes
1 answer
122 views

What can I do better in my C++ serialization implementation?

I want to serialize a class Mango recursively. ...
1 vote
2 answers
100 views

Several container functions rewritten as an excercise

I took one of my old university exercises for another language and re-solved it in c++. It consists of several higher order functions for vectors. I hope the comments are self-documenting enough. I am ...
  • 11
5 votes
2 answers
85 views

Mathematical expression evaluator (C++) Using Flex and Yacc Attempt2

Attempt 2: First Try here. Usage: ./expression Then you can either type expressions that are evaluated when you hit ...
  • 92.6k
4 votes
2 answers
138 views

First contact with C++ - Graphics Library

I am trying to learn C++ by writing a basic graphics library; undergrad-toy-project level. I am trying to write modern C++ (C++ 20 standard), but avoiding features that are not well supported by my ...
  • 791
10 votes
1 answer
442 views

Mathematical expression evaluator (C++) Using Flex and Yacc

Based on this question, I thought I should show how to implement an expression evaluator using Flex and Bison. Updated: Here Currently it does not handle releasing the expressions (I only spent an ...
  • 92.6k
8 votes
1 answer
305 views

Mathematical expression evaluator (C++)

I'm new to C++ and I decided to experiment with the language, by writing a mathematical expression evaluator, using the Shunting-Yard algorithm. A design choice that may stand out as weird is the fact ...
1 vote
1 answer
75 views

Timeit multithreading/multiprocessing C++

Given a Timeit method which runs for n times the provided function, which approach between multithreading and multiprocessing should be better to speed up the execution of all iterations and avoid the ...
1 vote
1 answer
111 views

Attributes Parsing in C++ Challenge

Link to task Similar question to same challenge Attribute Parser This challenge works with a custom-designed markup language HRML. In HRML, each element consists of a starting and ending tag, and ...