C# :: How To Assign Distance Values To Fixed Graph
Apr 28, 2014I'm working on a Dijkstra's algorithm with a fixed graph. My question is, how should I go about assign distance values to the graph. The user can start from any node.
View 4 RepliesI'm working on a Dijkstra's algorithm with a fixed graph. My question is, how should I go about assign distance values to the graph. The user can start from any node.
View 4 RepliesIt is supposed to calculate and graph time vs. distance. The problem I have is graphing, if I put too small values for Vi, which is the initial velocity, it just graphs one or two points, because t is too small. I already tried to adjust t with 'if(t<10) t=t*10; if (t>100) t=t/10;', But it seems not to solve my problem.
Other truble I have is that, as the graph is parabola, core values are very close together, and when plotted, these values are in the same line on the screen.
Here is my code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main() {
float x, y, hmax, t, amax, vi, v, a, b, g, ang; /*x= x coordinate, y= y coordinate, hmax= maximum height,
[Code] .....
I know that the issue is around the array distance being of type double in the function get distance of type double. My question is how do i get around using the values from the distance array in the function to be used for calculations.
#include <stdio.h>/* initialization of preprocessor directives*/
#include <stdlib.h>
#include <math.h> /*preprocessor directive in order to use sqrt function*/
int calcSecondsvar(int,int,int ,double);
double getdistance(double,double,int,int,int);
[Code] ....
I forgot to mention that it keeps giving me the error cannot convert from 'double[8] to 'double' ....
I'm a C beginner trying to assign struct member values to other struct members to create a list.
I've tried dot notation, pointer notation, strcpy, memcpy, memmove and normal assignment.
Nothing has worked.
cust_list.h
I can assign values to pointer character array like this...
Code:
char *array[4]={"abc","xyz","dgf","sdt"} ;
but the case is i don't know how to assign strings through key board ???? with using gets ,getchar or other suitable function
I create some code that assign values to a dynamic memory structure. I'm not sure why one code works and the other crashes when it assigns a value.
Working Code
#include <iostream>
using namespace std;
struct WorldOjectCollisionMap
{
[Code].....
My game is a sort of RPG with stats, money etc. I just recently added a save/load system using writing to a file. I initially got writing to a text file to work, then I got loading to work too.I eventually was able to read numbers from the file and assign them to integer variables in order.
My issue was I wanted to check if a save file existed, if it did, load it up, if it did not, go to character creation. I had a lot of trouble with this and after trying different code snippets to work I finally got it to check if a file existed, and execute the appropriate code.
My issue now is my code USED to go through each entry and assign variables in order.
Like the first number in the text file would be for the variable money, and it would read it, assign to to int money and scroll to down to the next variable for player strength, assign to to playerstr variable and so on. After making the tweak for loading it no longer functions like this, and makes the last entry in the text file the value for everything.
Here's my code:
Save Code:
{
ofstream savegame;
savegame.open("C:/Sounds/savegame.dat", ios::trunc);
savegame << money << endl;
savegame << playerstr <<endl;
[Code]....
I barely get how this code works, how can I tweak it to go through the file in order and assign variables one at a time?
At the current moment, it assigned the playerstr value to both money and playerstr int. But the save file being created lists the correct values in order.
I need to assign unique integer values to words in a dictionary that have the same alphabets, for example 'act' and 'cat' should have the same integer value. Would just adding the ascii values of the letters be sufficient?
View 1 Replies View Relatedhave to do an election program in C.
There are 7 candidates and 365 votes in total. I need to do this using an array of structures. I need to read from a text file each of the names of the candidate and the number of votes they get. At the end i need to output the winner of the election.
Here is a sample of my code so far
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct candidates {
char name[20];
int votes;
[code]....
Here is a sample of my text file:
Robert Bloom
John Brown
Michelle Dawn
Michael Hall
Sean O’Rielly
Arthur Smith
Carl White
1 2 4 5 1 2 3 4 4 1 2 3 7 4 4 5 3 7 7 7 7 7 7 7 7 7
Each candidate gets +1 vote for their number electionCandidate[0] for each one he gets one vote and so on for the rest. 365 voters in total.
I was able to input the name for each Candidate from the text file. Now the problem is putting each vote to the corresponding candidate. Also any vote that is above 7 is a spoilt vote which i am trying to count in the above code. The code compiles but it crashes.
I am using while(!feof) but it seems that its not working or this is not the correct way.
I was loaded a bmp file in my mfc window and stored rgb data in a file.My image size is 320x240.
Is possible to pick a single point (location) from that bmp image (Not the whole window)?
i like to plot a line graph using the pointed single line data using the stored file data?
here R is X Axis and G & B is Y Axis.
If i have 2D array of data means how can i plot the line graph?
I got this program to create an array of playing cards and assign the values and suits and shuffle the array. I'm at the point where I need to output the cards but I need to burn the first card by making it output "**" instead of the card. my cards[] is a constant so I can's assign the first card as such.
void showCards(const int cards[], int numCards, bool hideFirstCard) {
if (cards[0]) {
hideFirstCard=true;
cards[0] = '**';
} for(int a = 0; a <= numCards; a++) {
cout >> showCard(cards[a]);
} }
I am trying to assign the integer value to unsigned char array. But it is not storing the integer values. It prints the ascii values. Here the code snippet
Code: uchar uc[100];
for(i=0;i<100;i++)
{
uc[i] = i;
}
The values which are stored in uc[] is ascii values.I need the integer values to be stored in uc[]. I tried to do it with sprintf. but the output is not as expected. if I print the uc[i] it should diplay the value as 0,1,2....99.
I am reading about positive and negative infinity in c++ and i am trying to implement them in a fixed point math arthimethic implementation
I can see that max of a int will be equal to std::numeric_limits<int>::max();
and min value of the int will be equal to std::numeric_limits<int>::min();
in c++
Here as i am defining the int max and int min manually in my fixed point math implementation, my doubt is
int min = -int max; or int min = -int max -1; ?
I have been writing a fixed point library the would handle fixed point numbers with an 8:24 whole/fraction ratio. This has been working quite well but since I have a 24 bit fractional part, it should be able to store 2^(-24).
Code:
long long fraction_part = 0;
long long divisor = 1;
while(*string) {
fraction_part *= 10;
fraction_part += *string - '0';
divisor *= 10;
string++;
}
fraction_part <<= 24;
fraction_part /= divisor;
The issue here is that since the smallest possible fraction is 2^(-24) the divisor could end up needing more than 64 bits and so won't work. I'm not quite sure how else I could do this.
The input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 255 characters.
it said 1 to 255 characters
i have to use getline(cin,str);
i tried str[255] but some error happen
the program has to accept a keypress. It should wait for some fixed amount of time. If a key is pressed within this time, the program should call a function. If a key is not pressed in this time limit the program should continue its normal execution. The problem with getch() is that it essentially requires you to press a key and it does not allow other instructions to execute until the key is pressed.
View 3 Replies View Relatedhow to create an unordered map of fixed size vectors?
Code:
unordered_map<string, vector<int>> x;
x["mumb 5"][7] = 65; // this does not work since my vector size is not set.
While testing some simple examples with glDrawArrays I noticed switching it to shaders can cut my frame rate by over half (from 600- 300). I know I am using a bunch of deprecated code in GLSL right now but I don't expect it to cause that much of an fps drop. I would say it was just my intel graphics chip but if the FFP can handle it I see no reason shaders can't.
--Windows 7 Premum 64-bit
--Intel Core i3 540
--Intel HD Graphics
//Sending 10,000 quads with GLfloats (So Vertices vector has 80,000 elements, currently no indexing).
//Vertices allocated earlier in code, before main game loop
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableClientState(GL_VERTEX_ARRAY );
glVertexPointer(2, GL_FLOAT, 0, 0);
glDrawArrays(GL_QUADS, 0, Vertices.size() / 2);
[Code] .....
The highest Opengl version I can run is 2.1 so 120 in shaders. I know this is a fairly pointless test right now but it is still surprising to see, anything obvious I am missing?
I am working on a computer program where I need to generate points on a circle. I am familiar with this kind of algorithm:
for(d=0; d<=2*pi; d+=0.01)
{
x = cos(d)*radius;
y = sin(d)*radius;
}
However, due to the specifics of the program I am writing, I need to iterate through a fixed number of points one at a time, like so:
for ( int x = 0; x < blockSize; x++ )
{
y = ???
}
This essentially "fixes" one axis of the circle, since I can't do: x=rx+sin(d)*r.
I have tried simply: "y = sin(d)*radius;" and I get a curved shape, but it's not a circle.
My question then is, how do I get the value of y in this situation, where the x axis is incrementing by 1 through a range of values? Is it mathematically possible?
I've come across an interesting question involving a fixed-point arithmetic class.
Suppose I've got a template that implements a fixed-point quantity. It has two characteristics: width and number of fraction bits:
Code:
template <typename RAWTYPE, unsigned int FRACBITS>
class Fixed
{
....
};
So if I want a 32-bit value with 12 bits of fraction I can declare:
Code:
Fixed<int32_t, 12> x;
Suppose I've implemented a freestanding operator+() for fixed values, and I want to be able to add different types together:
Code:
template <typename RAWTYPE1, unsigned int FRACBITS1, typename RAWTYPE2, unsigned int FRACBITS2>
???? operator+(Fixed<RAWTYPE1, FRACBITS1> lhs, Fixed<RAWTYPE2, FRACBITS2> rhs)
{
???
}
What is the result type? Obviously, it's up to me to decide this. As reference, consider the type promotion rules for native types:
Code:
short a;
int b;
int result = a + b; In this case, the short value is promoted to the int value, and the addition happens on int.
It would seem a similar rule (go to the wider type) would be appropriate for fixed point. But there is another dimension to the problem, which is the number of fraction bits. Should you go to the wider type? Or the most precise type? Should you endeavor to minimize the number of bits which are discarded? What's the most intuitive rule?
all i want to do is to read a fixed char array sized 4 from user and pass it to Binary File then Print Encrypted content from the the File to the console screen .. but it seems it prints the same input every time .. and i tried everything .. it works fine with integers and strings .. but when it come to char array nothing ..
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
[Code].....
I want to save the char[8][8] // fixed size 2 dimension array
to a vector
such as
vector<?????> temp;
is there anyway to approach this?
I am doing fixed point implementation in c++ which is done by the following code
#ifndef __fixed_point_header_h__
#define __fixed_point_header_h__
#include <boost/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/operators.hpp>
#include <limits>
[Code] ....
I am getting the error ambiguous overload for âoperator<â in âbeta < ((-5.0e-1) * pi)â
I know the problem the static member function cannot access the members and objects of structs. am i right?
and how to solve this problem, do i need to implement the cossin_cordic function as a non member function.
how would i go about writing up an equation for euclidian distance using c language. I am quite unfamiliar with the syntax's involved using squared and square roots.the equation for euclidian distance is: square root((Xv -Xu)^2 + (Yv-Yu)^2 +(Zv-Zu)^2)
The variables Xv, Yv and Zv represent the equation of vector 1 and then variables Xu, Yu and Zu represent the equation of vector 2. I have already put these into my program and i just need to know how to write that equation up there into the text file so that it works.
I can't figure out the error in this code; it compiles but returns rubbish.
serge
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
[Code] ......
Write a program that creates the output shown in the Output Layout section below. The program should create 2 points with x and y coordinates as integers, prompt the user to input the x and y values for one of the points and randomly set the other (-99 to 99 range) and output the length of the radius line segment and the area of the circle that radius defines. The program should then end. Include an SDM for the program and any other appropriate documentation.
Special Calculations:
Distance between 2 points equation:
√((p0x – p1x)2 + (p0y – p1y)2) (This requires use of the math library)
Output Layout: (bold text represents user input)
Please enter the location of your first point.
Enter a value from -99 to 99 for your x coordinate: -2
Enter a value from -99 to 99 for your y coordinate: 17
The location of your second randomly set point.
Your x coordinate: 45
Your y coordinate: -89
The length of the radius line segment from point one to point two is 115.
The area of the circle with a radius of 115 is 41546.33.
Other:
int pAx;
int pAy;
int pBx;
int pBy;