C++ Code Snippet Index

4

Adding two Big string numeric integer

The function adds two large numeric string together, like "12345667" + "12345678" = ? It does not have complete error checking, I'll leave that up to you. It should work but I am prone to bugs, so do advise if bugs are found. Included are also helper function that helps us add the large... (Read More)
1

How to access map outside the class

#ifndef _READFILE_H_ #define _READFILE_H_ #include<string> #include<vector> #include<map> using namespace std; class Readfile{ (Read More)
2

musician needs basic help

Hello i am a musician and not a programmer. i assume this is completely obvious to you by now. do listen to my music if you please. something to do while you read my long enquiry. samantha.mp3 I am attempting my first c++ program to create a program for a midi control device..... a... (Read More)
2

Play a MIDI voice (Dev C++ console program)

You can access the sound chip to play midi voices using winmm.lib, or in case of Dev C++ the libwinmm.a library. There are 128 midi voices to pick from, anything from the Acoustic Grand Piano = 0 to the Gunshot = 127. (Read More)
2

reverse queue

I am given the class definition of stack and queue classes where I have to write a templated function called reverseQueue(?) that takes a pointer to queue as a parameter and uses stack object to reverse the given queue. The function call to reverseQueue should reverse the data of the passed as a... (Read More)

Reference Variable

What will be the value of "++n" in the above code? Pls help.. (Read More)
1

Binary Tree Question

Can someone help me with this problem here about Binary Trees. I was given this code... and I am required to write a function void count_nodes(?) to determine the total number of nodes in a Binary Tree. (Read More)
1

searching linux directories

I previously posted an MS-Windows example program about how to recursively search folders and create a list of their filename. This program is similar in concept but is for linux. It c++ and uses std::string and std::vector classes to hold the strings. When the program encounters a directory... (Read More)
-1

Need help with fraction calculator

I have add the two functions the add and subtract I have to now add the multiply and divsion functions can someone help (Read More)

N Queen

The problem is to find all ways of placing n non-taking queens on a n by n board. A queen attacks all cells in its same row, column, and either diagonal. Therefore, the objective is to place n queens on an n by n board in such a way that no two queens are on the same row, column or diagonal. really... (Read More)

Text - Based RPG V2

I accidentally posted a lower version of the game that had more flaws, and a few less features. This one has a few more minor bugs fixed, and a power attack instead of a normal attack. (Read More)
1

fstream not working

Hi, I tried to direct the output from a thread into a log file using fstream, but it dosent seem to work. If I use ostream then it works fine. Can you please let me know why fstream is not working. Thanks in advance (Read More)
-1

Simple File i/o routines

This is my file manipulation library. (Read More)

ListBox example for Dev C++

This shows how to create, load and access a ListBox. BCX was used to create the original code which was then modified to work with the Dev C++ (really GCC/G++) compiler, compile as a Windows Application. (Read More)

Conversion to any base, with a fixed number of digits

Here's a function that manually converts an integer to any base between 2 and 36, the parameter list is: void toBase( int value, // Integer value to convert char *target, // Pointer to a large enough buffer int base, // Base (from 2 to 36) int fixedDigitCount // The minimum... (Read More)

Analog Clock using TurboC++ graphics

This program displays a simple analog clock to show the current system time. Uses a Hand class to create objects - hour, minute and seconds hands.The 'hands' are just straight lines, and two circles make the 'frame' of the clock. Compiles correctly on TurboC++ v3.0 (Read More)

Calculator in C++

I am new to C and C++, but I wrote this calculator in C++. It compiles okay on borland 5.5, and can do addition, subtraction, multiplication, and division of two numbers. If you type any characters except numbers, +,-,*,/,or e, there will be lots of beeping noises and error messages! Please post... (Read More)

Neat Text-Based RPG C++ Console

Pretty neat text-based RPG that I made. Currently my first game. (Read More)

Dynamic 2D array - user input

This program asks for integers from the user and stores them into a multidimensional array that adjusts its size. (Read More)
1

