C++ :: Random Numbers (Representing X And Y Co-ordinate) Grid Reference
Sep 18, 2013
How to code the following:
I have two random numbers which are generated and are related to each other (representing x and y co-ordinate). These random numbers are generated within a specified range: (-range, +range).
I want to categorize these values in a (2-dimensional) grid. The grid size is not definite and so can be varied by the user would be in the order of 400 x 400. (e.g., think CCD detector). For each random number pair (x, y) I want to store a hit (a plus one) in the corresponding grid reference.
In the order of 500,000 related random numbers (x and y) are to be generated and the position recorded according to grid reference. So code needs to be fast.
View 8 Replies
ADVERTISEMENT
Sep 24, 2013
So basically I have an array of hex numbers representing a binary number. Each binary number is 1/5th layer of the over all font.
For example... the letter A
........ B00000000 0x00
.****... B01111000 0x78
...*.*.. B00010100 0x14
...*..*. B00010010 0x12
...*.*.. B00010100 0x14
.****... B01111000 0x78
........ B00000000 0x00
As you can see each HEX number is a layer in the font which consists of in the above example 7 layers.
Now what I would like to do is create a C++ program, so I can visualize a HEX font array that I got off the internet.
#include <iostream>
using namespace std;
const char font[][5] = {
{0x00,0x00,0x00,0x00,0x00}, // 0x20 32
{0x00,0x00,0x6f,0x00,0x00}, // ! 0x21 33
{0x00,0x07,0x00,0x07,0x00}, // " 0x22 34
{0x14,0x7f,0x14,0x7f,0x14}, // # 0x23 35
[Code]...
Basically I am asking two things. How can I make this display the correct representing letter in the array when a user inputs his own text.
And secondly, how can I output the HEX numbers that is in the array as a binary number.
View 1 Replies
View Related
May 1, 2014
I have to make a grid 40 X 40 with random numbers 0-9. I have already done this and it prints out great. My problem is I need to be able to choose a row number and output the sum of the number in that row. Here is what I have so far.
#include <iostream>
using namespace std;
int main(){
int Values[40][40];
int rows, cols;
[Code] ....
View 7 Replies
View Related
May 14, 2014
I have a program which generates lots of data points in 2D (x and y co-ordinates). Perhaps 1,000,000+ of these points. These are floating point numbers. The values all fall within a specific range -R/2 and +R/2.
I want to impose an 'imaginary' grid. Such that I can collect the number of each of these points falling within a specific grid location. The actual 'grid' size is variable.
Should I try and collate this data from my C++ program and then post-process it in some other s/w like matlab?
View 3 Replies
View Related
Aug 31, 2013
I want to make 10 random numbers thus making 10 random flips of a coin. I am getting 10 tails or 10 heads!
Code: #include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(int argc, const char * argv[])
{
[Code].....
View 4 Replies
View Related
Apr 16, 2015
string replace = targetListBox.Text;
replace = replace.Substring(0, replace.LastIndexOf("لیکن"));
targetTextBox2.Text = replace;
i am trying to remove sub ordinate clause from sentences but it ends till لیکن word with all other sentences having no subordinate clause.
View 12 Replies
View Related
Oct 25, 2013
Write a function called breakThree that will accept a 3 digit integer and returns each of the numbers individually. This function will take four paramaters. The first parameter is the three digit number to break apart. Parameters 2 through 4 are passed by reference and will be used to return each of the numbers back to main.
You should make sure that the input into the function is a 3-digit number. If it is not a three digit number the breakThree function should simply return false. If it is a three digit number the breakThree function should break the number apart, and store each of the numbers in the parameters passed by reference.
In main you should get the number from input and then output each of the numbers on a separate line.
What not to use
global variables
cin in breakThree function
cout in breakThree function
goto statements
#include <iostream>
using namespace std;
void separate(int a, int b, int c, int d);
int main(int argc, const char * argv[]) {
int num;
[Code] ....
View 4 Replies
View Related
Dec 24, 2013
I'm trying to make a space shooter and I want to make the code very reusable. So far I've been making a bunch of objects with multiple inheritance like this:
entity: anything which can be drawn, has a position and an orientation
solid: any entity which can collide with something else
mobile: any entity which can move
spriteEntity : an entity drawn using a sprite
vertexEntity : an entity drawn out of vertexes
The entity class has the virtual method draw, which gets defined by either spriteEntity or vertexEntity. mobile and solid virtually inherit from the entity class.
Then I could create a projectile class which inherits from solid and mobile but adds methods to damage stuff it collides with, and multiple subclasses which inherit from both projectile and spriteEntity... But I'm not sure if it's a good idea to go this deep in multiple inheritance for game objects. I know MI has a bad reputation.
I know that some objects of the game will be sprites and some will be vertexes, and I also know there will be stuff which collides and doesn't move... Or should I make the mobile class a subtype of solid?
View 6 Replies
View Related
Apr 17, 2012
I just started learning about pointer and reference. * and &
The assignment is " Write a program that stores the following numbers in the array named miles:15,22,16,18,27,23, and 20. Have your program copy the data stored in miles to another array named dist, and then display the values in the dist array. YOur program should use pointer notation when copying and displaying array elements.
And this is what i have so far. But there is an error. I highlighted it with red. It says it's incompatible...
#include <iostream>
using namespace std;
const int arraynumb = 7; // declaration of keys: number of characters of keys
void copyfunc(int *[], int); // function initialized
int main() {
int miles[arraynumb] = {15, 22, 16, 18, 27, 23, 20};
[Code] ....
View 1 Replies
View Related
Apr 6, 2013
how to use 3 variables to represent a rectangle in a grid instead of using 4. The traditional way is to use (x,y) (x2,y2). I propose using (x,l,h).In the traditional way as you probably know, (x,y) is the left op most corner, and (x2,y2) is the bottom right most corner. In the way I am proposing X is the left side, l is the length of the top side, and also the length of the bottom. 'h' is the height of the left and right. I think it's obvious how these three can define a rectangle same as the four.
View 2 Replies
View Related
Mar 18, 2015
We are supposed to create a point structure that can be used to represent a point in the xy-plane. Then, write a menu-driven C++ program that uses variables of type point to perform a variety of tasks involving points in the xy plane, including slope, distance, midpoint, equation of a line passing through points, and colinearity. One of the functions we are to create is simply for reading in the user-input in the following form "(x,y)" with the user entering the parentheses and comma. We are to create two functions that translate back and forth between this format and what the assignment calls "one point variable."
I'm confused how I'm supposed to take the user entering, say "(1,4)" and reading that into an x and y, and then comparing it against another set of points. I'm guessing I read them in as a, b, c, d, but I'm not sure what this has to do with a structure.
View 1 Replies
View Related
Mar 24, 2013
Create a class representing project activities. In this class include all the required data members and member functions. Each activity should have a record of activity duration, calculated early start, early finish, late start, late finish, free float, and total float. Each activity may or may not maintain a list of its successors and predecessors. Provide your design in UML and implement it in C++ using an interface head file and an implementation source file. I do not understand classes or UML designs.
View 2 Replies
View Related
Nov 3, 2013
I have been working on some C++ code that doesn't seem to be going right. I'm wanting it to read a (three-digit) integer representing the value to be encrypted, a (one-digit) integer representing the encryption key, encrypt the value and print the encrypted value. The encrypting method used is that each digit in the given number is replaced by ((the sum of that digit plus key) modulo 10) then the first and last “encrypted” digits are swapped.
For example, if the number entered was 216 and the key given was 7, after applying the encryption procedure described the first digit (2) would become 9, the middle digit (1) would become 8 and the last digit (6) would become 3. The first and last encrypted digits are then swapped. The program displays the encrypted number: that is 389 in this case.
#include <iostream>
using namespace std;
int main() {
int isolateDigits();
int replaceDigits();
int swapDigit1withDigit3();
[Code] ....
View 1 Replies
View Related
Oct 17, 2014
I'm trying to make a C++ program that generate 6 random numbers ( from 100,000 to 999,999 ), okay, so I wrote a few lines..
Code:
srand(time(0));
for (int i = 0; i < 5; i++)
{
std::cout << 100000 + (rand() % 999999) << std::endl;
}
The problem is, that it generates numbers like this:
117,207
123,303
131,083
... etc etc..
They're all starts with 100K, i want them to be an actual random..
View 8 Replies
View Related
Nov 9, 2014
My program behaves weird... I wanted to generate 10 random numbers from 1 to 100 each of them bigger than previous, using the while loop and function that returns a random number in specified range.
When I run the program, I get numbers much bigger than 100, even negative number, and numbers are same every time I run the program.
Code:
#include <ctime>#include <cstdlib>
#include <iostream>
using namespace std;
int range(int low, int high);
[Code] .....
View 2 Replies
View Related
Oct 19, 2014
I have a program that generates random numbers. After the random number is generated, the program asks if you want to generate another random number. However, if you generate another random number, it is always the same as the first random number. How can I fix this?
View 5 Replies
View Related
Mar 17, 2013
I'm trying to generate random numbers so that I can assign people to teams. So far I have come up with this
Code:
int generateTeam(){
int i, teamNumber, c, n;
for (c = 0; c <= 5; c++) {
n = rand()%100 + 1;
}
[code]....
}//end generateTeam I'm not sure how to make it so that I can exclude the previous random number when generating the next one. As an example, I have 22 students and I get the number 19. Now I can't have 19 again because that guy already has it.
View 3 Replies
View Related
Oct 30, 2013
Ok so Im suppose to make this program were the user inputs the size of the array then the user sets a certain range min and max for random numbers to be generated. I have a function named fillarray()
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int fillarray();
[Code] ....
Whenever i run the program i keep on getting a loop for the size of the array.
View 1 Replies
View Related
Feb 16, 2013
I want to generate big random numbers in C(not C++ please).By "big" I mean integers much bigger than srand(time(NULL)) and rand() functions' limit(32767).
I tried writing: (note:I am not able to see "code" tag button in this editor,so I am not using it)
//****
int randomnumber;
srand( time(NULL) );
randomnumber = (( rand() % 33 ) * ( rand() % 33 ) * ( rand() % 33) * ( rand() * 33) * (rand() % 33 )) + 1
//****
But I have doubts about it's randomness quality.Also there is another problem,the program can't know the maximum random number it should use before user input,so maximum random number may need to use much smaller maximum random number according to user input.
Is there a better algorithm to create big random numbers in C?
View 2 Replies
View Related
Nov 12, 2013
I am designing a math program for kids. I want the program to produce 2 random numbers and check the sum of these numbers against the user's guess. I have the generating random numbers portion complete. What's the coding procedure to compare the sum to the user's guess?
View 9 Replies
View Related
Jun 21, 2013
Assuming you have an array of these values x=[16,18,23,24,39,40] how would you write a function to generate random numbers that can add up to a 100? I need to know how many random numbers can add up to a 100.
View 3 Replies
View Related
Feb 5, 2014
This is my program i have to choose for random number between 1-25 and display them the program works perfectly just that every time i run its always the same numbers.
#include <iostream>
#include <cstdlib> // include library to use rand
using namespace std;
int main(){
int winner1; // declare variables
int winner2;
[Code] ....
View 3 Replies
View Related
Dec 13, 2013
i wrote this code but don't know if the numbers i array for p will generate in that order. how to get 5 random numbers horizontally and insure that 7,15, 22,27,31 will not generate in that exact sequence?
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <time.h>
using namespace std;
int main()
{
[Code]...
View 3 Replies
View Related
Feb 15, 2013
I want to generate big random numbers in C(not C++).By "big" I mean integers much bigger than srand(time(NULL)) and rand() functions' limit(32767).
I tried writing: (note:I am not able to see "code" tag button in this editor,so I am not using it)
//****
int randomnumber;
srand( time(NULL) );
randomnumber = (( rand() % 33 ) * ( rand() % 33 ) * ( rand() % 33) * ( rand() * 33) * (rand() % 33 )) + 1
//****
But I have doubts about it's randomness quality.Also there is another problem,the program can't know the maximum random number it should use before user input,so maximum random number may need to use much smaller maximum random number according to user input.
Is there a better algorithm to create quality big random numbers in C?
View 14 Replies
View Related
Apr 3, 2013
The program is to generate random numbers to a file and will have one integer parameter, Open a file and then using a loop write the required number of random numbers to the file. Scale the random numbers from 1 and 100 inclusive. Then closes the file .The last function will read the numbers in the file into your program. so far i have
Code: #include <iostream>
#include <string>
#include <iomanip>
#include <ctime>
#include <fstream>
#include <cstdlib>
[Code] .....
View 12 Replies
View Related
Nov 8, 2013
I generate a series of random numbers in parallel (using OpenMP), but depending on what number of threads I invoke, I get a different result. From that I conclude that I have made an error somewhere!
Here is the MWE, which generates a number between 0..1 and increments a variable if the generated variable is larger than 0.5:
Code:
#include <random>
typedef std::uniform_real_distribution<double> distr_uni;
#define max_threads 1
using namespace std;
[Code] ....
When I set max_threads=1 I get 50027, but when max_threads=60 (on a machine that supports it....) I get 50440.
The sensitive RNG and its engine I have declared within the parallelized area, so it's not really clear to me where the error can possibly be.
Looking for error that is apparently there?
View 8 Replies
View Related