Search Results

Search found 6374 results on 255 pages for 'double underscore'.

Page 38/255 | < Previous Page | 34 35 36 37 38 39 40 41 42 43 44 45  | Next Page >

  • C struct written in file, open with Java

    - by DaunnC
    For example in C I have structure: typedef struct { int number; double x1; double y1; double x2; double y2; double x3; double y3; } CTRstruct;` Then I write it to file fwrite(&tr, 1, sizeof(tr), fp); (tr - its CTRstruct var, fp - File pointer); Then I need to read it with Java! I really don't know how to read struct from file... I tried to read it with ObjectInputStream(), last idea is to read with RandomAccessFile() but I also don't know how to... (readLong(), readDouble() also doesn't work, it works ofcource but doesn't read correct data). So, any idea how to read C struct from binary file with Java? If it's interesting, my version to read integer (but it's ugly, & I don't know what to do with double): public class MyDataInputStream extends DataInputStream{ public MyDataInputStream(InputStream AIs) { super(AIs); } public int readInt1() throws IOException{ int ch1 = in.read(); int ch2 = in.read(); int ch3 = in.read(); int ch4 = in.read(); if ((ch1 | ch2 | ch3 | ch4) < 0) throw new EOFException(); return ((ch4 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1 << 0)); } with double we can deal the same way (like with int or with long (8bytes) & then convert to double with native func).

    Read the article

  • [C++] Trouble declaring and recognizing global functions

    - by Sarah
    I've created some mathematical functions that will be used in main() and by member functions in multiple host classes. I was thinking it would be easiest to make these math functions global in scope, but I'm not sure how to do this. I've currently put all the functions in a file called Rdraws.cpp, with the prototypes in Rdraws.h. Even with all the #includes and externs, I'm getting a "symbol not found" error at the first function call in main(). Here's what I have: // Rdraws.cpp #include <cstdlib> using namespace std; #include <cmath> #include "Rdraws.h" #include "rng.h" extern RNG rgen // this is the PRNG used in the simulation; global scope void rmultinom( double p_trans[], int numTrials, int numTrans, int numEachTrans[] ) { // function 1 def } void rmultinom( const double p_trans[], const int numTrials, int numTrans, int numEachTrans[]) { // function 2 def } int rbinom( int nTrials, double pLeaving ) { // function 3 def } // Rdraws.h #ifndef RDRAWS #define RDRAWS void rmultinom( double[], int, int, int[] ); void rmultinom( const double[], const int, int, int[] ); int rbinom( int, double ); #endif // main.cpp ... #include "Rdraws.h" ... extern void rmultinom(double p_trans[], int numTrials, int numTrans, int numEachTrans[]); extern void rmultinom(const double p_trans[], const int numTrials, int numTrans, int numEachTrans[]); extern int rbinom( int n, double p ); ... int main() { ... } I'm pretty new to programming. If there's a dramatically smarter way to do this, I'd love to know.

    Read the article

  • C#: An object reference is required for the non-static field, method, or Property

    - by Omin
    I feel bad for asking this when there are so many questions that are related but I was not able to find/understand the answer I am looking for. // 2. Develop a program to convert currency X to currency Y and visa versa. using System; class Problem2 { static void Main (string[] args) { while (true) { Console.WriteLine ("1. Currency Conversion from CAD to Won"); Console.WriteLine ("2. Currency Conversion from Won to Cad"); Console.Write ("Choose from the Following: (1 or 2)? "); int option = int.Parse( Console.ReadLine() ); //double x; if (option == 1) { Console.WriteLine ("Type in the amount you would like to Convert CAD to Won: "); //double y =double.Parse( Console.ReadLine()); //Console.WriteLine( cadToWon( y ) ); Console.WriteLine( cadToWon( double.Parse( Console.ReadLine() ) )); } if (option == 2) { Console.WriteLine ("Type in the amount you would like to Convert Won to CAD: "); Console.WriteLine( wonToCad (double.Parse( Console.ReadLine()))); } } } double cadToWon( double x ) { return x * 1113.26; } double wonToCad( double x) { return x / 1113.26; } } This give me the Error messgae "An object reference is required for the non-static field, method, or property 'Problem2..." I know that I'll be able to run the program if I add static infront of the methods but I'm wondering why I need it (I think it's because Main is static?) and what do I need to change in order to use these methods without adding static to them? Thank you

    Read the article

  • C++, inject additional data in a method

    - by justik
    I am adding the new modul in some large library. All methods here are implemented as static. Let mi briefly describe the simplified model: typedef std::vector<double> TData; double test ( const TData &arg ) { return arg ( 0 ) * sin ( arg ( 1 ) + ...;} double ( * p_test ) ( const TData> &arg) = &test; class A { public: static T f1 (TData &input) { .... //some computations B::f2 (p_test); } }; Inside f1() some computations are perfomed and a static method B::f2 is called. The f2 method is implemented by another author and represents some simulation algorithm (example here is siplified). class B { public: static double f2 (double ( * p_test ) ( const TData &arg ) ) { //difficult algorithm working p_test many times double res = p_test(arg); } }; The f2 method has a pointer to some weight function (here p_test). But in my case some additional parameters computed in f1 for test() methods are required double test ( const TData &arg, const TData &arg2, char *arg3.... ) { } How to inject these parameters into test() (and so to f2) to avoid changing the source code of the f2 methods (that is not trivial), redesign of the library and without dirty hacks :-) ? The most simple step is to override f2 static double f2 (double ( * p_test ) ( const TData &arg ), const TData &arg2, char *arg3.... ) But what to do later? Consider, that methods are static, so there will be problems with objects. Thanks for your help.

    Read the article

  • Variable from block is put into a calculation but throws off wrong reading

    - by user2926620
    I am having troubles with trying to retrieve a double variable that is already established outside the block and called inside but I want to return the value of the same variable so that I can apply it to a calculation. the variable that I want returned is: double quarter = 0; but when I plug it into quarter in my first else/if statement, it plugs in 0 and not the value in my switch block. What can I do to retrieve the value? double quarter = 0; //Date entry will be calculated by how much KW user enters switch (input) { case "2/15/13": quarter = kwUsed * 0.10; break; case "4/15/13": quarter = kwUsed * 0.12; break; case "8/15/13": quarter = kwUsed * 0.15; break; case "11/15/13": quarter = kwUsed * 0.15; break; default: System.out.println("Invalid date"); } //Declaring variables for calculations double base = 0; double over = 0; double excess = 0; double math1 = 0; double math2 = 0; //KW Calculations if (kwUsed <= 350) { base = quarter; }else if (kwUsed <= 500) { math1 = ((kwUsed - 350) * quarter); base = ((kwUsed * quarter) - math1); over = ((math1 * 0.1) + math1); }else if (kwUsed > 500) { math2 = ((kwUsed - 350) * 0.1); base = ((kwUsed * 0.1) - math2); math2 = ((kwUsed -350) - 50); over = ((math2 * 0.1) + (15 * 0.1)); double math3 =((kwUsed - 500) * 0.1); excess = ((math3 * 0.25) + math3); } Edited to clarify question.

    Read the article

  • Unit Conversion from feet to meters

    - by user1742419
    I have to write a program that reads in a length in feet and inches and outputs the equivalent length in meters and centimeters. I have to create three functions: one for input, one or more for calculating, and one for output; And include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. I can't seem to get the input from one function to be used in the conversion function and then outputted by the next function. How do I do that? Thank you. #include <iostream> #include <conio.h> using namespace std; double leng; void length(double leng); double conv(double leng); void output(double leng); int main() { length(leng); conv(leng); output(leng); _getche(); return 0; } void length(double leng) { cout<<"Enter a length in feet, then enter a length in inches if needed: "; cin>>leng; return; } double conv(double leng) { return leng = leng * .3048; } void output(double leng) { cout<<"Your input is converted to "<<leng; return; }

    Read the article

  • Double Buffering for Game objects, what's a nice clean generic C++ way?

    - by Gary
    This is in C++. So, I'm starting from scratch writing a game engine for fun and learning from the ground up. One of the ideas I want to implement is to have game object state (a struct) be double-buffered. For instance, I can have subsystems updating the new game object data while a render thread is rendering from the old data by guaranteeing there is a consistent state stored within the game object (the data from last time). After rendering of old and updating of new is finished, I can swap buffers and do it again. Question is, what's a good forward-looking and generic OOP way to expose this to my classes while trying to hide implementation details as much as possible? Would like to know your thoughts and considerations. I was thinking operator overloading could be used, but how do I overload assign for a templated class's member within my buffer class? for instance, I think this is an example of what I want: doublebuffer<Vector3> data; data.x=5; //would write to the member x within the new buffer int a=data.x; //would read from the old buffer's x member data.x+=1; //I guess this shouldn't be allowed If this is possible, I could choose to enable or disable double-buffering structs without changing much code. This is what I was considering: template <class T> class doublebuffer{ T T1; T T2; T * current=T1; T * old=T2; public: doublebuffer(); ~doublebuffer(); void swap(); operator=()?... }; and a game object would be like this: struct MyObjectData{ int x; float afloat; } class MyObject: public Node { doublebuffer<MyObjectData> data; functions... } What I have right now is functions that return pointers to the old and new buffer, and I guess any classes that use them have to be aware of this. Is there a better way?

    Read the article

  • Conversion from string to type 'Double' is not valid.

    - by Adnan Badar
    Hi, I am getting the following error while running a select statement (using OleDbCommand). My query is SELECT CME FROM Personnel WHERE CME = '11349D' If objOleDbCom.ExecuteScalar() 0 Then When i execute the above statement i got this error Conversion from string "11349D" to type 'Double' is not valid. My field CME data type is Text My database is Access 2007 I tried by running my query directly inside database and it is running fine. Please suggest. Thanks.

    Read the article

  • Does single or double quote matter in str_ireplace in PHP ?

    - by Richards
    Hi, I've to replace newline (\n) with & in a string so that the received data could be parsed with parse_str() into array. The thing is that when I put \n in single quote it somehow turns out as to be replaced with a space: str_ireplace(array('&', '+', '\n'), array('', '', '&'), $response) "id=1 name=name gender=gender age=age friends=friends" But when I put \n in double quotes then it works just fine: str_ireplace(array('&', '+', "\n"), array('', '', '&'), $response) "id=1&name=name&gender=gender&age=age&friends=friends" Why is that so?

    Read the article

  • What's the difference between single and double quotes in Objective-C?

    - by Alex Mcp
    I'm working through a book exercise to generate some random serial number, and here's my function: NSString *randomSerialNumber = [NSString stringWithFormat:@"%c%c%c%c%c", '0' + random() % 10, 'A' + random() % 26, '0' + random() % 10, 'A' + random() % 26, '0' + random() % 10]; This works and has an output like: 2J6X7. But before, the 0s and As I had wrapped in double quotes, and an example output was 11764iÒ˜. What did I do wrong my first time around, and why did using single quotes fix it?

    Read the article

  • Send a double click to a listview (c++, not .net!)

    - by Jorge Branco
    Hello. I want to send a double click to a listview. From what I've read on msdn it seems I gotta send a WM_NOTIFY message and something with NM_DBLCLK. But I do not understand really well hwo to implement it. I've worked with SendMessage before but MSDN is not that clear on how to fill the structs and so: WM_NOTIFY http://msdn.microsoft.com/en-us/library/bb775583(VS.85).aspx NM_DBLCLK http://msdn.microsoft.com/en-us/library/bb774867(VS.85).aspx

    Read the article

  • How to change the default "double click" action of a web service in a class library (VS2010)?

    - by JL
    I have a web service defined as follows, residing in a class library: [WebService(Namespace = "http://comp.com/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class SendingItems_new : System.Web.Services.WebService When I double click it, instead of going to code view, it shows the design view. I NEVER use design view, so how can I get it to open up code view instead, its very annoying having to flick from design view each time. Thank you

    Read the article

< Previous Page | 34 35 36 37 38 39 40 41 42 43 44 45  | Next Page >