Skip to main content
39 votes
Accepted

Count all vowels in string

An alternative route is to use string.replace() and Regular Expressions to strip everything but the vowels from the string. Then count the length of the resulting ...
Joseph's user avatar
  • 25.4k
28 votes

Count all vowels in string

I'm just wondering if there's an easier way to solve this problem without the big blocky code in the if statement. Well, you could put all of those in an array: <...
Sᴀᴍ Onᴇᴌᴀ's user avatar
25 votes
Accepted

Transcode UCS-4BE to UTF-8

Efficient file I/O By default, files opened with fopen() are buffered, meaning that not every call to fread() or ...
G. Sliepen's user avatar
  • 69.3k
24 votes

Dungeon Crawl game for the terminal

Overall, this is really well done. You've missed the usual traps of using magic numbers, not creating structures for related items, and other common things. So nice work! I think it could be improved ...
user1118321's user avatar
  • 11.9k
24 votes

Transcode UCS-4BE to UTF-8

log is already declared in <math.h>. You don't need to declare it yourself. In fact, it could be harmful. As stated in ...
vnp's user avatar
  • 58.7k
22 votes
Accepted

Simple modern C++ string class implementation

Error handling ...
kraskevich's user avatar
  • 5,660
21 votes
Accepted

COBOL Database Program

ZOMG, that is frightening along so many dimensions. Disclaimer: Within the last decade I wrote lots of python code to parse production COBOL database record formats. And as an undergraduate I had ...
J_H's user avatar
  • 42.3k
20 votes
Accepted

Python code that sorts books

It looks good and readable IMHO. For brownie points, you could: modify the structure a bit. Not every LinkedList will contain books. Similarly, not every ...
Eric Duminil's user avatar
  • 3,991
20 votes

Multiplying binary strings using divide and conquer in C++

Design review Since you are interested in good coding design, I thought I’d give a little preamble to the actual review to discuss C++ design guidelines. There are two key features of C++ that I ...
indi's user avatar
  • 16.5k
19 votes
Accepted

Customization of memory class C++

Try to be more consistent with naming I'm seeing camelCase, PascalCase and snake_case all mixed together. Pick one style and stick with it. Furthermore, I see redundant things in names like ...
G. Sliepen's user avatar
  • 69.3k
18 votes

Dungeon Crawl game for the terminal

That's an awesome little game! User experience Before we dive into the code, let's talk about the game itself. Random hangs Sometimes, the executable hangs when I ...
Indiana Kernick's user avatar
18 votes

Naïve RSA decryption in Python

Simple does not mean fast, so you cannot judge performance based on how simple the implementation looks. Usually the most efficient way to perform a non-trivial task is not also the simplest way to do ...
user555045's user avatar
  • 12.4k
17 votes
Accepted

Huffman Code in C++

Looks pretty readable and I agree with most of your formatting however there are some things that stand out. using namespace std; Kick this habit before it kicks ...
yuri's user avatar
  • 4,548
16 votes
Accepted

Implementing a rectangle class

PEP-8 Class names should be CapWords, so instead of rectangle you should have Rectangle. ...
AJNeufeld's user avatar
  • 35.3k
15 votes
Accepted

Phone Book Program in C++

There are a number of things that could be improved, and I hope you find this list of suggestions useful. Don't abuse using namespace std Putting ...
Edward's user avatar
  • 67.2k
15 votes

Count the frequency of items in an array

Answer to the Performance Issue Anytime there are a list of variables named NAMEi where i is an integer, there is a strong chance that a container such as std::array or std::vector should be used. ...
pacmaninbw's user avatar
  • 26.1k
15 votes

Value store ("optional" type)

About these assignments As someone who’s been teaching C++ for 15 holy shit, almost 20 years now, I have to say that these assignments are pretty terrible… especially the “vector” one. (To be clear, I ...
indi's user avatar
  • 16.5k
14 votes
Accepted

Checking for parentheses balance in C

Bugs The loop header is wrong: for(i=0;line[i]!=NULL;i++){ Here, you want to scan until you find a byte with ASCII value 0 (also called an ASCII NUL, and written ...
200_success's user avatar
14 votes

Python code that sorts books

A little late here as I just got back in front of a non-mobile device, so let me try to add some new points: Most importantly (with the caveat that I'm super pedantic), the format of this assignment ...
Bailey Parker's user avatar
14 votes

Egg size Prompt Box

The parseInt(eggWeight); calls are not doing anything, because you are not using its return value. And since you aren't using the return value, the comparisons are ...
RoToRa's user avatar
  • 11.6k
13 votes

Checking for parentheses balance in C

The idea is correct, the implementation is not. Upon exiting the loop you need to test for pilepointer == -1. Otherwise, the strings like ...
vnp's user avatar
  • 58.7k
13 votes

Transcode UCS-4BE to UTF-8

This program reads 4 byte codepoints (in BIG ENDIAN) from a file strictly called "input.data" and creates another file called "ENCODED.data" with the relative encoding in UTF8. Needless to say, ...
Maarten Bodewes's user avatar
13 votes

Egg size Prompt Box

Since you already checked > 69 , if you get to the next else if you don't need to check that it is ...
user985366's user avatar
  • 1,775
13 votes
Accepted

Toggle 2 LEDs using a timer XMEGA-A3BU Xplained

The optimizer has a habit of optimizing out my timing loops. This is (a) a non-surprise, and (b) somewhat of a red flag when it comes to coding practice. If you're writing timing loops that attempt ...
Reinderien's user avatar
  • 71.1k
12 votes
Accepted

A Date Class with simple methods

What's in the public interface? Most of the public interface looks reasonable, except it's not obvious what Date::magic() means to a user - I think that's more ...
Toby Speight's user avatar
  • 88.3k
12 votes
Accepted

Array Stutter Implementation

By reviewing your code, the first thing that comes to my mind is a lot of if statements. You should try and keep those minimal by writing solutions to be as general ...
Pritilender's user avatar
12 votes
Accepted

Function that returns a sequence of numbers [x: sqrt(x_(n-1)^3)] given a start value and a max value

Instead of using comments to describe the function, use a doc string. This can then be used by tools, unlike comments. ...
Toby Speight's user avatar
  • 88.3k
11 votes

Checking for parentheses balance in C

Here are some things that may help you improve your code. Don't use gets Using gets is not good practice because it can lead ...
Edward's user avatar
  • 67.2k
11 votes
Accepted

C++ code to read, sort, and write data

Your code doesn't seem to work. However, let's break down just the sort routine, since that's what you seem to think is the bottleneck. using namespace std; Get ...
Quuxplusone's user avatar
  • 19.7k
10 votes
Accepted

'Snakes and Ladders' game

First of all: "Lines of Code" doesn't mean a thing if it is unreadable code. Dry The don't repeat yourself principle, (which also handily removes duplicate lines and therefore greatly reduces LoC) ...
Ludisposed's user avatar
  • 11.8k

Only top scored, non community-wiki answers of a minimum length are eligible