I've been working on creating a simulator to crash two galaxies together as part of a project to stress test a CUDA super computer. I've got a long way to go and am currently just working on correctly simulating n-body gravity functions. First I will use this to simulate the cores of the galaxies (the black holes) and eventually the stars.
So long story short I'm working on the beginnings of a gravity simulator. At this point I found some basic code that works well but doesn't quite give the effect I'm looking for.
The code below only pulls each object towards each other like a spring faster and faster until they shoot off into infinity. I try to give one of my bodies an initial velocity to get it to orbit another, but it always just shoots straight at the other body. I'm thinking I need to factor in inertia so that the initial velocity doesn't just get calculated away really fast by the other calculations.
I'm really looking for a bit of direction to get a real gravity simulator with orbits and such working right so eventually I can scale it up to a galaxy, throw in 100B stars and let the CUDA run for a month..
As you can see, I'm calculating all the bodies in a vector called "galaxies" with each other, and doing a basic gravity calculation to it. The update_position function simply takes the calculated acceleration and uses it to calculate the velocity and position based on the "elapsedTime".
I think I need to use the Varlet or Runge-Kutta integration methods, after doing a bit more research.
I have recently begun programming c within my university course. I have been given a task to add arrays to a program I had previously made to make it record the values as I expect I will then quote them on an exported document.
Code:
#include <stdio.h> #include <math.h> main() { int i; // step counter float theta[10000]; // initial value for angle
[Code]....
The pendulum is meant to swing and take gravity into account, then it is meant to loop and record values for the step count, time, theta and omega (mainly theta and omega required). The boundaries are set so once the angle of theta reaches 180 degrees it then stops. I believe the problem lies in the way I have created my theta array, however, I don't properly know how to implement this. Upon launch it asks for omega, as required, after inputting the value it crashes.
I've been having trouble working on this physics engine of mine. Right now I'm having trouble adding gravity.
The game is a spaceship--which you control--flying around in space with asteroids and eventually the ability to shoot bullets. There should be a wrap on the edges of the screen and gravity for each object depending on their mass.
I'm creating a forceX and forceY for each force put onto each object, and then computing that force into a velX and velY which will determine the direction of each object and at which speed.
Where my problem arises:
Code: //add gravity pulls to forces for(int i = 0; i <= pushCount; i++) //add gravity pulls for each object { for(int u = 0 ; u <= pushCount; u++) //each object should add a force for every other object { if(i != u) { switch(id[i])
I'm attempting to make a cache simulator in C++. But I need to access individual bits in an integer to figure out where in my "cache" the writing actually gets done. I'm pretty new to bit shifting. Say I'm trying to access the the bits of the int 5, which are its "address". I'm simulating a direct mapped cache. I need to find its tag, the set it goes into, and which line. How do I use bit shifting to access the bits to acquire the tag, the index bits, offset bits, block number...all these pieces in order to actually find where I store it in the cache.
I'm attempting to make a cache simulator in C++. But I need to access individual bits in an integer to figure out where in my "cache" the writing actually gets done. I'm pretty new to bit shifting. Say I'm trying to access the the bits of the int 5, which are its "address". I'm simulating a direct mapped cache. I need to find its tag, the set it goes into, and which line. How do I use bit shifting to access the bits to aquire the tag, the index bits, offset bits, block number...all these pieces in order to actually find where I store it in the cache. I need to break the bits up into 3 sections: tag, set index, and block index. I think I can figure out the set and block index sizes based on the values passed in. The tag bits are just the remaining ones. And I'm hard coding values such as cache size (C) - 1024, number of physical address bits (m) - 32, block size (B) - 2, number of lines per set (E) - 1 (again, directly mapped cache). How would this look? I'll be using unsigned longs, so it can handle up to 64 bits.
We've been tasked write a code which would mimic a secure entry keypad.. Only recognising the digits 0-9 for the passcode, and non-numerics S (start again) C (clear last digit) and E (enter) for the control. All other key strokes are to be ignored.
The passcode has to be <10 digits and represented on the screen by "****", with any keystrokes >10 ignored. The valid passcode being 4 digits (1234).
With 3 attempts to get the correct pass code, after each fail attempt as please try again message show, where after the 3rd attempt a specific message is displayed and an alarm sounds..
I made this dice simulator which basically throws the dice 1 million times and outputs the frequency and percentage average for each side (1 to 6).
Everything is working fine, except my averages (floats) seem to be rounding up, causing 4% being "unassigned" at the end of the million rolls. I'm outputting with a setprecision of 2, but I only get 0's and no fractional numbers.
I finished my Enigma cipher simulator...how should I write the error handling code? Should I throw an exception in main, or in the Enigma ctor and Encrypt() fn when the user enters a non-alphanumeric character?
For a big project for school I have to make an airline reservation simulator but I have run into a problem. I want to save the the flight code and its location in a binary file so that I can obtain a code according to the location but this happens:
[URL] ... (link to current output and expected output)
I've been working on a battle simulator, and using it as a learning experience. So far, I've been able to debug the program, and learn some stuff, and it's been running smoothly. It's still runnable, but I've been trying to make it so the player can save his character, and continue the game later. However, I'm not sure whether it's the save or load function that's not working, because even if i save to a txt file, it's just a bunch of random characters. I don't know if that means it's not saving correctly, or if it's just supposed to be like that. Anyway, here are the two functions I'm speaking of:
i want to draw a highway, this simulator must not be graphical (must draw by "|" and "-" and...) . this highway include 3 type of car,
1- heavy 2-light heavy 3-light, t
These cars move from start point to quit at end of highway, highway must be object (programmed by class), and have 200 columns and 4 raw, it must be horizontal... . the cars speed are different,
I have to develop minimalistic implementation of RSA algorithm in C for an embedded device.
I'm doing that for two days but I have run into a problem. The N modulus is the limitation for the maximum message value to be encrypted with RSA.
For example theoretically RSA-1024 can encrypt/decrypt messages 1024 bits long but I still cannot understand how to choose p and q values to produce N == pow(2, 1024).
Is it possible to encrypt/decrypt 1024 bits long messages in practice if the N < pow(2, 1024)?
I was trying to implement Big Integer Implementation. I wanted to start with the basic operation of addition. I am having some problems with operator overloading part
I was looking at this tutorial: [URL] ..... And I was wondering if implementing it in MVC would be pretty much the same way? How would I display feed items in the views page using?
I tried something like:
ReaderModel Reader = new ReaderModel(); Collection<Rss.Item> List; List = Reader.GetFeed(); ViewData["RssItems"] = List;
// then in index.cshtml @foreach(Collection<Rss.Item> items in ViewData["RssItems"]) { <h3>items.Title</h3> ... }
I don't think this is right as I'm getting those red error lines...
Output to terminal: 0 2 3 1 4 5 but it should be: 0 2 4 5 3 1
Here's my code:
#include<stdio.h> #include<assert.h> /* maxVertices represents maximum number of vertices that can be present in the graph. */ #define maxVertices 100 void Dfs(int graph[][maxVertices], int *size, int presentVertex,int *visited)
I am trying to implement a stack class which has struct data type as its private member. I am getiing the following error ,
bash-3.2$ g++ stack_str_arr.cpp stack_str_arr.cpp: In member function ‘void stack::push(int)’: stack_str_arr.cpp:39: error: ‘top’ was not declared in this scope stack_str_arr.cpp: At global scope: stack_str_arr.cpp:43: error: no ‘void stack::display()’ member function declared in class ‘stack’
Code:
#include<iostream> using namespace std; #define MAX 5 class stack { public : stack();
I'm implementing a 4x4 matrix class and all is going well until the inverse function turned up. I'm trying to implement the inverse function, but I can't seem to get my head around it.
I've tried the internet, but found nothing useful. Also, I've looked into source code of other programs/libraries that implement a matrix class, but the code is unreadable.
How I can implement this damn 4x4 inverse function? I know the process of inversion, but putting that process into code is proving quite a challenge.
In addition, I do have some code, but it's unmanageable and inefficient at the moment. If you want to see it, just ask.
Additional question(s): What applications does the inverse matrix have in 3-D?
I'd like te have a heap which contains any item inserted by me. However, when I insert the values, if I delete the min value of this coded heap twice, I get the min value uncorrect.I could not find where the mistake is.
Code:
void BinaryHeap::percolateDown(int hole) { int child = hole*2; while (child < size) {
I was trying to implement a hash function in c++. This is just for learning purposes and not for a class project or assignment question. I had some questions before I started programming it:
1) Is it meaningful to have a hash function which maps string to string, string to int, int to int, float to int? 2) Can we have a template implementation which does element to element hashing?
I looked at several sources for a clear understanding of concepts and implementation technique but could not find a good source for reading about hashing.
I created a structure Vector and implement some functions to make the new defined type (vector) dynamically allocated and resized (inspired from the C++ implementation of the dynamic arrays : vector). I need to assign a structure to every vector element but I am not sure that I am doing it right:
here is the structure that I've defined:
typedef struct { void** mem; // to make this parametrizable I want the void* to point to a Structure (referenced with * a pointer) unsigned long elems; unsigned long elemsize; //element size
[Code] ....
I believe I have serious problems with pointers, values and dereferencing a pointer.