Stack Exchange Network

Stack Exchange network consists of 174 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
20 views

LRU implementation in C++ using a LinkedList

Explanation : I am adding new elements in the list until the window runs out. Head will have the earliest element and tail will have the most recent element. Once the window is over, every addition ...
1
vote
1answer
66 views

Calculating array size in C++

This code shows two ways to calculate size of array of any type. I would like to know, which should be preferred? Is there any advantage/disadvantage? ...
2
votes
0answers
22 views

get; set; in c++

I wrote a class that replaces get and set functions: ...
3
votes
2answers
101 views

Determine whether a vector intersects the up or down unit vector

I wrote an if statement that checks if an iteratively altered vector "crosses" the up vector (0,1,0) or the down vector (0,-1,0). ...
0
votes
0answers
32 views

Dynamic programming with 3D arrays

I am trying to solve a question given on Codeforces involving dynamic programming with 3D arrays. F. Trucks and Cities There are \$n\$ cities along the road, which can be represented as a ...
-1
votes
0answers
28 views

Function to check if received message matches any of the expected messages [on hold]

I have a message coming in and I need to match it against the expected messages. The program will eventually do something as a result of receiving those messages. I am not very experienced at ...
3
votes
3answers
109 views

Image filter for gradient detection

This filter is basically gradient detection (the variable gradImg) like an edge detection (Sobel or Prewitt filters) and also the direction of that gradient whether ...
1
vote
1answer
48 views

Simple DP problem solved in compile time

The problem is taken from one of recent SO questions: Finding max sum of matrix elements with following constraints: Exactly one row element has to be included in the sum If element at (i, j) is ...
6
votes
3answers
93 views

C++14 std::array implementation

I invested an hour or so to reimplement the C++ header <array>. Most stuff is in the namespace my_std, but ...
1
vote
2answers
40 views

Mutex Protected Object (scoped object wrapper)

This is a class that holds mutex and associated object. On checkout/access the mutex is locked while the stack object lives and a reference to object is obtained. Any suggestions or improvements is ...
1
vote
1answer
34 views

Moving character in given direction C++ SFML

I have written simple input manager which is used for me to detect key press, and fire assigned function. For example I can do something like that: ...
3
votes
1answer
50 views

C++ OpenGL - GLFW Window Abstraction

I made a GLFW window abstraction, as I find it very useful for me to make such abstractions while learning an API, and It actually pretty much eases my work while coding. Anyways, share your ...
-1
votes
0answers
16 views

How to reduce a given series expression to an algebraic expression? [on hold]

I need to reduce the given series expression to an algebraic expression, without summation. Then I have to express the performance of the algebraic expression in Big O Notation. I am mainly confused ...
1
vote
0answers
41 views

Simple Mastermind in c++

i created this console application ( it's actually a Mastermind) and i would like to know what can i improve as a beginner. Thanks ! ...
5
votes
3answers
91 views

Student grade calculator using classes/ structs in C++

I am trying to teach myself C++ and using Problem Solving in C++ by Walter Savitch. This is a program project from the book that I used to practice using classes/ structs and would like some feedback, ...
2
votes
1answer
50 views

Simple Console Snake game C++

I recently started learning C++ and have made a very simple Console-based Snake Game, I would like to have some feedback on improvements. You might notice the obvious delay in clearing and printing ...
2
votes
1answer
75 views

C++ ASCII To Base64 String Encoding

My Base64 encoder class converts a string with ascii characters to a base64 encoded string with padding if required. Note that I'm not using istream as the input ...
2
votes
1answer
29 views

Using boost::mpi to take the Euclidean norm of a vector

I am learning MPI (via boost::mpi) and wrote this program that takes the euclidean norm of a 1-D vector (represented as an array here.) I want to make sure that I ...
0
votes
0answers
70 views

Algebraic data types in C++ [on hold]

After some exposure to Haskell I came to love ADTs to describe 'is one of' and tree-like structures. But now that I work with C++ a lot more I want to use them in C++ too. As far as I know I have two ...
-2
votes
0answers
18 views

Priority Queue comparator map [closed]

I have a custom comparator for a priority queue. ...
2
votes
0answers
56 views

Command line sliding tile puzzle in C++

I have rolled a simple program for controlling a sliding tile puzzle via command line. I would like to hear comments on how to make it more idiomatic C++17 and efficient. Here is my code: ...
3
votes
0answers
36 views

Calculate huge Fibonacci Numbers in C++ using GMP and boost::multiprecision

Problem Statement Calculate the exact value of the n-th Fibonacci number, say the one-billionth. Algorithm The algorithm is based on the idea that Fibonacci numbers can be represented as 2x2 ...
0
votes
0answers
82 views

Voxel Engine with Vulkan

Here is my voxel engine. I want some review for performance on the renderer. What can be improved? What must change? Also I'm not sure it is efficient to use vkWaitQueueIdle for syncing. The end goal ...
6
votes
2answers
62 views

Rearrage sequence so that adjacent numbers add to perfect squares

Consider the array: original_array1[17] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17} I want to sort it in such a way that: Sum of adjacent numbers should be a ...
3
votes
1answer
79 views

Basic substring algorithms + auxiliary string-generating functions

Summary: a bunch of algorithms to find if particular substring exists in the string. Meanwhile there's a lot to learn and I am looking forward to implementing more complex ones, I suppose there's some ...
0
votes
1answer
116 views

“Food Ordering” program exceeds time limit in test 9

