C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language.

learn more… | top users | synonyms

4
votes
2answers
14 views

Implementation of fixed size hash map

I'm trying to brush up on my algorithms and data structures and wrote a fixed sized hash map assuming both key and value will be only integers. This is a significant simplification of the real case ...
2
votes
2answers
31 views

Linked list implementation of a stack

I am working on a basic linked list implementation of a stack of ItemType (currently set to double but can be changed) values. The stack code will then be used in a ...
3
votes
1answer
72 views

XML Writer in C++ - Updated

I recently posted about a basic XML writer in C++ and got a lot of great feedback. Well, I'm back with an updated version of the XML writer that is a bit less basic, but hope it's better than the ...
-3
votes
0answers
26 views

I can't make my code functional. [on hold]

These are the errors I am getting. I googled them and I went through my code and don't see what I need to fix. ...
12
votes
4answers
349 views

Array alive/dead entity “refresh” algorithm

I have an Entity class that can be either dead or alive. I store entities contiguously in a resizable array. During an ...
3
votes
3answers
70 views

Chain of Responsibility Design pattern in C++

I am learning design patterns from Design pattern for dummies, from that book i have written chain of responsibility pattern, I have written two programs, can ...
6
votes
2answers
251 views

Course Grade Calculator

Here is my objective: Ask how many categories there are for the class (ex: Labs, Tests, Homework, Quizzes), and then ask what total percentage each make up for the class (ex: Lab are 15%, tests are ...
0
votes
0answers
7 views

why is the private member function accessible outside the class [migrated]

I expect he below code to give an error but Compiles ok ...
9
votes
7answers
2k views

Cola Machine #1

I have been working on the code listed here. I am working on Problem #2, 0 stars. Here's what I have to do: Write a program that presents the user w/ a choice of your 5 favorite beverages (Coke, ...
6
votes
0answers
66 views

Easy Bit IO. Very simple interface works up to N == 64

After reading this question Easy bitset I/O. I wanted to see if there was a simpler way of doing it. This is how I would define a way of outputting ...
6
votes
4answers
280 views

Basic XML Writer in C++

This is an XML Writer in C++. It doesn't do much but the basics, and I've tested it, so it should hold up well enough. I hope in the near future, I can bring you an XML Reader. I kinda built the ...
6
votes
3answers
440 views

Simple password encryption / decryption

I'm working on a simple data storing program for my senior year (Secondary School / Grade 12), and there is a user sign-in functionality I've decided to implement. The way I've done this is by storing ...
1
vote
2answers
44 views

Rotating contents of a matrix (vector<string>) to the left or right

Each vector element is a row. Each character is a column. Assume the matrix is square (N*N) and N is < 10. I got some code to do it but doesn't look great and would love some feedback on how to ...
0
votes
2answers
43 views

deleting values from std::vector of different types

I need to make a vector of different types and be able to delete the values (please ignore anything else but deleting the values for now). Is the next code safe to delete the values? ...
5
votes
3answers
242 views

Optimizing simple C++ grading program

I have started working on the projects listed here. I want to practice my C++ coding skills. I would love any constructive criticism I can get! This is for the very first problem, #1 "Grading ...
-2
votes
0answers
24 views

Creating a singly sorted linked list of structs [on hold]

So I'd first like to punctuate this by saying that it is for a homework assignment, so this code is going to be published anywhere. Along with that, this is a sort of repost from an earlier topic ...
11
votes
2answers
112 views

Fast (faster than std::) ostringstream

I tried to implement a faster ostringstream which initially uses the stack (up to 256 bytes before using the heap). Also, unlke the standard, it provides a way to ...
8
votes
0answers
41 views

Function composition using std::bind

Given a number of functions f1, f2, f3, ..., fn I ...
6
votes
2answers
76 views

Vector backed by memory pages

The purpose of this class is to wrap a std::vector in a class so that never a new object is added. We don't allocate a new object on the stack but we trying to fit ...
5
votes
1answer
38 views

Formatting database like table

The goal of my program is take some headers and fields and display a nicely formatted table like this: ...
6
votes
4answers
209 views

Simple resizable array

In some (lower-level) parts of my codebase I often have the need to allocate resizable array storage for certain objects, that usually are not default-constructible. I created a simple class using ...
4
votes
4answers
133 views

Binary search tree

This is a binary tree using classes. What can be improved upon? ClassTree.h ...
4
votes
1answer
93 views

Easy bitset I/O

I'm writing a program that makes heavy use of std::bitset's and occasionally needs to read/write these to file. std::bitset does ...
2
votes
2answers
424 views

Simple TakeOut Menu

This is for my intro level C++ class. This is the assignment: Write a program that displays a takeout menu from which a user can place an order. The program begins by displaying the menu and ...
3
votes
3answers
96 views

Calculating budget for employee hierarchy

You have to write a C++ program that reads in the employee hierarchy of a company and computes a statistic called 'salary budget' for all employees. For this problem, the 'salary budget' ...
6
votes
1answer
66 views

Is this a correct implementation/use of move semantics?

I'm trying to account for the fact that my program will contain calculations such as: v(t) = w ∗ v(t−1)+ c1∗r1∗( pBest − x(t −1)) + c2∗r2∗(gBest − x(t−1)) where ...
4
votes
3answers
85 views

Basic Encoding Rules (BER) class for embedded system

I'm implementing a communications protocol in an embedded system and the protocol uses a subset of the ASN.1 BER (Basic Encoding Rules). In a nutshell, this class simply represents a TLV triplet ...
2
votes
2answers
48 views

Function that normalizes a vector of double

I have written the following function in order to normalize a container of double, so that it sums up to 1.0: ...
1
vote
2answers
72 views

Multithreaded lock-free queue implementation

My partner and I are beginning to believe there could be a desync possibility in the lock free queue we have written, but we would like some fresh eyes on the subject. What are your thoughts on our ...
2
votes
4answers
227 views

Output digits of a number

This is a simple C++ program I had to write for class. It prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. How do I improve ...
2
votes
2answers
81 views

Creating a singly linked list of structs

I'm pretty new to linked lists - I understand the concept and how they work - but coding them is a bit more...complicated. I have some code below that I'm using for homework - essentially we're to ...
2
votes
2answers
72 views

User input for student grades is too verbose

I need some help with this beginner C++ program (it's an assignment). How can I use a single variable and make the program get the six inputs I need instead of using a variable for each input? ...
1
vote
0answers
38 views

Writing a universal “call” function: call(f, args…) where “f” might be a member function/data pointer

I need a function call(f, args...) which calls the "function" f with the arguments args.... ...
8
votes
0answers
83 views
+50

JSON C++14 library API/implementation

I'm creating a C++14 header-only JSON library for fun, learning experience and to use it in my personal projects. I'm looking for feedback on: Its API/interface: since I'm using modern C++, I want ...
5
votes
2answers
93 views

More optimized approach of Dijkstra's algorithm

I need a graph-search algorithm that is enough in our application of robot navigation and I chose Dijkstra's algorithm. We are given the gridmap which contains free, occupied and unknown cells where ...
3
votes
5answers
385 views

Greatest common divisor

I wrote a program to find the greatest common divisor between two numbers. How do I improve this program? ...
9
votes
5answers
651 views

Find primes using “naive” algorithm

I know I can use Sieves to make this faster, but I wondered if there's anything I'm missing with this implementation of the "naive" algorithm. On my PC running the command (first million primes): ...
2
votes
2answers
111 views

Max path sum algorithm

This is for Project Euler question 18 and I'm looking for feedback on whether my algorithm is incorrect or whether I've just implemented it wrong (which I don't think is the case after some testing). ...
3
votes
2answers
253 views

Squaring numbers in an array

I want to know if there is a better way to square numbers in an array. This is what I wrote: ...
6
votes
1answer
70 views

Tic Tac Toe with an “algorithm” which can counter the player's moves and count scores

Here's a Tic Tac Toe program I wrote in C++. It can play (semi-effectively) against the player. Please give tips on how to improve. ...
5
votes
2answers
72 views

Writing out a tree of Tnodes with words as values in alphabetical order

I'm doing this: Consider: struct Tnode { string word; int count; Tnode* left; Tnode* right; }; Write a function for entering new words ...
6
votes
4answers
88 views

Efficient prime factorization for large numbers

I've been working on a little problem where I need to compute 18-digit numbers into their respective prime factorization. Everything compiles and it runs just fine, considering that it actually works, ...
11
votes
2answers
2k views

Snake game in C++

This is my version of the Snake game written in C++. How could it be improved and what general advice would be useful for future projects? ...
8
votes
4answers
2k views

Printing 100 prime numbers

This is a program I wrote to print out 100 prime numbers. How can I improve it? ...
4
votes
2answers
399 views

Count number of even and odd numbers from input

I had to write a program that accepted five numbers from the user. Then it will display the number of odd and even numbers, and a total sum of all numbers. ...
4
votes
5answers
250 views

Optimizing simple prime number function test

For my first basic project with functions, I wanted to make a program that would allow you to input a number, and it would output whether it was prime or not. For the most part, it's functional and ...
0
votes
1answer
45 views

Converting integers to strings

I drafted a method that I intend to use to convert integers to strings. Is there a way to make it faster? Are there any "simple" changes I could make to improve its performance? This cannot be done ...
1
vote
2answers
88 views

Most common words in a text file

I've made a program that outputs you the most common word in txt file. Does anybody know how to optimize it so that it would work for bigger files and run faster? ...
6
votes
3answers
263 views

Copying one array to the end of another array

I wrote a program that places values in one array to the end of another array. It keeps the order of the values. If the second array is bigger, then there will be leading zeroes. Is there anything I ...
1
vote
0answers
44 views

Unrolled linked list with iterator [closed]

I'm making an unrolled linked list (linked list with an array of 50 in each Node) for a class project with an iterator. In addition, whenever more than half of the arrays are unused (they would all be ...