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
0
votes
0answers
18 views

Arduino test pin and store or return result; help convert working function to library

I created an Arduino compatible checkDevice() function for a circuit designed to enable detecting devices that are plugged in. Essentially testing if a pin is HIGH or LOW and storing up to 8 boolean ...
3
votes
2answers
57 views

API for a progress display function

I want to create an object, that represents a progress output. In a GUI this would be a progress bar, in a console application it may be a text output, that can only be written, but not changed ...
3
votes
2answers
28 views

Atomic fixed-size parallel std::vector wrapper

I'm in need of a simple wrapper for a fixed-size std::vector that can ensure atomic insertion. Since my only real problem is with atomic insertion and I know ...
-1
votes
0answers
36 views

Player Ship Update function in an Asteroids-like game

In a Asteroids game, I have a player ship. In the code below, I have an Update function for Ship which will handle things like controls, collision and movement. What are your thoughts on this code? ...
1
vote
1answer
35 views

Minimal Property system in c++17

So I needed to represent by objects in terms in ini format and change their values from the ini as well, so I thought why don't implement a property system for this. I want it to be bit fast so I ...
8
votes
3answers
968 views

Reverse each word in the string. All spaces in the string should be retained

This was part of a code challenge. I use them to help me learn c++/c# along with tutorials and guides. Basically I was taking a string... The quick brown fox jumps over the lazy dog. ...and ...
-7
votes
0answers
45 views

i need help asap [closed]

I need help and its due in 2 hours. please help guys I am stuck printf("Input principal:"); printf("Input Principal: "); printf("Input Principal: ");
-2
votes
0answers
24 views

Correctly releasing allocated memory in C++ [closed]

Let me check if I could understand how to use delete operator ...
5
votes
3answers
409 views

Template Matrix Class: implemented some basic functionalities

Basically I have written a matrix class for addition, multiplication and scalar multiplication. I need your review of the class implementation below in terms of efficiency, memory consumption and new ...
2
votes
3answers
102 views

XOR two files together

I am trying to XOR two files each 1Mb which contains only 0 and 1. It works, but I think it is very slow for the C++ program - approximately 4 sec. Could someone, please, suggest the fastest XOR ...
4
votes
3answers
84 views

C++ Merge Sort Algorithm

I have created this first-timer implementation of Merge Sort and I got confused by the C++ syntax once or twice. So I have some questions about this code: ...
1
vote
2answers
81 views

2-sum problem in C++

I'm a beginner at C++; all my previous programming experience is mainly through PLCs in industrial maintenance. I have to accept 10 integers and a target value, then print all the pairs that sum to ...
2
votes
1answer
61 views

Simple BST implementation using C++ Struct

I am trying to implement DSs in C++ and this is BST insert and search functions. I tried in two different ways, please review and see if one is advantageous over other. With pointer to pointer ...
3
votes
2answers
103 views

Simple Binary Search Tree Class with Insert and Search Functions

I am trying to learn to implement DSs in C++ and here is a simple implementation. Please review in terms of optimization, memory management, coding standards, etc ...
-1
votes
0answers
54 views

C++ Circular buffer data structure and iterator [closed]

I am self taught and beginner in c++ programming , i tried to implement circular buffer data structure as an exercise and its corresponding iterator class, please help me to improve the quality of ...
-3
votes
0answers
26 views

C++ Cycles Is a graph denoted by the adjacency matrix a cycle graph? [closed]

Cycles Is a graph denoted by the adjacency matrix a cycle graph? Input In the first line: a number of next lines. In a line (expect the first): a number of vertices and after space an adjacency matrix ...
2
votes
1answer
101 views

Random Number Generator game

...
2
votes
1answer
51 views

Parallel MergeSort in C++

I've tried to implement parallel MergeSort in C++, that also tracks how many comparisons it's made and how many threads it uses: ...
2
votes
2answers
62 views

A-Star for 2D Graph (not grid)