Basic RLE File compression routine

The RLE (Run length encoding) compression method compresses a file by writing repeated data as a byte containing the length, then a byte of the data itself. The 'real' RLE method involves writing control bytes. The first bit says whether the following data is compressed or uncompressed. The... (Read More)

C-String reverse

A small function which reverses a c-string by just swapping the elements :) ... Usage:: char str = "hello"; reverse(str); // str now contains "olleh" (Read More)

Stack Intersection C++

Stack Intersection by Fraz Jamshed (Read More)

Dev-C++ and Python

Python has some powerful functions, like the math expression evaluator eval(). You can embed this function and others in your Development C++ code. All you need to do, is to download and install the free Python Development Pak and feed the Python code in the form of a string to the interpreter. ... (Read More)
1

Byte to KILOBYTE conversion in c++

HEy:) Buddies in early morning i want to calculate that exchange during download & you very well known that it is shown in byte so just i am g with c++ and play a game for writing this. thanks enjoy it. It's very easy and handy with simple logic. (Read More)
1

Convert Hex to dec or Octal

The user is asked to input a number in either Hex, Octal or Decimal, which is then converted to Hex, Octal & Decimal. The user can exit the program from the MAIN MENU or by the Escape key after each convertion. Compiler : Borland Turbo C++... (Read More)

shape drawer class

This code draws different shapes to the screen,(in this version, only a square or a cross. It will be updated soon!!). This code was written by a beginner, for the beginners!! (Read More)

Convert Decimal to any base

The following code snippet can be used to convert a decimal integer into any base from 2-16. This is a simple piece of code and I hope t proves useful to people. I see many people posting Decimal to Hex. or Decimal to binary, non any better than the next. I'm not saying this is the best method,... (Read More)

Roman to decimal converter

A roman to decimal converter, no validity checking, so inputting an invalid roman number will certainly just yield a wrong result. (Read More)

//Generates Prime using Seive of Eratosthenes Idea

It uses the idea of Seive of Eratosthenes. The code is basically does the following to find Prime Numbers : 1) Populate Array from 0 - > MAX 2) Find 1st Prime, which is 2 3) Delete all Multiple of 2, i.e set it to false 4) Find next prime, which is 3 5) Delete all multiple of 3 6)... (Read More)

A Simple SetTimer Example

Just use the SetTimer function after you Create the window , and just handle the WM_TIMER message inside the message loop. That's it ! (Read More)
2

Recursive translation of numbers to words

This is an example of how to turn numbers into words. 1473 would get translated to "one thousand four hundred seventy three", for example. The class has a simple interface and can handle any value representable by unsigned int. The implementation recursively processes groups of 3 digits using table... (Read More)
1

string split inC++ using STL

Two methods for two distinct needs when splitting a string (Read More)

String to any data_type

Convert string to other datatypes via template. See below. (Read More)

Random number functions

Random number generator under its own namespace. Its a sample program. (Read More)
2

Complete CSV Reader

CSV is more than just comma delimited fields. There are quoting and white space rules too. This is a short function as an example of a complete way to read CSV records line by line. (Read More)
1

C++ String Split

The forum is buzzing with questions about tokenizing a C++ string. This is a short function that does it and returns a vector of the tokens. As an option, the delimiter string can represent either a multichar delimiter or a collection of single char delimiters: // multichar delimiter == "^^" ... (Read More)
-1

Link List by Fraz Jamshed

Link List for the beginners of cpp, who want to get the idea about link list before starting OOP. its implemented by struct for best teaching the design standards to beginners. (Read More)
-1

A countdown timer in c++

here is a wonderful short program to try out! A COUNTDOWN TIMER (Read More)

Input Validation in C++

Code will check whether the number entered is integer or not. ignore extracts characters from the input sequence and discards them. The extraction ends when max characters have been extracted and discarded or when the character delim(\n) is found, whichever comes first. In the latter case, the... (Read More)

Forum Tools


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC