This is a function that generates a string of random characters to the length that you specify.

Member Avatar
Member Avatar
+0 forum 3
Code Snippet Base85 Class

Here's a simple class for what it's worth that will do simple base85 encoding and decoding. This only works with the required blocks of data and not large data structures or streams, and does no validation of the data. What it does do is encode a block of 4 8-bit bytes into 5 base85 characters and decode a block of 5 Base85 characters into 4 8-bit bytes. There's also a provision in the definition for base85 to represent 5 !'s with a single 'z'. However the definition I read wasn't clear on whether it was mandatory, so I didn't implement …

Member Avatar
Member Avatar
+0 forum 3

Here is simple Digital Clock coded in C++ and compiler used is TurboC. A class DIGIT is designed to draw digits. Follwoing are the details for this class: Consructor: DIDGT(); for default settings DIGITE(int s,int c,int st); for user define settings s -> is size of the digit c -> color of the digit st -> fill style of the digit Methods: void DIGITE::DrawDig(int x,int y,int n) x,y -> x and y coordinates of the screen n -> interge value (<10) to be display void DIGITE::PutDig(int x,int y,int n) x,y -> x and y coordinates of the screen n -> …

Member Avatar
Member Avatar
-2 forum 2

I have add the two functions the add and subtract I have to now add the multiply and divsion functions can someone help

Member Avatar
Member Avatar
-1 forum 1

An example how to plot the function y = sin(x) using the WinApi function SetPixel(). The plot is centered along a line at pixel y = 200. Add an x-axis and a couple of tickmarks and it could look impressive.

Member Avatar
Member Avatar
+1 forum 5

Factorials get large very rapidly. The factorial of 13 is !13 = 1*2*3*4*5*6*7*8*9*10*11*12*13 = 6227020800. This number already exceeds the unsigned long integer, and gets into the real money as the politicians say! This program uses an array of characters to store the factorial as a numeric string. Go ahead, exercise your computer with astronomical numbers. The factorial of 47 is 258623241511168180642964355153611979969197632389120000000000. Checked it with Python, where these kind of things are a natural.

Member Avatar
Member Avatar
+0 forum 16
Code Snippet Bitmap class

Enjoy.

Member Avatar
Member Avatar
+0 forum 1

Here is a small--complete--program that includes a sub-routine that inputs two matrices and then multiplies them. Notes: * 1) I happen to like taking input from a text file. It eliminates the need to type input from the console, especially when debugging, it prevents the possibility of making typos. * 2) The sub-routine includes several checks to make sure the array sizes are correct. These checks are not necessary for this particular program, but the checks were added in case the sub-routine is ever copied and used somewhere other than this program. * 3) To make the code more concise, …

Member Avatar
Member Avatar
+3 forum 4

[B]Simple C++ program for billing[/B] NB:Excuse me experts,,,,,This is only for beginners 1.copy and paste the program in a notepad 2.save the textfile with .cpp extension 3.select file type all 4.cut the textfile and paste it in your bin folder where turbo c is located 5.open turbo c and open the document we just saved in bin 6.if opened,press F9 to compile and then ctrl+F9 to run... 7.search the bin folder for the .exe format file with the name you given for the text file......use it further........ try it!!!!!!!!!!!!!!! Its your friend.... Rajeesh.N.Santhu

Member Avatar
Member Avatar
-5 forum 2

OK, I've taken advice from some members here, and members from another forum. And I've come up with this, thouht I'd just share it with you.

Member Avatar
Member Avatar
+0 forum 1

Here is my first Code Snippet contribution: a C++ sub-routine that computes the roots of a quadratic equation. Notes: * This sub-routine checks if a = 0. * IF a = 0, then the equation is actually not a quadratic equation; it is a linear equation with one--if any--root. * IF the user misses the output statement alerting the user to this fact, the second root has been explicitly assigend a NaN value so that the result is not mistaken for a number.

Member Avatar
Member Avatar
+1 forum 10

Hello. This code snippet is a basic calculator. The general concept is that the calculator accepts infix expressions as strings, converts them to reverse polish notation by way of the shunting-yard algorithm and then evaluates the resulting expression. I tried to encapsulate the functionality of each piece so that, in theory, they could be pulled out and used independently. The shunting-yard behavior is provided via `class ShuntingYard`; I used the visitor pattern for the `Token`; and `RPNExpression` could be built by hand (or some other process) and still be used with `Calculator`. I removed almost all error checking and input …

Member Avatar
Member Avatar
+2 forum 5

I was going to post this in a thread, but it turned into something a bit more serious and may be useful as a code snippet. The code shows three files: * menu.h: The header file for the menu library. * menu.c: Implementation of the menu library functions. * main.c: A sample driver that uses the library. The menu library is fairly generic in that you can provide a format string of menu options and possible matching input values. See main.c for an example of how to use it.

Member Avatar
Member Avatar
+3 forum 2
Code Snippet Simple Trie Class

As the title says, it's a simple trie class written in C++11. The only operations implemented are insert, remove, and search (both prefix and exact matches). I sort of abandoned the test/debug process, and while I'm somewhat confident that there aren't any serious bugs, I can't guarantee it. Use this class at your own risk. ;)

Member Avatar
Member Avatar
+3 forum 4

The annoying use case is this: for (vector<int>::size_type i = 0; i < v.size(); i++) { cout << v[i] << ' '; if (i == v.size() - 1) { cout << endl; } } C++11 offers the `auto` keyword for initializer type deduction so that we can avoid verbose and ugly types like `vector<int>::size_type`. However, the naive attempt doesn't work: for (auto i = 0; i < v.size(); i++) { cout << v[i] << ' '; if (i == v.size() - 1) { cout << endl; } } The reason it doesn't work is because 0 doesn't match the type …

Member Avatar
+5 forum 0

I've needed to write sample code using conio.h over the years, but my compilers don't support all of it (most notable being clrscr() and gotoxy()). So I wrote a conio simulator class to help me. Not all of the conio.h functions are present, such as cgets() and cscanf(), because I haven't needed them. But the design is such that they can easily be added. It's based around an abstract IConio class that can be inherited from for specific implementations. The conio.h library is *very* platform specific, and I've included a Win32 implementation as I work primarily with Windows systems. POSIX …

Member Avatar
+2 forum 0

Another quickie. This is a basic class for working with Windows path strings. It's based off of .NET's System.IO.Path class, but doesn't contain any API dependencies (and thus doesn't normalize the paths, it's all straight string handling). Methods that I've personally found to be useful are included. The class is specific to std::string so as to remain both simple and clean.

Member Avatar
Member Avatar
+0 forum 2

No bells and whistles, just a quickie millisecond timer showing an alternative to the far less portable clock_t method. A test main() is included, just define TEST_DRIVER as a macro or remove the conditional compilation at the end.

Member Avatar
Member Avatar
+0 forum 1

C++ conversion of [this C snippet](http://www.daniweb.com/software-development/c/code/445012/simple-interactive-menu) for a simple interactive menuing system. The code shows three files: * menu.h: The header file for the menu class. * menu.cpp: Implementation of the menu class. * main.cpp: A sample driver that uses the library. The menu library is fairly generic in that you can provide a format string of menu options and possible matching input values. See main.cpp for an example of how to use it. Note that C++11 features are used in this code.

Member Avatar
Member Avatar
+2 forum 15

[B]Introduction[/B] Hello everyone. This little code snippet shows you how to read in scan codes from the keyboard. It is slightly different than reading in a regular character. When you use the [INLINECODE]getch()[/INLINECODE] function, it is normally returning an ASCII value. Some keyboards have extra keys though. These include the F1 - F12 function keys and the directional arrows to start. These keys do not have an ASCII code. A [INLINECODE]char[/INLINECODE] data type is a one byte item. When you press a key that doesn't have an ASCII code, it returns [I]two[/I] bytes. If the first byte is 0, then …

Member Avatar
Member Avatar
+2 forum 35
Code Snippet Countdown timer

Input the minutes, then the seconds, and it will do the rest. Pretty simple but I just thought I'd post it. Made as a quick test for my game.

Member Avatar
Member Avatar
+0 forum 11
Code Snippet Tic Tac Toe Code

I thought i would share this with the community wrote most of it in school but the ai i wrote at home enjoy!

Member Avatar
Member Avatar
+2 forum 2

A real useful piece of code, hence I put it under Z. It does nothing but open and close the door of the CD-ROM player, and pushes the tray in and out. Should your coffee be too hot, you can put it on the moving tray and cool it off! Get the old computer out of the attic, we found a use for it! Seriously, just a quick look at the many things the mciSendString() function can do.

Member Avatar
Member Avatar
+1 forum 8

Well, I have just made this funtion that will split an array using a delimiter. I'm new to C++ so I will take any suggestions you have. Anyhow, good luck! Enjoy!

Member Avatar
Member Avatar
+0 forum 7

These are codes that do absolutley nothing, except to show whart you can do with to much time on your hands. Oh the silliness

Member Avatar
Member Avatar
+1 forum 20

This is my solution for generating prime numbers. With this code hopefully you can generate prime numbers with incredible speed. The generated numbers will be stored in a text file titled as "Primes.txt". I have a dual core machine, but this program does not support dual core architecture, so it can only use one of the cores. Still the speed results are remarkable. On my 5600+ AMD, it is capable of generating 1 million prime numbers less than 8 seconds! Compiled and tried under Vista, and Ubuntu 8.10. I use VisualStudio 2008 on Vista, and Code::Blocks 8.02 on Linux. There …

Member Avatar
Member Avatar
+1 forum 19

Ok, so, this code snippet is a reply to this thread: http://www.daniweb.com/software-development/cpp/threads/425821/prime-number-c From what I understood form the OPs request, is that, he wanted an algorihm which would check for prime numbers in a given range, applying these conditions: a number is to be considered valid if: a. the number itself is a prime number. b. the digits composing the number are prime, like this: 37397 is a prime number: 3 is a prime number 37 is a prime number 373 is a prime number 3739 is a prime number I would not recommend this algorithm thou because it's slow, …

Member Avatar
Member Avatar
+0 forum 8

What is it : A simple logic (text based) game, in which you are required to identify the counterfeit coin within 3 chances. How it works : You are given 'x' coins ( best is to play it with 12 coins ). You are asked how many coins you want to put in Pan 1. You enter 'y' amount of coins. Then same process with Pan 2. After that, it shows which Pan is heavier, for example if Pan 1 is heavier than Pan 2 then it shows, ' Pan 1 > Pan 2 '. Then using this information you …

Member Avatar
Member Avatar
+0 forum 4

This is a very simple Rock Paper scissors game i made. i showed it to my cousin and he played it for like 20 mins lol. Its against an AI and you pick by number, not words.

Member Avatar
Member Avatar
+0 forum 3

These are just some of the more useful #define statements I've used in C++. These are some of the statements you'll use the most (in the case of template<typename T> when you use it, you use it a lot!). So I figured I'd post it for others, even though a lot of the programmers probably already have this list.

Member Avatar
Member Avatar
-4 forum 9

The End.