So, I've recently started working on CodeForces to practice from older contests (and maybe even start participating in current ones), but there is one problem that I can't seem to make an efficient ...
4
votes
1answer
220 views

Variadic Datablocks

I would like to have my variadic template class reviewed. First some explanation what it should do: I'm writing an application where I read in blocks of data. I know before i read in the data which ...
0
votes
1answer
59 views

Saving settings to Windows registry as a tuple

Regarding an application written in C++ using the Windows API. I'd like to store a user setting like the window position on program exit, to the Windows registry and retrieve settings like these on ...
3
votes
2answers
88 views

Regex Generator in C++

So I am writing an XML parser, and I'm using regexes to do some pattern matching during parsing. However, writing longer regexes quickly became a bit boring, annoying and just confusing. So I thought ...
6
votes
1answer
62 views

Smart pointer like implementations

For educational purposes I implemented standard library smart pointers like class templates. They are definitely not a full replacement for the library classes but I'd like to get some comments on the ...
4
votes
1answer
55 views

Builder pattern that forces all members to be initialized at compile-time [closed]

This java answer made me wonder whether it would be possible to implement the builder pattern in C++ in a way that checks at compile-time whether all necessary members of the constructed object are ...
2
votes
0answers
74 views

Program to take a number from 0 to 9 as input

I'm trying to make a function that requests a number from 0 to 9 to the user and that is robust. I've been looking at code to guide me and most fail to find any of these situations, usually due to the ...
6
votes
3answers
228 views

Encoding 0/1 bits to 0/255 bytes in C++

I need to map a sequence of bits that represents a float into a sequence of bytes by this rule: the value 1 maps to the value 255 and the value 0 maps to the value 0. This is the code I have now: <...
7
votes
3answers
674 views

C++ arithmetic on two numbers [closed]

I need someone with experience to judge my first project to let me know what I have to work on. I recently started learning C++ using resources like Solo Learn and Bucky's tutorials on YouTube hoping ...
3
votes
1answer
57 views

C++ OpenGL GPU resource wrapper pattern

So with OpenGL(and I'm assuming other GPU APIs) you create different buffers/programs/etc that live on the GPU and you are given a handle to them when created. For instance, if you want a buffer to ...
2
votes
1answer
45 views

Proxy to hide singleton implementation [closed]

I have a resource (e.g., current program configuration) that I want to handle in a single class instance, but want to hide the fact that there is, in effect, a singleton class by using a proxy class. ...
3
votes
2answers
38 views

Chip8 emulator memory map

I am making a Chip8 emulator and I started out with making a class for handling the memory map. So main the execution will read from this memory object and write to it. /include/Chip8.h ...
4
votes
0answers
75 views

Quicksort template (for sorting corresponding arrays)

I needed a function for sorting two corresponding arrays. So I wrote this code to sort N corresponding arrays! The really "metaprogrammy" way to do it would be to use ...
3
votes
1answer
46 views

SplitSort — An adaptive algorithm to handle collections with few inversions

SplitSort SplitSort is a rather simple Inv-adaptive and Rem-adaptive sorting algorithm described in Splitsort — an adaptive sorting algorithm by Christos Levcopoulos and Ola Petersson. The paper ...
8
votes
3answers
789 views

Binary Search Tree implementation using smart pointers

I have implemented below code for binary search tree implementation using shared pointer. At present, I have considered only integers. It supports insertion and deletion of values. Also, a print ...
2
votes
1answer
83 views

Iterating over different Objects which are ordered by index number

I am currently working on a bigger project where I found a part of it which seems very ugly to me from the code. I stripped out the algorithm and made a working code, so it can be reviewed. I have ...
2
votes
1answer
41 views

Sharing data with another thread using lock_guard

I wrote a updater_thread() and a reader_thread(), and used lock_guard to protect a global ...
1
vote
3answers
64 views

Password generator class and CLI

I made a password generator class in C++. I am not as familiar with C++ as I am with C, so I am looking for ways to move to a C++ mindset. I am also trying to use embedded practices like avoiding ...
2
votes
1answer
90 views

Offering coffee

I'm new to programming and even more new to C++. Anyway, I started to watch and read some tutorials and resources I found on the web. I created this program to offer the user a coffee, expecting an ...
8
votes
2answers
444 views

Hunt the Wumpus game in C++

I have created a simple version of the classic game Hunt the Wumpus in C++. The rules for the game can be found on Code Golf SE. The rules of the game are (from PPCG): The player starts in a ...
-3
votes
1answer
42 views

Assessment help, application that interrogates tweets [closed]

I'm a bit of a novice in terms of coding. I have to print to the console any tweets from a file that mentions a specific word like "Uber". This image below is what I have done so far. It prints how ...
-3
votes
1answer
42 views

About the problem of seeking matrix inverse

Recently I have solved the inverse matrix in three ways, found that their work efficiency has obvious differences. This is the case: ...
0
votes
2answers
66 views

Find whether two (or 'n') particular values are present in a binary tree

I have a solution to find if two values are present in a binary tree (not a BST). I would like to know if there is a more efficient way to do this? a more elegant way to this? specific improvement ...
3
votes
2answers
302 views

Implementing different types of light sources in a Graphics project

Edit: I got asked a lot why I need to have the LightSource base class or why do I keep one vector of all the light sources, so here's my explanation: In many ...
8
votes
2answers
435 views

Chemical Formula Parser

As an exercise, I wrote a simple context free parser modeled from a pushdown automaton for chemical formulas such as NO2 or ...