This is my A-Star implementation for a 2D space of nodes but allowing to specifically set connections between nodes because my usecase does not have points tied to a grid (however for clarification ...
3
votes
1answer
40 views

Determining whether a string is transformable into another by repetitively increasing its prefixes alphabetically

Here's Alice and Strings, a programming challenge on hackerearth: Two strings \$A\$ and \$B\$ comprising of lower case English letters are compatible if they are equal or can be made equal by ...
1
vote
1answer
46 views

My second hangman game (Hangman in C++), how to avoid nested while-loops? How to stick to the SRP?

Here I already asked for tips, and I wrote another hangman game with the tips I got. My questions are: is int game() doing too many things that I should split ...
5
votes
1answer
86 views

HugeInt division using base 2^32 implementation

I previously submitted my code for a HugeInt class here. That version lacked a long division implementation. I have now implemented (long) division using Donald Knuth's algorithm D, following the ...
0
votes
0answers
17 views

Using auto vs decltype(vec.size()) in for loop to process vector of strings [migrated]

Teaching myself some of the particulars in using vectors and strings. To do this, I'm taking a paragraph typed into the standard input, storing each word in a separate element in a vector of strings ...
11
votes
4answers
2k views

BigInt class in C++

I made a BigInt class that supports almost all functions an int would. The code seems too bulky and there might be a few bugs lurking here and there. I would like ...
3
votes
1answer
56 views

LeetCode: Most Frequent Subtree Sum

My solution to LeetCode problem Most Frequent Subtree Sum works, but I have several questions regarding the code. I am also looking for an advice on how to improve the code. Problem: Given the ...
1
vote
2answers
54 views

Class template, custom container

So I wrote this class template for a custom container. Basically, it stores elements and their occurences. When an element is pushed into the container, if it ...
1
vote
1answer
44 views

Serializable and extensible API implementing the Command Design Pattern

I am currently trying to implement an extensible way to create commands that can be sent to some type of executor. In my case, there would be two of them (server and client). As I posted here, I had a ...
1
vote
1answer
53 views

Better to use string concatenation using std::string::operator+() or std::string::reserve() and std::string::append()? [closed]

I'm doing some code review and I saw something like the following: ...
1
vote
1answer
59 views

C++ matrix calculator

I wrote a program that is able to perform calculations with matrices: main.cpp (Just for test purposes) ...
5
votes
2answers
79 views

Speeding up string splitting in Rcpp/Cpp

I'm looking to speed up an Rcpp function I have written. The function takes in a string called vcfield, which takes the format od ...
4
votes
1answer
110 views

Function to convert little endian bytes into big endian

I'm working on a little endian machine and in my program I need to convert 2,3,4,5 or 8 bytes into network order before transmitting them over the network. I've written the following function which ...
2
votes
1answer
49 views

Leetcode: Subtree of Another Tree

My solution to the LeetCode's Subtree of Another Tree passes all the test cases, but the code feels and looks ugly. Would appreciate an advice on how to improve it. The problem: Given two non-...
1
vote
1answer
32 views

Event handler for SFML

Below is code for handling events in SFML. It works by reading a text file containing a sequence of functions to be called when a given event is detected: EventManager.hpp ...
21
votes
10answers
5k views

Find nth Fibonacci Number, using iteration and recursion

I'm a beginner programmer and I came upon this problem which is to find the n​th number in the Fibonacci series. I used to solve the problem using a for loop; ...
4
votes
1answer
63 views

Count frequencies of elements in array

I've been writing code to get the frequencies of elements of an array. The code works, but it uses a lot of "old style" C constructs, some of which I feel should be changed to more C++-like features, ...
4
votes
2answers
109 views

INI config loader / saver

Please take a review of my simple .ini config loader / saver: ...
2
votes
4answers
80 views

User Specified Array Read and Modify

How may this code be improved upon, the user inputs array of specified length and replaces each element that is smaller than the mean of the first and last element with the mean. Is there a better ...
1
vote
1answer
50 views

Optmize logic IF statement [closed]

I have a little dilema with such if statement, I have tried optimizing it in order to remove some checks, but could not think of how to make this code part cleaner. Can someone please make a review, ...
3
votes
2answers
159 views

Finding median of sub arrays taking too much time

I'm trying to solve a programming challenge where I have to find the median of given subarrays of an array. I have used std::vector's ...
4
votes
4answers
93 views

check_prime.cpp (checks if input is a prime number)

check_prime.cpp Description: Accepts user input to check if the user entered a prime number. Notes: If any text inputted after an integer will be ignored. For example: 1234.5678 and 98abc will be ...
0
votes
0answers
44 views

Making a parameter struct that preserves const

Given a group of functions that all take similar arguments, eg. ...
5
votes
3answers
575 views

Implementing Sample Abstract Factory Pattern using Smart Pointers in C++

Was trying to implement and example code to smart pointer from link. Is it a good practice? To go with all unique pointers or should we use shared pointers in this case? How can i improve this ? <...
4
votes
1answer
38 views

Windows autoclicker with a console interface

I have recently started coding in c++ and have made a simple console application. When executed the program asks the user to position their cursor wherever they want continuous repeating clicks, after ...
0
votes
2answers
87 views

Array indexing with copy constructor, assignment operator and index operator overload

The code below is a custom array class that handles indexing, copying, printing, etc. explicitly. Is there a better approach for specification (declaration and definition) of the assignment operator (...
1
vote
2answers
59 views

C++ determinant calculator - 2nd follow-up

After following the suggestions you can find here, I'd like to show the result again (but I did not change the algorithm): ...
-2
votes
1answer
59 views

C++ generic task interface for delayed execution

I want to rework my current game-server engine to use some global queue of tasks which will be distributed through all the working threads. I started with task interface. I want it to be able to ...
4
votes
3answers
369 views

Cool text based adventure game

I am looking for general critique of my code and notice of any bugs or errors. I have included the main file and the class files. Also, I'm wondering where would I need comments. Sorry it is such a ...
1
vote
2answers
126 views

A first Hangman game in C++

I wonder whether I included too many libraries; also can you point out obvious beginner mistakes? Is the while loop the best for what I intend, or is there a ...
5
votes
2answers
240 views

Message Broadcaster

I've written a basic event messenger broadcasting service. This is meant to allow for broadcasting events between loosely coupled areas of code where you may not have or care about a direct reference ...
3
votes
3answers
127 views

Codeabbey Code Guesser

I was doing this exercise on codeabbey. Andrew and Peter play the code-guessing game. Andrew chooses a secret number consisting of 3 digits. Peter tries to guess it, proposing several values, ...

1 2 3 4 5 148